We no longer care about numerical runlevels, #184733.
This commit is contained in:
parent
ae160bf293
commit
1cda2a2036
@ -1,6 +1,10 @@
|
||||
# ChangeLog for Gentoo System Intialization ("rc") scripts
|
||||
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2
|
||||
|
||||
10 Jul 2007; Roy Marples <uberlord@gentoo.org>:
|
||||
|
||||
We no longer care about numerical runlevels, #184733.
|
||||
|
||||
09 Jul 2007; Roy Marples <uberlord@gentoo.org>:
|
||||
|
||||
Add an option to fork ldconfig in env-update, #182794
|
||||
|
131
src/rc.c
131
src/rc.c
@ -475,6 +475,30 @@ static void set_ksoftlevel (const char *runlevel)
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
static int get_ksoftlevel (char *buffer, int buffer_len)
|
||||
{
|
||||
FILE *fp;
|
||||
int i = 0;
|
||||
|
||||
if (! rc_exists (RC_SVCDIR "ksoftlevel"))
|
||||
return 0;
|
||||
|
||||
if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r"))) {
|
||||
eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fgets (buffer, buffer_len, fp)) {
|
||||
i = strlen (buffer) - 1;
|
||||
if (buffer[i] == '\n')
|
||||
buffer[i] = 0;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
return i;
|
||||
}
|
||||
|
||||
static void wait_for_services ()
|
||||
{
|
||||
int status = 0;
|
||||
@ -753,10 +777,22 @@ int main (int argc, char **argv)
|
||||
RUNLEVEL = getenv ("RUNLEVEL");
|
||||
PREVLEVEL = getenv ("PREVLEVEL");
|
||||
|
||||
if (RUNLEVEL && newlevel) {
|
||||
if (strcmp (RUNLEVEL, "S") == 0 || strcmp (RUNLEVEL, "1") == 0) {
|
||||
|
||||
/* Load current softlevel */
|
||||
runlevel = rc_get_runlevel ();
|
||||
|
||||
/* Check we're in the runlevel requested, ie from
|
||||
rc single
|
||||
rc shutdown
|
||||
rc reboot
|
||||
*/
|
||||
if (newlevel) {
|
||||
if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0 &&
|
||||
RUNLEVEL &&
|
||||
(strcmp (RUNLEVEL, "S") == 0 ||
|
||||
strcmp (RUNLEVEL, "1") == 0))
|
||||
{
|
||||
/* OK, we're either in runlevel 1 or single user mode */
|
||||
if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0) {
|
||||
struct utsname uts;
|
||||
#ifdef __linux__
|
||||
FILE *fp;
|
||||
@ -820,68 +856,12 @@ int main (int argc, char **argv)
|
||||
mark_interactive ();
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/* Parse the inittab file so we can work out the level to telinit */
|
||||
if (strcmp (newlevel, RC_LEVEL_BOOT) != 0 &&
|
||||
strcmp (newlevel, RC_LEVEL_SINGLE) != 0)
|
||||
{
|
||||
char **inittab = rc_get_list (NULL, "/etc/inittab");
|
||||
char *line;
|
||||
char *p;
|
||||
char *token;
|
||||
char lvl[2] = {0, 0};
|
||||
|
||||
STRLIST_FOREACH (inittab, line, i) {
|
||||
p = line;
|
||||
token = strsep (&p, ":");
|
||||
if (! token || token[0] != 'l')
|
||||
continue;
|
||||
|
||||
if ((token = strsep (&p, ":")) == NULL)
|
||||
continue;
|
||||
|
||||
/* Snag the level */
|
||||
lvl[0] = token[0];
|
||||
|
||||
/* The name is spaced after this */
|
||||
if ((token = strsep (&p, " ")) == NULL)
|
||||
continue;
|
||||
|
||||
if ((token = strsep (&p, " ")) == NULL)
|
||||
continue;
|
||||
|
||||
if (strcmp (token, newlevel) == 0)
|
||||
break;
|
||||
}
|
||||
rc_strlist_free (inittab);
|
||||
|
||||
/* We have a level, so telinit into it */
|
||||
if (lvl[0] == 0) {
|
||||
eerrorx ("%s: couldn't find a runlevel called `%s'",
|
||||
applet, newlevel);
|
||||
} else {
|
||||
execl ("/sbin/telinit", "/sbin/telinit", lvl, (char *) NULL);
|
||||
eerrorx ("%s: unable to exec `/sbin/telinit': %s",
|
||||
applet, strerror (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we're in the runlevel requested, ie from
|
||||
rc single
|
||||
rc shutdown
|
||||
rc reboot
|
||||
*/
|
||||
if (newlevel) {
|
||||
if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) {
|
||||
} else if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) {
|
||||
if (! RUNLEVEL ||
|
||||
(strcmp (RUNLEVEL, "S") != 0 &&
|
||||
strcmp (RUNLEVEL, "1") != 0))
|
||||
{
|
||||
einfo ("Setting %s", runlevel);
|
||||
/* Remember the current runlevel for when we come back */
|
||||
set_ksoftlevel (runlevel);
|
||||
single_user ();
|
||||
@ -911,18 +891,9 @@ int main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Export our current softlevel */
|
||||
runlevel = rc_get_runlevel ();
|
||||
|
||||
/* Now we start handling our children */
|
||||
signal (SIGCHLD, handle_signal);
|
||||
|
||||
/* If we're in the default runlevel and ksoftlevel exists, we should use
|
||||
that instead */
|
||||
if (newlevel &&
|
||||
rc_exists (RC_SVCDIR "ksoftlevel") &&
|
||||
strcmp (newlevel, RC_LEVEL_DEFAULT) == 0)
|
||||
{
|
||||
/* We should only use ksoftlevel if we were in single user mode
|
||||
If not, we need to erase ksoftlevel now. */
|
||||
if (PREVLEVEL &&
|
||||
@ -930,21 +901,13 @@ int main (int argc, char **argv)
|
||||
strcmp (PREVLEVEL, "S") == 0 ||
|
||||
strcmp (PREVLEVEL, "N") == 0))
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
|
||||
eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
|
||||
strerror (errno));
|
||||
else {
|
||||
if (fgets (ksoftbuffer, sizeof (ksoftbuffer), fp)) {
|
||||
i = strlen (ksoftbuffer) - 1;
|
||||
if (ksoftbuffer[i] == '\n')
|
||||
ksoftbuffer[i] = 0;
|
||||
if (get_ksoftlevel (ksoftbuffer, sizeof (ksoftbuffer)))
|
||||
newlevel = ksoftbuffer;
|
||||
}
|
||||
fclose (fp);
|
||||
}
|
||||
} else
|
||||
} else if (! RUNLEVEL ||
|
||||
(strcmp (RUNLEVEL, "1") != 0 &&
|
||||
strcmp (RUNLEVEL, "S") != 0 &&
|
||||
strcmp (RUNLEVEL, "N") != 0))
|
||||
{
|
||||
set_ksoftlevel (NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user