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:
Joachim Nilsson
2013-06-06 18:19:26 +02:00
parent 0f60aa2289
commit 4171fbdfd3
5 changed files with 29 additions and 9 deletions
+2 -2
View File
@@ -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)
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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))
{
+23 -2
View File
@@ -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);
}
-1
View File
@@ -42,7 +42,6 @@ typedef enum {
SVC_CMD_RUN /* Like task, but wait for completion */
} svc_type_t;
#define RUNLEVEL_BOOT 10
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
#define MAX_ARG_LEN 64
#define MAX_STR_LEN 64