diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/librc/librc-depend.c | 6 | ||||
-rw-r--r-- | src/librc/rc.h.in | 1 | ||||
-rw-r--r-- | src/rc/rc.c | 79 | ||||
-rw-r--r-- | src/rc/runscript.c | 5 |
4 files changed, 53 insertions, 38 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index 739e6fc1..2c05ea1e 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -189,7 +189,8 @@ valid_service(const char *runlevel, const char *service, const char *type) if (rc_service_in_runlevel(service, runlevel)) return true; - if (strcmp(runlevel, RC_LEVEL_SYSINIT) != 0 && + if (strcmp(runlevel, RC_LEVEL_SHUTDOWN) != 0 && + strcmp(runlevel, RC_LEVEL_SYSINIT) != 0 && strcmp(runlevel, bootlevel) != 0) { if (rc_service_in_runlevel(service, bootlevel)) @@ -499,8 +500,7 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char *runlevel, int options) /* When shutting down, list all running services */ if (strcmp(runlevel, RC_LEVEL_SINGLE) == 0 || - strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0 || - strcmp(runlevel, RC_LEVEL_REBOOT) == 0) + strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0) { list = rc_services_in_state(RC_SERVICE_STARTED); list2 = rc_services_in_state(RC_SERVICE_INACTIVE); diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 92fb19c7..6f7c64e0 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -70,7 +70,6 @@ typedef TAILQ_HEAD(rc_stringlist, rc_string) RC_STRINGLIST; #define RC_LEVEL_SYSINIT "sysinit" #define RC_LEVEL_SINGLE "single" #define RC_LEVEL_SHUTDOWN "shutdown" -#define RC_LEVEL_REBOOT "reboot" /*! Return the current runlevel. * @return the current runlevel */ diff --git a/src/rc/rc.c b/src/rc/rc.c index a6cde112..995cc910 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -831,6 +831,11 @@ main(int argc, char **argv) } newlevel = argv[optind++]; + /* For compat with old system */ + if (newlevel) { + if (strcmp(newlevel, "reboot") == 0) + newlevel = UNCONST(RC_LEVEL_SHUTDOWN); + } /* Enable logging */ setenv("EINFO_LOG", "rc", 1); @@ -875,8 +880,7 @@ main(int argc, char **argv) set_krunlevel(NULL); if (newlevel && - (strcmp(newlevel, RC_LEVEL_REBOOT) == 0 || - strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0 || + (strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0 || strcmp(newlevel, RC_LEVEL_SINGLE) == 0)) { going_down = true; @@ -887,9 +891,9 @@ main(int argc, char **argv) #ifdef __FreeBSD__ /* FIXME: we shouldn't have todo this */ - /* For some reason, wait_for_services waits for the logger proccess - * to finish as well, but only on FreeBSD. We cannot allow this so - * we stop logging now. */ + /* For some reason, wait_for_services waits for the logger + * proccess to finish as well, but only on FreeBSD. + * We cannot allow this so we stop logging now. */ rc_logger_close(); #endif @@ -944,29 +948,30 @@ main(int argc, char **argv) } /* Load our list of hotplugged services */ - hotplugged_services = rc_services_in_state(RC_SERVICE_HOTPLUGGED); - if (!going_down || - strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) == 0) - start_services = rc_services_in_runlevel(RC_LEVEL_SYSINIT); - if (!going_down && + start_services = rc_services_in_runlevel(newlevel ? + newlevel : runlevel); + if (strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 && strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SYSINIT) != 0) { - /* We need to include the boot runlevel services */ - tmplist = rc_services_in_runlevel(bootlevel); + tmplist = rc_services_in_runlevel(RC_LEVEL_SYSINIT); TAILQ_CONCAT(start_services, tmplist, entries); free(tmplist); - if (strcmp (newlevel ? newlevel : runlevel, bootlevel) != 0) { - tmplist = rc_services_in_runlevel(newlevel ? - newlevel : runlevel); - TAILQ_CONCAT(start_services, tmplist, entries); - free(tmplist); - } - - if (hotplugged_services) { - if (!start_services) - start_services = rc_stringlist_new(); - TAILQ_FOREACH(service, hotplugged_services, entries) - rc_stringlist_addu(start_services, service->value); + if (strcmp(newlevel ? runlevel : runlevel, + RC_LEVEL_SINGLE) != 0) + { + if (strcmp(newlevel ? newlevel : runlevel, + bootlevel) != 0) + { + tmplist = rc_services_in_runlevel(bootlevel); + TAILQ_CONCAT(start_services, tmplist, entries); + free(tmplist); + } + if (hotplugged_services) { + TAILQ_FOREACH(service, hotplugged_services, + entries) + rc_stringlist_addu(start_services, + service->value); + } } } @@ -994,15 +999,12 @@ main(int argc, char **argv) setenv("RC_RUNLEVEL", runlevel, 1); } - /* Run the halt script if needed */ - if (strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0 || - strcmp(runlevel, RC_LEVEL_REBOOT) == 0) - { +#ifdef __linux__ + /* We can't log beyond this point as the shutdown runlevel + * will mount / readonly. */ + if (strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0) rc_logger_close(); - execl(HALTSH, HALTSH, runlevel, (char *) NULL); - eerrorx("%s: unable to exec `%s': %s", - applet, HALTSH, strerror(errno)); - } +#endif mkdir(RC_STARTING, 0755); rc_plugin_run(RC_HOOK_RUNLEVEL_START_IN, runlevel); @@ -1064,5 +1066,18 @@ main(int argc, char **argv) if (regen && strcmp(runlevel, bootlevel) == 0) unlink(RC_DEPTREE_CACHE); +#ifdef __linux__ + /* Run our halt script if it exists + * We only do this for compat with Gentoo sysvinit which + * should run halt.sh itself. */ + if (exists(HALTSH)) { + if (strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0) { + execl(HALTSH, HALTSH, (char *) NULL); + eerrorx("%s: unable to exec `%s': %s", + applet, HALTSH, strerror(errno)); + } + } +#endif + return EXIT_SUCCESS; } diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 4fc12bfe..d0557307 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -519,6 +519,9 @@ svc_exec(const char *arg1, const char *arg2) } execok = rc_waitpid(service_pid) == 0 ? true : false; + if (!execok && errno == ECHILD) + /* killall5 -9 could cause this */ + execok = true; service_pid = 0; return execok; @@ -1009,8 +1012,6 @@ svc_stop(bool deps) (strcmp(runlevel, RC_LEVEL_SHUTDOWN) == 0 || strcmp(runlevel, - RC_LEVEL_REBOOT) == 0 || - strcmp(runlevel, RC_LEVEL_SINGLE) == 0)) continue; rc_service_mark(service, RC_SERVICE_FAILED); |