Merge "init: call restorecon on /sys"
diff --git a/init/init.c b/init/init.c
index d75adca..b7e34d0 100644
--- a/init/init.c
+++ b/init/init.c
@@ -948,6 +948,7 @@
     restorecon("/dev");
     restorecon("/dev/socket");
     restorecon("/dev/__properties__");
+    restorecon_recursive("/sys");
 
     is_charger = !strcmp(bootmode, "charger");
 
diff --git a/init/util.c b/init/util.c
old mode 100755
new mode 100644
index 918bc05..fffc8a4
--- a/init/util.c
+++ b/init/util.c
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <time.h>
+#include <ftw.h>
 
 #include <selinux/label.h>
 
@@ -499,3 +500,17 @@
     freecon(secontext);
     return 0;
 }
+
+static int nftw_restorecon(const char* filename, const struct stat* statptr,
+    int fileflags, struct FTW* pftw)
+{
+    restorecon(filename);
+    return 0;
+}
+
+int restorecon_recursive(const char* pathname)
+{
+    int fd_limit = 20;
+    int flags = FTW_DEPTH | FTW_MOUNT | FTW_PHYS;
+    return nftw(pathname, nftw_restorecon, fd_limit, flags);
+}
diff --git a/init/util.h b/init/util.h
index 45905b6..6bca4e6 100644
--- a/init/util.h
+++ b/init/util.h
@@ -41,4 +41,5 @@
 void import_kernel_cmdline(int in_qemu, void (*import_kernel_nv)(char *name, int in_qemu));
 int make_dir(const char *path, mode_t mode);
 int restorecon(const char *pathname);
+int restorecon_recursive(const char *pathname);
 #endif