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.
This commit is contained in:
parent
ae692e294e
commit
0d98d56188
@ -10,12 +10,9 @@
|
|||||||
trap : SIGINT
|
trap : SIGINT
|
||||||
trap "echo 'Boot interrupted'; exit 1" SIGQUIT
|
trap "echo 'Boot interrupted'; exit 1" SIGQUIT
|
||||||
|
|
||||||
# BSD's init works somewhat differently to sysvinit.
|
/sbin/rc sysinit || exit 1
|
||||||
# This block should 'translate' from the way init calls it to the way it would
|
/sbin/rc boot || exit 1
|
||||||
# be called by sysvinit on linux.
|
/sbin/rc default
|
||||||
RUNLEVEL="1" /sbin/rc sysinit || exit 1
|
|
||||||
RUNLEVEL="1" /sbin/rc boot || exit 1
|
|
||||||
PREVLEVEL="1" /sbin/rc default
|
|
||||||
|
|
||||||
# We don't actually care if rc default worked or not, we should exit 0
|
# We don't actually care if rc default worked or not, we should exit 0
|
||||||
# to allow logins
|
# to allow logins
|
||||||
|
@ -14,13 +14,4 @@ export LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}"
|
|||||||
[ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@"
|
[ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@"
|
||||||
|
|
||||||
action=${1:-shutdown}
|
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}"
|
exec /sbin/rc "${action}"
|
||||||
|
21
man/rc.8
21
man/rc.8
@ -22,7 +22,7 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd Feb 22, 2008
|
.Dd October 27, 2008
|
||||||
.Dt RC 8 SMM
|
.Dt RC 8 SMM
|
||||||
.Os OpenRC
|
.Os OpenRC
|
||||||
.Sh NAME
|
.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
|
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
|
which deal with the mounting of filesystems, set the initial state of attached
|
||||||
peripherals and logging.
|
peripherals and logging.
|
||||||
Coldplugged services are added to the boot runlevel by the system.
|
Hotplugged services are added to the boot runlevel by the system.
|
||||||
All services in the boot runlevel are automatically included in all other
|
All services in the boot and sysinit runlevels are automatically included
|
||||||
runlevels except for those listed here.
|
in all other runlevels except for those listed here.
|
||||||
.It Ar single
|
.It Ar single
|
||||||
Stops all services and enters single user mode.
|
Stops all services except for those in the sysinit runlevel.
|
||||||
.It Ar reboot
|
.It Ar reboot
|
||||||
Changes to the single runlevel and then reboots the host.
|
Changes to the single runlevel and then reboots the host.
|
||||||
.It Ar shutdown
|
.It Ar shutdown
|
||||||
Changes to the single runlevel and then halts the host.
|
Changes to the single runlevel and then halts the host.
|
||||||
.El
|
.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
|
.Sh SEE ALSO
|
||||||
.Xr rc-status 8 ,
|
.Xr rc-status 8 ,
|
||||||
.Xr rc-update 8
|
.Xr rc-update 8 ,
|
||||||
|
.Xr init 8 ,
|
||||||
|
.Xr shutdown 8
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.An Roy Marples <roy@marples.name>
|
.An Roy Marples <roy@marples.name>
|
||||||
|
181
src/rc/rc.c
181
src/rc/rc.c
@ -82,9 +82,6 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
|
|||||||
|
|
||||||
#define DEVBOOT "/dev/.rcboot"
|
#define DEVBOOT "/dev/.rcboot"
|
||||||
|
|
||||||
static char *RUNLEVEL = NULL;
|
|
||||||
static char *PREVLEVEL = NULL;
|
|
||||||
|
|
||||||
const char *applet = NULL;
|
const char *applet = NULL;
|
||||||
static char *runlevel = NULL;
|
static char *runlevel = NULL;
|
||||||
static RC_STRINGLIST *hotplugged_services = NULL;
|
static RC_STRINGLIST *hotplugged_services = NULL;
|
||||||
@ -250,12 +247,6 @@ static bool want_interactive(void)
|
|||||||
if (rc_yesno(getenv("EINFO_QUIET")))
|
if (rc_yesno(getenv("EINFO_QUIET")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (PREVLEVEL &&
|
|
||||||
strcmp(PREVLEVEL, "N") != 0 &&
|
|
||||||
strcmp(PREVLEVEL, "S") != 0 &&
|
|
||||||
strcmp(PREVLEVEL, "1") != 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (! gotinteractive) {
|
if (! gotinteractive) {
|
||||||
gotinteractive = true;
|
gotinteractive = true;
|
||||||
interactive = rc_conf_yesno("rc_interactive");
|
interactive = rc_conf_yesno("rc_interactive");
|
||||||
@ -334,13 +325,6 @@ static void sulogin(bool cont)
|
|||||||
|
|
||||||
if (! cont) {
|
if (! cont) {
|
||||||
rc_logger_close();
|
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);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,15 +477,6 @@ static void handle_signal(int sig)
|
|||||||
/* Notify plugins we are aborting */
|
/* Notify plugins we are aborting */
|
||||||
rc_plugin_run(RC_HOOK_ABORT, NULL);
|
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);
|
exit(EXIT_FAILURE);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
|
||||||
@ -513,95 +488,50 @@ static void handle_signal(int sig)
|
|||||||
errno = serrno;
|
errno = serrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_newlevel(const char *newlevel)
|
static void
|
||||||
|
do_sysinit()
|
||||||
{
|
{
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
const char *sys;
|
const char *sys;
|
||||||
|
|
||||||
if (strcmp(newlevel, RC_LEVEL_SYSINIT) == 0
|
/* exec init-early.sh if it exists
|
||||||
#ifndef PREFIX
|
* This should just setup the console to use the correct
|
||||||
&& RUNLEVEL &&
|
* font. Maybe it should setup the keyboard too? */
|
||||||
(strcmp(RUNLEVEL, "S") == 0 ||
|
if (exists(INITEARLYSH))
|
||||||
strcmp(RUNLEVEL, "1") == 0)
|
run_program(INITEARLYSH);
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
/* OK, we're either in runlevel 1 or single user mode */
|
|
||||||
|
|
||||||
/* exec init-early.sh if it exists
|
uname(&uts);
|
||||||
* This should just setup the console to use the correct
|
printf("\n %sOpenRC %s" VERSION "%s is starting up %s",
|
||||||
* font. Maybe it should setup the keyboard too? */
|
ecolor(ECOLOR_GOOD), ecolor(ECOLOR_HILITE),
|
||||||
if (exists(INITEARLYSH))
|
ecolor(ECOLOR_NORMAL), ecolor(ECOLOR_BRACKET));
|
||||||
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
|
#ifdef BRANDING
|
||||||
printf(BRANDING " (%s)", uts.machine);
|
printf(BRANDING " (%s)", uts.machine);
|
||||||
#else
|
#else
|
||||||
printf("%s %s (%s)",
|
printf("%s %s (%s)",
|
||||||
uts.sysname,
|
uts.sysname,
|
||||||
uts.release,
|
uts.release,
|
||||||
uts.machine);
|
uts.machine);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((sys = rc_sys()))
|
if ((sys = rc_sys()))
|
||||||
printf(" [%s]", sys);
|
printf(" [%s]", sys);
|
||||||
|
|
||||||
printf("%s\n\n", ecolor(ECOLOR_NORMAL));
|
printf("%s\n\n", ecolor(ECOLOR_NORMAL));
|
||||||
|
|
||||||
if (! rc_yesno(getenv ("EINFO_QUIET")) &&
|
if (! rc_yesno(getenv ("EINFO_QUIET")) &&
|
||||||
rc_conf_yesno("rc_interactive"))
|
rc_conf_yesno("rc_interactive"))
|
||||||
printf("Press %sI%s to enter interactive boot mode\n\n",
|
printf("Press %sI%s to enter interactive boot mode\n\n",
|
||||||
ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
|
ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
|
||||||
|
|
||||||
setenv("RC_RUNLEVEL", newlevel, 1);
|
setenv("RC_RUNLEVEL", RC_LEVEL_SYSINIT, 1);
|
||||||
run_program(INITSH);
|
run_program(INITSH);
|
||||||
|
|
||||||
/* init may have mounted /proc so we can now detect or real
|
/* init may have mounted /proc so we can now detect or real
|
||||||
* sys */
|
* sys */
|
||||||
if ((sys = rc_sys()))
|
if ((sys = rc_sys()))
|
||||||
setenv("RC_SYS", sys, 1);
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool runlevel_config(const char *service, const char *level)
|
static bool runlevel_config(const char *service, const char *level)
|
||||||
{
|
{
|
||||||
char *init = rc_service_resolve(service);
|
char *init = rc_service_resolve(service);
|
||||||
@ -849,11 +779,6 @@ int main(int argc, char **argv)
|
|||||||
/* Change dir to / to ensure all scripts don't use stuff in pwd */
|
/* Change dir to / to ensure all scripts don't use stuff in pwd */
|
||||||
chdir("/");
|
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
|
/* Ensure our environment is pure
|
||||||
* Also, add our configuration to it */
|
* Also, add our configuration to it */
|
||||||
env_filter();
|
env_filter();
|
||||||
@ -914,37 +839,24 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
rc_plugin_load();
|
rc_plugin_load();
|
||||||
|
|
||||||
/* Check we're in the runlevel requested, ie from
|
/* Run any special sysinit foo */
|
||||||
* rc single
|
if (newlevel && strcmp(newlevel, RC_LEVEL_SYSINIT) == 0)
|
||||||
* rc shutdown
|
do_sysinit();
|
||||||
* rc reboot
|
|
||||||
*/
|
|
||||||
if (newlevel)
|
|
||||||
do_newlevel(newlevel);
|
|
||||||
|
|
||||||
/* Now we start handling our children */
|
/* Now we start handling our children */
|
||||||
signal_setup(SIGCHLD, handle_signal);
|
signal_setup(SIGCHLD, handle_signal);
|
||||||
|
|
||||||
/* We should only use krunlevel if we were in single user mode
|
/* We should only use krunlevel if we were in single user mode
|
||||||
* If not, we need to erase krunlevel now. */
|
* If not, we need to erase krunlevel now. */
|
||||||
if (PREVLEVEL &&
|
if (strcmp(runlevel, RC_LEVEL_SINGLE) == 0) {
|
||||||
(strcmp(PREVLEVEL, "1") == 0 ||
|
|
||||||
strcmp(PREVLEVEL, "S") == 0 ||
|
|
||||||
strcmp(PREVLEVEL, "N") == 0))
|
|
||||||
{
|
|
||||||
/* Try not to join boot and krunlevels together */
|
/* Try not to join boot and krunlevels together */
|
||||||
if (! newlevel ||
|
if (! newlevel ||
|
||||||
(strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0 &&
|
(strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0 &&
|
||||||
strcmp(newlevel, RC_LEVEL_SYSINIT) != 0))
|
strcmp(newlevel, RC_LEVEL_SYSINIT) != 0))
|
||||||
if (get_krunlevel(krunlevel, sizeof(krunlevel)))
|
if (get_krunlevel(krunlevel, sizeof(krunlevel)))
|
||||||
newlevel = krunlevel;
|
newlevel = krunlevel;
|
||||||
} else if (! RUNLEVEL ||
|
} else
|
||||||
(strcmp(RUNLEVEL, "1") != 0 &&
|
|
||||||
strcmp(RUNLEVEL, "S") != 0 &&
|
|
||||||
strcmp(RUNLEVEL, "N") != 0))
|
|
||||||
{
|
|
||||||
set_krunlevel(NULL);
|
set_krunlevel(NULL);
|
||||||
}
|
|
||||||
|
|
||||||
if (newlevel &&
|
if (newlevel &&
|
||||||
(strcmp(newlevel, RC_LEVEL_REBOOT) == 0 ||
|
(strcmp(newlevel, RC_LEVEL_REBOOT) == 0 ||
|
||||||
@ -952,6 +864,7 @@ int main(int argc, char **argv)
|
|||||||
strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
|
strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
|
||||||
{
|
{
|
||||||
going_down = true;
|
going_down = true;
|
||||||
|
set_krunlevel(runlevel);
|
||||||
rc_runlevel_set(newlevel);
|
rc_runlevel_set(newlevel);
|
||||||
setenv("RC_RUNLEVEL", newlevel, 1);
|
setenv("RC_RUNLEVEL", newlevel, 1);
|
||||||
setenv("RC_GOINGDOWN", "YES", 1);
|
setenv("RC_GOINGDOWN", "YES", 1);
|
||||||
@ -1095,13 +1008,11 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* mark any services skipped as started */
|
/* mark any services skipped as started */
|
||||||
if (PREVLEVEL && strcmp(PREVLEVEL, "N") == 0) {
|
proc = p = proc_getent("noinitd");
|
||||||
proc = p = proc_getent("noinitd");
|
if (proc) {
|
||||||
if (proc) {
|
while ((token = strsep(&p, ",")))
|
||||||
while ((token = strsep(&p, ",")))
|
rc_service_mark(token, RC_SERVICE_STARTED);
|
||||||
rc_service_mark(token, RC_SERVICE_STARTED);
|
free(proc);
|
||||||
free(proc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1118,13 +1029,11 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* mark any services skipped as stopped */
|
/* mark any services skipped as stopped */
|
||||||
if (PREVLEVEL && strcmp(PREVLEVEL, "N") == 0) {
|
proc = p = proc_getent("noinitd");
|
||||||
proc = p = proc_getent("noinitd");
|
if (proc) {
|
||||||
if (proc) {
|
while ((token = strsep(&p, ",")))
|
||||||
while ((token = strsep(&p, ",")))
|
rc_service_mark(token, RC_SERVICE_STOPPED);
|
||||||
rc_service_mark(token, RC_SERVICE_STOPPED);
|
free(proc);
|
||||||
free(proc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user