aboutsummaryrefslogtreecommitdiffstats
path: root/init/util.c
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2012-02-24 11:15:22 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2012-02-24 11:15:22 -0800
commit3b04bde991d57765a830e06c6f5bb094722583bd (patch)
treecb17f9dd95bca7ef3abb9b9eb4eaff1eeb025d0a /init/util.c
parent4802f78191f0056e184f0c62ffa682866e86decb (diff)
parentee79b455a904558f74d63a99ade8f3f1197a5de5 (diff)
downloadsystem_core-3b04bde991d57765a830e06c6f5bb094722583bd.tar.gz
system_core-3b04bde991d57765a830e06c6f5bb094722583bd.tar.bz2
system_core-3b04bde991d57765a830e06c6f5bb094722583bd.zip
am ee79b455: am 93553073: Merge "Extend init and ueventd for SE Android."
* commit 'ee79b455a904558f74d63a99ade8f3f1197a5de5': Extend init and ueventd for SE Android.
Diffstat (limited to 'init/util.c')
-rwxr-xr-xinit/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/init/util.c b/init/util.c
index 13c9ca25..3a4b10b0 100755
--- a/init/util.c
+++ b/init/util.c
@@ -23,6 +23,10 @@
#include <errno.h>
#include <time.h>
+#ifdef HAVE_SELINUX
+#include <selinux/label.h>
+#endif
+
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -33,6 +37,7 @@
#include <private/android_filesystem_config.h>
+#include "init.h"
#include "log.h"
#include "util.h"
@@ -84,6 +89,9 @@ int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid)
{
struct sockaddr_un addr;
int fd, ret;
+#ifdef HAVE_SELINUX
+ char *secon;
+#endif
fd = socket(PF_UNIX, type, 0);
if (fd < 0) {
@@ -102,12 +110,26 @@ int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid)
goto out_close;
}
+#ifdef HAVE_SELINUX
+ secon = NULL;
+ if (sehandle) {
+ ret = selabel_lookup(sehandle, &secon, addr.sun_path, S_IFSOCK);
+ if (ret == 0)
+ setfscreatecon(secon);
+ }
+#endif
+
ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
if (ret) {
ERROR("Failed to bind socket '%s': %s\n", name, strerror(errno));
goto out_unlink;
}
+#ifdef HAVE_SELINUX
+ setfscreatecon(NULL);
+ freecon(secon);
+#endif
+
chown(addr.sun_path, uid, gid);
chmod(addr.sun_path, perm);