aboutsummaryrefslogtreecommitdiff
path: root/src/rc
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-11-03 15:31:01 +0000
committerRoy Marples <roy@marples.name>2008-11-03 15:31:01 +0000
commit0af7d5bc204cd6b7d03f22aacf4072c5f526c0ee (patch)
treeaa819c4140f8c34bd3814ae5894a8b6214fff914 /src/rc
parent895c4f41492199d6aee75bb6c5a935134d67c29e (diff)
Add a new shutdown runlevel, Gentoo #224537.
Split halt.sh into halt, killprocs, romount and savecache services. The reboot runlevel is removed but mapped to shutdown. The halt script should be moved to the sysvinit package.
Diffstat (limited to 'src/rc')
-rw-r--r--src/rc/rc.c79
-rw-r--r--src/rc/runscript.c5
2 files changed, 50 insertions, 34 deletions
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);