mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
initctl: Support printing previous runlevel
This patch adds support for "PREVLEVEL RUNLEVEL" output to the initctl runlevel command. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
cae61ad6df
commit
f06a0fcb71
2 files changed
+29
-9
No files matched your search
@@ -267,7 +267,8 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
|
|
||||||
case INIT_CMD_GET_RUNLEVEL:
|
case INIT_CMD_GET_RUNLEVEL:
|
||||||
_d("get runlevel");
|
_d("get runlevel");
|
||||||
rq.runlevel = runlevel;
|
rq.runlevel = runlevel;
|
||||||
|
rq.sleeptime = prevlevel;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT_CMD_ACK:
|
case INIT_CMD_ACK:
|
||||||
|
|||||||
+27
-8
@@ -46,7 +46,7 @@
|
|||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int runlevel = 0;
|
int runlevel = 0;
|
||||||
|
|
||||||
static int runlevel_get(void)
|
static int runlevel_get(int *prevlevel)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
struct init_request rq;
|
struct init_request rq;
|
||||||
@@ -56,8 +56,11 @@ static int runlevel_get(void)
|
|||||||
rq.magic = INIT_MAGIC;
|
rq.magic = INIT_MAGIC;
|
||||||
|
|
||||||
result = client_send(&rq, sizeof(rq));
|
result = client_send(&rq, sizeof(rq));
|
||||||
if (!result)
|
if (!result) {
|
||||||
result = rq.runlevel;
|
result = rq.runlevel;
|
||||||
|
if (prevlevel)
|
||||||
|
*prevlevel = rq.sleeptime;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -88,6 +91,9 @@ static int do_log(char *svc)
|
|||||||
return system(cmd);
|
return system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX: Convert to read UTMP instead, like runlevel(8) does
|
||||||
|
*/
|
||||||
static int do_runlevel(char *arg)
|
static int do_runlevel(char *arg)
|
||||||
{
|
{
|
||||||
struct init_request rq = {
|
struct init_request rq = {
|
||||||
@@ -96,10 +102,21 @@ static int do_runlevel(char *arg)
|
|||||||
.runlevel = (int)arg[0],
|
.runlevel = (int)arg[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Not compatible with the SysV runlevel(8) command, it prints
|
|
||||||
* "PREVLEVEL RUNLEVEL", we just print the current runlevel. */
|
|
||||||
if (!rq.runlevel) {
|
if (!rq.runlevel) {
|
||||||
printf("%d\n", runlevel_get());
|
char prev;
|
||||||
|
int runlevel, prevlevel;
|
||||||
|
|
||||||
|
runlevel = runlevel_get(&prevlevel);
|
||||||
|
if (255 == runlevel) {
|
||||||
|
printf("unknown\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = prevlevel + '0';
|
||||||
|
if (prev <= '0' || prev > '9')
|
||||||
|
prev = 'N';
|
||||||
|
|
||||||
|
printf("%c %d\n", prev , runlevel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,15 +418,17 @@ char *runlevel_string(int runlevel, int levels)
|
|||||||
return lvl;
|
return lvl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In verbose mode we skip the header and each service description.
|
/*
|
||||||
|
* In verbose mode we skip the header and each service description.
|
||||||
* This in favor of having all info on one line so a machine can more
|
* This in favor of having all info on one line so a machine can more
|
||||||
* easily parse it. */
|
* easily parse it.
|
||||||
|
*/
|
||||||
static int show_status(char *arg)
|
static int show_status(char *arg)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
/* Fetch UTMP runlevel, needed for svc_status() call below */
|
/* Fetch UTMP runlevel, needed for svc_status() call below */
|
||||||
runlevel = runlevel_get();
|
runlevel = runlevel_get(NULL);
|
||||||
|
|
||||||
if (arg && arg[0]) {
|
if (arg && arg[0]) {
|
||||||
int id = 1;
|
int id = 1;
|
||||||
|
|||||||
Reference in new issue
Block a user