mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
Store RUN_LVL in UTMP and change RUNLEVEL_BOOT from 10 to 0
Standard init implementations save current and previous runlevels in utmp, now finit does too. Also, the initial runlevel at boot has changed from 10 to the more obvious 0. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -71,10 +71,10 @@ int parse_runlevels(char *runlevels)
|
||||
}
|
||||
|
||||
if ('s' == lvl || 'S' == lvl)
|
||||
lvl = ':'; /* RUNLEVEL_BOOT */
|
||||
lvl = '0';
|
||||
|
||||
level = lvl - '0';
|
||||
if (level > RUNLEVEL_BOOT || level < 0)
|
||||
if (level > 9 || level < 0)
|
||||
continue;
|
||||
|
||||
if (not)
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
|
||||
int debug = 0;
|
||||
int verbose = 1;
|
||||
int runlevel = RUNLEVEL_BOOT; /* Bootstrap */
|
||||
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
||||
int prevlevel = 0; /* HALT */
|
||||
int runlevel = 0; /* Bootstrap */
|
||||
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
||||
int prevlevel = 0; /* HALT */
|
||||
char *sdown = NULL;
|
||||
char *network = NULL;
|
||||
char *username = NULL;
|
||||
|
||||
@@ -110,7 +110,7 @@ static void sigstop_handler(int sig, siginfo_t *info, void *UNUSED(ctx))
|
||||
_d("Received SIGSTOP(%d) from %s (PID %d)",
|
||||
sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid);
|
||||
touch(SYNC_STOPPED);
|
||||
stopped ++;
|
||||
stopped++;
|
||||
}
|
||||
static void sigcont_handler(int sig, siginfo_t *info, void *UNUSED(ctx))
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <utmp.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -141,6 +142,25 @@ void svc_bootstrap(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void utmp_save(int pre, int now)
|
||||
{
|
||||
struct utmp utent;
|
||||
|
||||
int encode(int lvl)
|
||||
{
|
||||
if (!lvl) return 0;
|
||||
return lvl + '0';
|
||||
}
|
||||
|
||||
utent.ut_type = RUN_LVL;
|
||||
utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF);
|
||||
strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user));
|
||||
|
||||
setutent();
|
||||
pututline(&utent);
|
||||
endutent();
|
||||
}
|
||||
|
||||
/**
|
||||
* svc_runlevel - Change to a new runlevel
|
||||
* @newlevel: New runlevel to activate
|
||||
@@ -159,7 +179,8 @@ void svc_runlevel(int newlevel)
|
||||
return;
|
||||
|
||||
prevlevel = runlevel;
|
||||
runlevel = newlevel;
|
||||
runlevel = newlevel;
|
||||
utmp_save(prevlevel, newlevel);
|
||||
|
||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||
int run = svc_enabled(svc, 0, NULL);
|
||||
@@ -187,7 +208,7 @@ void svc_runlevel(int newlevel)
|
||||
else
|
||||
remove("/etc/nologin");
|
||||
|
||||
if (RUNLEVEL_BOOT != prevlevel)
|
||||
if (0 != prevlevel)
|
||||
tty_runlevel(runlevel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user