diff options
Diffstat (limited to 'init/init.c')
-rwxr-xr-x | init/init.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/init/init.c b/init/init.c index f2a1d27..bb27c4e 100755 --- a/init/init.c +++ b/init/init.c @@ -150,11 +150,11 @@ void service_start(struct service *svc, const char *dynamic_args) int needs_console; int n; - /* starting a service removes it from the disabled + /* starting a service removes it from the disabled or reset * state and immediately takes it out of the restarting * state if it was in there */ - svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING)); + svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET)); svc->time_started = 0; /* running processes require no additional work -- if @@ -243,13 +243,22 @@ void service_start(struct service *svc, const char *dynamic_args) /* as requested, set our gid, supplemental gids, and uid */ if (svc->gid) { - setgid(svc->gid); + if (setgid(svc->gid) != 0) { + ERROR("setgid failed: %s\n", strerror(errno)); + _exit(127); + } } if (svc->nr_supp_gids) { - setgroups(svc->nr_supp_gids, svc->supp_gids); + if (setgroups(svc->nr_supp_gids, svc->supp_gids) != 0) { + ERROR("setgroups failed: %s\n", strerror(errno)); + _exit(127); + } } if (svc->uid) { - setuid(svc->uid); + if (setuid(svc->uid) != 0) { + ERROR("setuid failed: %s\n", strerror(errno)); + _exit(127); + } } if (!dynamic_args) { @@ -291,27 +300,42 @@ void service_start(struct service *svc, const char *dynamic_args) notify_service_state(svc->name, "running"); } -void service_stop(struct service *svc) +/* The how field should be either SVC_DISABLED or SVC_RESET */ +static void service_stop_or_reset(struct service *svc, int how) { /* we are no longer running, nor should we * attempt to restart */ svc->flags &= (~(SVC_RUNNING|SVC_RESTARTING)); + if ((how != SVC_DISABLED) && (how != SVC_RESET)) { + /* Hrm, an illegal flag. Default to SVC_DISABLED */ + how = SVC_DISABLED; + } /* if the service has not yet started, prevent * it from auto-starting with its class */ - svc->flags |= SVC_DISABLED; + svc->flags |= how; if (svc->pid) { NOTICE("service '%s' is being killed\n", svc->name); - kill(-svc->pid, SIGTERM); + kill(-svc->pid, SIGKILL); notify_service_state(svc->name, "stopping"); } else { notify_service_state(svc->name, "stopped"); } } +void service_reset(struct service *svc) +{ + service_stop_or_reset(svc, SVC_RESET); +} + +void service_stop(struct service *svc) +{ + service_stop_or_reset(svc, SVC_DISABLED); +} + void property_changed(const char *name, const char *value) { if (property_triggers_enabled) @@ -384,6 +408,9 @@ void handle_control_message(const char *msg, const char *arg) msg_start(arg); } else if (!strcmp(msg,"stop")) { msg_stop(arg); + } else if (!strcmp(msg,"restart")) { + msg_stop(arg); + msg_start(arg); } else { ERROR("unknown control msg '%s'\n", msg); } @@ -676,7 +703,7 @@ int main(int argc, char **argv) mkdir("/proc", 0755); mkdir("/sys", 0755); - mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755"); + mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755"); mkdir("/dev/pts", 0755); mkdir("/dev/socket", 0755); mount("devpts", "/dev/pts", "devpts", 0, NULL); @@ -715,6 +742,7 @@ int main(int argc, char **argv) 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); queue_builtin_action(property_service_init_action, "property_service_init"); queue_builtin_action(signal_init_action, "signal_init"); |