mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00: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:
1 parent
0f60aa2289
commit
4171fbdfd3
5 files changed
+29
-9
No files matched your search
@@ -71,10 +71,10 @@ int parse_runlevels(char *runlevels)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('s' == lvl || 'S' == lvl)
|
if ('s' == lvl || 'S' == lvl)
|
||||||
lvl = ':'; /* RUNLEVEL_BOOT */
|
lvl = '0';
|
||||||
|
|
||||||
level = lvl - '0';
|
level = lvl - '0';
|
||||||
if (level > RUNLEVEL_BOOT || level < 0)
|
if (level > 9 || level < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (not)
|
if (not)
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
int verbose = 1;
|
int verbose = 1;
|
||||||
int runlevel = RUNLEVEL_BOOT; /* Bootstrap */
|
int runlevel = 0; /* Bootstrap */
|
||||||
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
||||||
int prevlevel = 0; /* HALT */
|
int prevlevel = 0; /* HALT */
|
||||||
char *sdown = NULL;
|
char *sdown = NULL;
|
||||||
char *network = NULL;
|
char *network = NULL;
|
||||||
char *username = 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)",
|
_d("Received SIGSTOP(%d) from %s (PID %d)",
|
||||||
sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid);
|
sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid);
|
||||||
touch(SYNC_STOPPED);
|
touch(SYNC_STOPPED);
|
||||||
stopped ++;
|
stopped++;
|
||||||
}
|
}
|
||||||
static void sigcont_handler(int sig, siginfo_t *info, void *UNUSED(ctx))
|
static void sigcont_handler(int sig, siginfo_t *info, void *UNUSED(ctx))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <utmp.h>
|
||||||
|
|
||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
#include "helpers.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
|
* svc_runlevel - Change to a new runlevel
|
||||||
* @newlevel: New runlevel to activate
|
* @newlevel: New runlevel to activate
|
||||||
@@ -159,7 +179,8 @@ void svc_runlevel(int newlevel)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
prevlevel = runlevel;
|
prevlevel = runlevel;
|
||||||
runlevel = newlevel;
|
runlevel = newlevel;
|
||||||
|
utmp_save(prevlevel, newlevel);
|
||||||
|
|
||||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
int run = svc_enabled(svc, 0, NULL);
|
int run = svc_enabled(svc, 0, NULL);
|
||||||
@@ -187,7 +208,7 @@ void svc_runlevel(int newlevel)
|
|||||||
else
|
else
|
||||||
remove("/etc/nologin");
|
remove("/etc/nologin");
|
||||||
|
|
||||||
if (RUNLEVEL_BOOT != prevlevel)
|
if (0 != prevlevel)
|
||||||
tty_runlevel(runlevel);
|
tty_runlevel(runlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ typedef enum {
|
|||||||
SVC_CMD_RUN /* Like task, but wait for completion */
|
SVC_CMD_RUN /* Like task, but wait for completion */
|
||||||
} svc_type_t;
|
} svc_type_t;
|
||||||
|
|
||||||
#define RUNLEVEL_BOOT 10
|
|
||||||
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
|
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
|
||||||
#define MAX_ARG_LEN 64
|
#define MAX_ARG_LEN 64
|
||||||
#define MAX_STR_LEN 64
|
#define MAX_STR_LEN 64
|
||||||
|
|||||||
Reference in new issue
Block a user