diff options
Diffstat (limited to 'init/init.c')
-rw-r--r-- | init/init.c | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/init/init.c b/init/init.c index 00f4558..e4ac1cf 100644 --- a/init/init.c +++ b/init/init.c @@ -46,8 +46,6 @@ #include <private/android_filesystem_config.h> #include <termios.h> -#include <sys/system_properties.h> - #include "devices.h" #include "init.h" #include "log.h" @@ -164,7 +162,7 @@ void service_start(struct service *svc, const char *dynamic_args) * state and immediately takes it out of the restarting * state if it was in there */ - svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART)); + svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART|SVC_DISABLED_START)); svc->time_started = 0; /* running processes require no additional work -- if @@ -364,7 +362,7 @@ static void service_stop_or_reset(struct service *svc, int how) { /* The service is still SVC_RUNNING until its process exits, but if it has * already exited it shoudn't attempt a restart yet. */ - svc->flags &= (~SVC_RESTARTING); + svc->flags &= ~(SVC_RESTARTING | SVC_DISABLED_START); if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) { /* Hrm, an illegal flag. Default to SVC_DISABLED */ @@ -530,7 +528,8 @@ static int is_last_command(struct action *act, struct command *cmd) void execute_one_command(void) { - int ret; + int ret, i; + char cmd_str[256] = ""; if (!cur_action || !cur_command || is_last_command(cur_action, cur_command)) { cur_action = action_remove_queue_head(); @@ -547,7 +546,17 @@ void execute_one_command(void) return; ret = cur_command->func(cur_command->nargs, cur_command->args); - INFO("command '%s' r=%d\n", cur_command->args[0], ret); + if (klog_get_level() >= KLOG_INFO_LEVEL) { + for (i = 0; i < cur_command->nargs; i++) { + strlcat(cmd_str, cur_command->args[i], sizeof(cmd_str)); + if (i < cur_command->nargs - 1) { + strlcat(cmd_str, " ", sizeof(cmd_str)); + } + } + INFO("command '%s' action=%s status=%d (%s:%d)\n", + cmd_str, cur_action ? cur_action->name : "", ret, cur_command->filename, + cur_command->line); + } } static int wait_for_coldboot_done_action(int nargs, char **args) @@ -843,24 +852,21 @@ static int bootchart_init_action(int nargs, char **args) static const struct selinux_opt seopts_prop[] = { { SELABEL_OPT_PATH, "/property_contexts" }, + { SELABEL_OPT_PATH, "/data/security/current/property_contexts" }, { 0, NULL } }; struct selabel_handle* selinux_android_prop_context_handle(void) { - int i = 0; - struct selabel_handle* sehandle = NULL; - while ((sehandle == NULL) && seopts_prop[i].value) { - sehandle = selabel_open(SELABEL_CTX_ANDROID_PROP, &seopts_prop[i], 1); - i++; - } - + int policy_index = selinux_android_use_data_policy() ? 1 : 0; + struct selabel_handle* sehandle = selabel_open(SELABEL_CTX_ANDROID_PROP, + &seopts_prop[policy_index], 1); if (!sehandle) { ERROR("SELinux: Could not load property_contexts: %s\n", strerror(errno)); return NULL; } - INFO("SELinux: Loaded property contexts from %s\n", seopts_prop[i - 1].value); + INFO("SELinux: Loaded property contexts from %s\n", seopts_prop[policy_index].value); return sehandle; } @@ -873,6 +879,7 @@ void selinux_init_all_handles(void) static bool selinux_is_disabled(void) { +#ifdef ALLOW_DISABLE_SELINUX char tmp[PROP_VALUE_MAX]; if (access("/sys/fs/selinux", F_OK) != 0) { @@ -886,12 +893,14 @@ static bool selinux_is_disabled(void) /* SELinux is compiled into the kernel, but we've been told to disable it. */ return true; } +#endif return false; } static bool selinux_is_enforcing(void) { +#ifdef ALLOW_DISABLE_SELINUX char tmp[PROP_VALUE_MAX]; if (property_get("ro.boot.selinux", tmp) == 0) { @@ -908,6 +917,7 @@ static bool selinux_is_enforcing(void) ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp); } +#endif return true; } @@ -933,12 +943,33 @@ int selinux_reload_policy(void) return 0; } -int audit_callback(void *data, security_class_t cls, char *buf, size_t len) +static int audit_callback(void *data, security_class_t cls __attribute__((unused)), char *buf, size_t len) { snprintf(buf, len, "property=%s", !data ? "NULL" : (char *)data); return 0; } +int log_callback(int type, const char *fmt, ...) +{ + int level; + va_list ap; + switch (type) { + case SELINUX_WARNING: + level = KLOG_WARNING_LEVEL; + break; + case SELINUX_INFO: + level = KLOG_INFO_LEVEL; + break; + default: + level = KLOG_ERROR_LEVEL; + break; + } + va_start(ap, fmt); + klog_vwrite(level, fmt, ap); + va_end(ap); + return 0; +} + static void selinux_initialize(void) { if (selinux_is_disabled()) { @@ -1012,7 +1043,7 @@ int main(int argc, char **argv) process_kernel_cmdline(); union selinux_callback cb; - cb.func_log = klog_write; + cb.func_log = log_callback; selinux_set_callback(SELINUX_CB_LOG, cb); cb.func_audit = audit_callback; @@ -1031,8 +1062,7 @@ int main(int argc, char **argv) is_charger = !strcmp(bootmode, "charger"); INFO("property init\n"); - if (!is_charger) - property_load_boot_defaults(); + property_load_boot_defaults(); INFO("reading config file\n"); init_parse_config_file("/init.rc"); @@ -1047,28 +1077,19 @@ int main(int argc, char **argv) /* execute all the boot actions to get us started */ action_for_each_trigger("init", action_add_queue_tail); - /* skip mounting filesystems in charger mode */ - if (!is_charger) { - action_for_each_trigger("early-fs", action_add_queue_tail); - action_for_each_trigger("fs", action_add_queue_tail); - action_for_each_trigger("post-fs", action_add_queue_tail); - action_for_each_trigger("post-fs-data", action_add_queue_tail); - } - /* Repeat mix_hwrng_into_linux_rng in case /dev/hw_random or /dev/random * wasn't ready immediately after wait_for_coldboot_done */ queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng"); - queue_builtin_action(property_service_init_action, "property_service_init"); queue_builtin_action(signal_init_action, "signal_init"); queue_builtin_action(check_startup_action, "check_startup"); + /* Don't mount filesystems or start core system services if in charger mode. */ if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); } else { - action_for_each_trigger("early-boot", action_add_queue_tail); - action_for_each_trigger("boot", action_add_queue_tail); + action_for_each_trigger("late-init", action_add_queue_tail); } /* run all property triggers based on current state of the properties */ |