runlevel override works correctly again.
This commit is contained in:
parent
1acbfcf5ca
commit
dc712a109e
54
src/rc/rc.c
54
src/rc/rc.c
@ -383,13 +383,13 @@ get_krunlevel(char *buffer, int buffer_len)
|
|||||||
return 0;
|
return 0;
|
||||||
if (!(fp = fopen(RC_KRUNLEVEL, "r"))) {
|
if (!(fp = fopen(RC_KRUNLEVEL, "r"))) {
|
||||||
eerror("fopen `%s': %s", RC_KRUNLEVEL, strerror(errno));
|
eerror("fopen `%s': %s", RC_KRUNLEVEL, strerror(errno));
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(buffer, buffer_len, fp)) {
|
if (fgets(buffer, buffer_len, fp)) {
|
||||||
i = strlen(buffer) - 1;
|
i = strlen(buffer);
|
||||||
if (buffer[i] == '\n')
|
if (buffer[i - 1] == '\n')
|
||||||
buffer[i] = 0;
|
buffer[i - 1] = 0;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return i;
|
return i;
|
||||||
@ -810,8 +810,14 @@ main(int argc, char **argv)
|
|||||||
case 'o':
|
case 'o':
|
||||||
if (*optarg == '\0')
|
if (*optarg == '\0')
|
||||||
optarg = NULL;
|
optarg = NULL;
|
||||||
exit(set_krunlevel(optarg) ?
|
if (!rc_runlevel_exists(optarg)) {
|
||||||
EXIT_SUCCESS : EXIT_FAILURE);
|
eerror("runlevel `%s' does not exist", optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!set_krunlevel(optarg))
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
einfo("Overriding next runlevel to %s", optarg);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case 's':
|
case 's':
|
||||||
newlevel = rc_service_resolve(optarg);
|
newlevel = rc_service_resolve(optarg);
|
||||||
@ -872,29 +878,35 @@ main(int argc, char **argv)
|
|||||||
/* 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
|
|
||||||
* If not, we need to erase krunlevel now. */
|
|
||||||
if (strcmp(runlevel, RC_LEVEL_SINGLE) == 0) {
|
|
||||||
/* Try not to join boot and krunlevels together */
|
|
||||||
if (!newlevel ||
|
|
||||||
(strcmp(newlevel, RC_LEVEL_SINGLE) != 0 &&
|
|
||||||
strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0 &&
|
|
||||||
strcmp(newlevel, RC_LEVEL_SYSINIT) != 0))
|
|
||||||
if (get_krunlevel(krunlevel, sizeof(krunlevel)))
|
|
||||||
newlevel = krunlevel;
|
|
||||||
} else
|
|
||||||
set_krunlevel(NULL);
|
|
||||||
|
|
||||||
if (newlevel &&
|
if (newlevel &&
|
||||||
(strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0 ||
|
(strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0 ||
|
||||||
strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
|
strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
|
||||||
{
|
{
|
||||||
going_down = true;
|
going_down = true;
|
||||||
set_krunlevel(runlevel);
|
if (!exists(RC_KRUNLEVEL))
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
/* We should not use krunevel in sysinit or the boot runlevel */
|
||||||
|
if (!newlevel ||
|
||||||
|
strcmp(newlevel, RC_LEVEL_SYSINIT) != 0 ||
|
||||||
|
strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0)
|
||||||
|
{
|
||||||
|
if (get_krunlevel(krunlevel, sizeof(krunlevel))) {
|
||||||
|
newlevel = krunlevel;
|
||||||
|
set_krunlevel(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newlevel &&
|
||||||
|
strcmp(runlevel, newlevel) != 0 &&
|
||||||
|
!rc_runlevel_exists(newlevel))
|
||||||
|
eerrorx("%s: is not a valid runlevel", newlevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (going_down) {
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
/* FIXME: we shouldn't have todo this */
|
/* FIXME: we shouldn't have todo this */
|
||||||
/* For some reason, wait_for_services waits for the logger
|
/* For some reason, wait_for_services waits for the logger
|
||||||
@ -963,7 +975,7 @@ main(int argc, char **argv)
|
|||||||
tmplist = rc_services_in_runlevel(RC_LEVEL_SYSINIT);
|
tmplist = rc_services_in_runlevel(RC_LEVEL_SYSINIT);
|
||||||
TAILQ_CONCAT(start_services, tmplist, entries);
|
TAILQ_CONCAT(start_services, tmplist, entries);
|
||||||
free(tmplist);
|
free(tmplist);
|
||||||
if (strcmp(newlevel ? runlevel : runlevel,
|
if (strcmp(newlevel ? newlevel : runlevel,
|
||||||
RC_LEVEL_SINGLE) != 0)
|
RC_LEVEL_SINGLE) != 0)
|
||||||
{
|
{
|
||||||
if (strcmp(newlevel ? newlevel : runlevel,
|
if (strcmp(newlevel ? newlevel : runlevel,
|
||||||
|
Loading…
Reference in New Issue
Block a user