From ae76f6dbcf3dfd6eda223911f91f4a1316433771 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Thu, 11 Jul 2013 15:38:26 -0700 Subject: [PATCH] init: call restorecon on /sys Not all files on /sys are not getting labeled properly. Fix them. Change-Id: I9dcff76354e7f50d41f1b6e702836cfbbc149278 --- init/init.c | 1 + init/util.c | 15 +++++++++++++++ init/util.h | 1 + 3 files changed, 17 insertions(+) mode change 100755 => 100644 init/util.c diff --git a/init/init.c b/init/init.c index 294c2c435..b699be047 100644 --- a/init/init.c +++ b/init/init.c @@ -945,6 +945,7 @@ int main(int argc, char **argv) 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 1820aa92b..154bb2dbc --- a/init/util.c +++ b/init/util.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -519,3 +520,17 @@ int restorecon(const char *pathname) 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 39d6f5240..04b8129ba 100644 --- a/init/util.h +++ b/init/util.h @@ -41,4 +41,5 @@ void get_hardware_name(char *hardware, unsigned int *revision); 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