aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-10-27 18:01:03 +0000
committerRoy Marples <roy@marples.name>2008-10-27 18:01:03 +0000
commit0d98d56188527109da1e334b19b4cc2e92499246 (patch)
treee327abad42788fb4b1531c8841c46b56c9c8b99a
parentae692e294e3b1679c1eb0f7aedddc6fe943963da (diff)
Remove sysvinit specific code.
The runlevels shutdown, reboot, sysinit and single should be called by init(8) and shutdown(8) and not manually. sysvinit users will have to add sulogin to their inittab to secure the console.
-rw-r--r--etc/rc.in9
-rw-r--r--etc/rc.shutdown.in9
-rw-r--r--man/rc.821
-rw-r--r--src/rc/rc.c185
4 files changed, 65 insertions, 159 deletions
diff --git a/etc/rc.in b/etc/rc.in
index aab7cbb8..53fe24f7 100644
--- a/etc/rc.in
+++ b/etc/rc.in
@@ -10,12 +10,9 @@
trap : SIGINT
trap "echo 'Boot interrupted'; exit 1" SIGQUIT
-# BSD's init works somewhat differently to sysvinit.
-# This block should 'translate' from the way init calls it to the way it would
-# be called by sysvinit on linux.
-RUNLEVEL="1" /sbin/rc sysinit || exit 1
-RUNLEVEL="1" /sbin/rc boot || exit 1
-PREVLEVEL="1" /sbin/rc default
+/sbin/rc sysinit || exit 1
+/sbin/rc boot || exit 1
+/sbin/rc default
# We don't actually care if rc default worked or not, we should exit 0
# to allow logins
diff --git a/etc/rc.shutdown.in b/etc/rc.shutdown.in
index e26e8468..f3b8568e 100644
--- a/etc/rc.shutdown.in
+++ b/etc/rc.shutdown.in
@@ -14,13 +14,4 @@ export LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}"
[ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@"
action=${1:-shutdown}
-
-# BSD's init works somewhat differently to sysvinit.
-# This block should 'translate' from the way init calls it to the way it would
-# be called by sysvinit on linux.
-case "${action}" in
- reboot) export RUNLEVEL=6;;
- single) export RUNLEVEL=S;;
- *) export RUNLEVEL=0;;
-esac
exec /sbin/rc "${action}"
diff --git a/man/rc.8 b/man/rc.8
index c85bd2bb..e0e31987 100644
--- a/man/rc.8
+++ b/man/rc.8
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd Feb 22, 2008
+.Dd October 27, 2008
.Dt RC 8 SMM
.Os OpenRC
.Sh NAME
@@ -60,18 +60,27 @@ sysinit always runs when the host first starts should not be run again.
Generally the only services you should add to the boot runlevel are those
which deal with the mounting of filesystems, set the initial state of attached
peripherals and logging.
-Coldplugged services are added to the boot runlevel by the system.
-All services in the boot runlevel are automatically included in all other
-runlevels except for those listed here.
+Hotplugged services are added to the boot runlevel by the system.
+All services in the boot and sysinit runlevels are automatically included
+in all other runlevels except for those listed here.
.It Ar single
-Stops all services and enters single user mode.
+Stops all services except for those in the sysinit runlevel.
.It Ar reboot
Changes to the single runlevel and then reboots the host.
.It Ar shutdown
Changes to the single runlevel and then halts the host.
.El
+.Pp
+You should not call any of these runlevels yourself.
+Instead you should use
+.Xr init 8
+and
+.Xr shutdown 8
+and let them call these special runlevels.
.Sh SEE ALSO
.Xr rc-status 8 ,
-.Xr rc-update 8
+.Xr rc-update 8 ,
+.Xr init 8 ,
+.Xr shutdown 8
.Sh AUTHORS
.An Roy Marples <roy@marples.name>
diff --git a/src/rc/rc.c b/src/rc/rc.c
index f268bcb6..a6aa5dbb 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -82,9 +82,6 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#define DEVBOOT "/dev/.rcboot"
-static char *RUNLEVEL = NULL;
-static char *PREVLEVEL = NULL;
-
const char *applet = NULL;
static char *runlevel = NULL;
static RC_STRINGLIST *hotplugged_services = NULL;
@@ -250,12 +247,6 @@ static bool want_interactive(void)
if (rc_yesno(getenv("EINFO_QUIET")))
return false;
- if (PREVLEVEL &&
- strcmp(PREVLEVEL, "N") != 0 &&
- strcmp(PREVLEVEL, "S") != 0 &&
- strcmp(PREVLEVEL, "1") != 0)
- return false;
-
if (! gotinteractive) {
gotinteractive = true;
interactive = rc_conf_yesno("rc_interactive");
@@ -334,13 +325,6 @@ static void sulogin(bool cont)
if (! cont) {
rc_logger_close();
-#ifdef __linux__
- if (RUNLEVEL && strcmp(RUNLEVEL, "S") == 0) {
- execl("/sbin/sulogin", "/sbin/sulogin", (char *) NULL);
- eerrorx("%s: unable to exec `/sbin/sulogin': %s",
- applet, strerror(errno));
- }
-#endif
exit(EXIT_SUCCESS);
}
@@ -493,15 +477,6 @@ static void handle_signal(int sig)
/* Notify plugins we are aborting */
rc_plugin_run(RC_HOOK_ABORT, NULL);
- /* Only drop into single user mode if we're booting */
- if ((PREVLEVEL &&
- (strcmp(PREVLEVEL, "S") == 0 ||
- strcmp(PREVLEVEL, "1") == 0)) ||
- (RUNLEVEL &&
- (strcmp(RUNLEVEL, "S") == 0 ||
- strcmp(RUNLEVEL, "1") == 0)))
- single_user();
-
exit(EXIT_FAILURE);
/* NOTREACHED */
@@ -513,94 +488,49 @@ static void handle_signal(int sig)
errno = serrno;
}
-static void do_newlevel(const char *newlevel)
+static void
+do_sysinit()
{
struct utsname uts;
const char *sys;
- if (strcmp(newlevel, RC_LEVEL_SYSINIT) == 0
-#ifndef PREFIX
- && RUNLEVEL &&
- (strcmp(RUNLEVEL, "S") == 0 ||
- strcmp(RUNLEVEL, "1") == 0)
-#endif
- )
- {
- /* OK, we're either in runlevel 1 or single user mode */
-
- /* exec init-early.sh if it exists
- * This should just setup the console to use the correct
- * font. Maybe it should setup the keyboard too? */
- if (exists(INITEARLYSH))
- run_program(INITEARLYSH);
-
- uname(&uts);
- printf("\n %sOpenRC %s" VERSION "%s is starting up %s",
- ecolor(ECOLOR_GOOD), ecolor(ECOLOR_HILITE),
- ecolor(ECOLOR_NORMAL), ecolor(ECOLOR_BRACKET));
+ /* exec init-early.sh if it exists
+ * This should just setup the console to use the correct
+ * font. Maybe it should setup the keyboard too? */
+ if (exists(INITEARLYSH))
+ run_program(INITEARLYSH);
+
+ uname(&uts);
+ printf("\n %sOpenRC %s" VERSION "%s is starting up %s",
+ ecolor(ECOLOR_GOOD), ecolor(ECOLOR_HILITE),
+ ecolor(ECOLOR_NORMAL), ecolor(ECOLOR_BRACKET));
#ifdef BRANDING
- printf(BRANDING " (%s)", uts.machine);
+ printf(BRANDING " (%s)", uts.machine);
#else
- printf("%s %s (%s)",
- uts.sysname,
- uts.release,
- uts.machine);
+ printf("%s %s (%s)",
+ uts.sysname,
+ uts.release,
+ uts.machine);
#endif
- if ((sys = rc_sys()))
- printf(" [%s]", sys);
+ if ((sys = rc_sys()))
+ printf(" [%s]", sys);
- printf("%s\n\n", ecolor(ECOLOR_NORMAL));
+ printf("%s\n\n", ecolor(ECOLOR_NORMAL));
- if (! rc_yesno(getenv ("EINFO_QUIET")) &&
- rc_conf_yesno("rc_interactive"))
- printf("Press %sI%s to enter interactive boot mode\n\n",
- ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
+ if (! rc_yesno(getenv ("EINFO_QUIET")) &&
+ rc_conf_yesno("rc_interactive"))
+ printf("Press %sI%s to enter interactive boot mode\n\n",
+ ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
- setenv("RC_RUNLEVEL", newlevel, 1);
- run_program(INITSH);
-
- /* init may have mounted /proc so we can now detect or real
- * sys */
- if ((sys = rc_sys()))
- setenv("RC_SYS", sys, 1);
- } else if (strcmp(newlevel, RC_LEVEL_SINGLE) == 0) {
-#ifndef PREFIX
- if (! RUNLEVEL ||
- (strcmp(RUNLEVEL, "S") != 0 &&
- strcmp(RUNLEVEL, "1") != 0))
- {
- set_krunlevel(runlevel);
- single_user();
- }
-#endif
- } else if (strcmp(newlevel, RC_LEVEL_REBOOT) == 0) {
- if (! RUNLEVEL ||
- strcmp(RUNLEVEL, "6") != 0)
- {
- rc_logger_close();
- execl(SHUTDOWN, SHUTDOWN, "-r", "now", (char *) NULL);
- eerrorx("%s: unable to exec `" SHUTDOWN "': %s",
- applet, strerror(errno));
- }
- } else if (strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0) {
- if (! RUNLEVEL ||
- strcmp(RUNLEVEL, "0") != 0)
- {
- rc_logger_close();
- execl(SHUTDOWN, SHUTDOWN,
-#ifdef __linux__
- "-h",
-#else
- "-p",
-#endif
- "now", (char *) NULL);
- eerrorx("%s: unable to exec `" SHUTDOWN "': %s",
- applet, strerror(errno));
- }
- }
-}
+ setenv("RC_RUNLEVEL", RC_LEVEL_SYSINIT, 1);
+ run_program(INITSH);
+ /* init may have mounted /proc so we can now detect or real
+ * sys */
+ if ((sys = rc_sys()))
+ setenv("RC_SYS", sys, 1);
+}
static bool runlevel_config(const char *service, const char *level)
{
@@ -849,11 +779,6 @@ int main(int argc, char **argv)
/* Change dir to / to ensure all scripts don't use stuff in pwd */
chdir("/");
- /* RUNLEVEL is set by sysvinit as is a magic number
- * RC_RUNLEVEL is set by us and is the name for this magic number */
- RUNLEVEL = getenv("RUNLEVEL");
- PREVLEVEL = getenv("PREVLEVEL");
-
/* Ensure our environment is pure
* Also, add our configuration to it */
env_filter();
@@ -914,37 +839,24 @@ int main(int argc, char **argv)
rc_plugin_load();
- /* Check we're in the runlevel requested, ie from
- * rc single
- * rc shutdown
- * rc reboot
- */
- if (newlevel)
- do_newlevel(newlevel);
+ /* Run any special sysinit foo */
+ if (newlevel && strcmp(newlevel, RC_LEVEL_SYSINIT) == 0)
+ do_sysinit();
/* Now we start handling our children */
signal_setup(SIGCHLD, handle_signal);
/* We should only use krunlevel if we were in single user mode
* If not, we need to erase krunlevel now. */
- if (PREVLEVEL &&
- (strcmp(PREVLEVEL, "1") == 0 ||
- strcmp(PREVLEVEL, "S") == 0 ||
- strcmp(PREVLEVEL, "N") == 0))
- {
+ if (strcmp(runlevel, RC_LEVEL_SINGLE) == 0) {
/* Try not to join boot and krunlevels together */
if (! newlevel ||
(strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0 &&
strcmp(newlevel, RC_LEVEL_SYSINIT) != 0))
if (get_krunlevel(krunlevel, sizeof(krunlevel)))
newlevel = krunlevel;
- } else if (! RUNLEVEL ||
- (strcmp(RUNLEVEL, "1") != 0 &&
- strcmp(RUNLEVEL, "S") != 0 &&
- strcmp(RUNLEVEL, "N") != 0))
- {
+ } else
set_krunlevel(NULL);
- }
if (newlevel &&
(strcmp(newlevel, RC_LEVEL_REBOOT) == 0 ||
@@ -952,6 +864,7 @@ int main(int argc, char **argv)
strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
{
going_down = true;
+ set_krunlevel(runlevel);
rc_runlevel_set(newlevel);
setenv("RC_RUNLEVEL", newlevel, 1);
setenv("RC_GOINGDOWN", "YES", 1);
@@ -1095,13 +1008,11 @@ int main(int argc, char **argv)
#ifdef __linux__
/* mark any services skipped as started */
- if (PREVLEVEL && strcmp(PREVLEVEL, "N") == 0) {
- proc = p = proc_getent("noinitd");
- if (proc) {
- while ((token = strsep(&p, ",")))
- rc_service_mark(token, RC_SERVICE_STARTED);
- free(proc);
- }
+ proc = p = proc_getent("noinitd");
+ if (proc) {
+ while ((token = strsep(&p, ",")))
+ rc_service_mark(token, RC_SERVICE_STARTED);
+ free(proc);
}
#endif
@@ -1118,13 +1029,11 @@ int main(int argc, char **argv)
#ifdef __linux__
/* mark any services skipped as stopped */
- if (PREVLEVEL && strcmp(PREVLEVEL, "N") == 0) {
- proc = p = proc_getent("noinitd");
- if (proc) {
- while ((token = strsep(&p, ",")))
- rc_service_mark(token, RC_SERVICE_STOPPED);
- free(proc);
- }
+ proc = p = proc_getent("noinitd");
+ if (proc) {
+ while ((token = strsep(&p, ",")))
+ rc_service_mark(token, RC_SERVICE_STOPPED);
+ free(proc);
}
#endif