initctl: Add support for showing current runlevel

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2015-06-21 18:30:01 +02:00
1 parent d0da3b8b98
commit 59731988fd
1 file changed
+10 -3
+10 -3
View File
@@ -82,7 +82,7 @@ static int toggle_debug(char *UNUSED(arg))
return do_send(&rq, sizeof(rq)); return do_send(&rq, sizeof(rq));
} }
static int set_runlevel(char *arg) static int do_runlevel(char *arg)
{ {
struct init_request rq = { struct init_request rq = {
.magic = INIT_MAGIC, .magic = INIT_MAGIC,
@@ -90,6 +90,13 @@ static int set_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) {
printf("%d\n", runlevel_get());
return 0;
}
return do_send(&rq, sizeof(rq)); return do_send(&rq, sizeof(rq));
} }
@@ -200,7 +207,7 @@ static int usage(int rc)
"Commands:\n" "Commands:\n"
" debug Toggle Finit debug\n" " debug Toggle Finit debug\n"
" reload Reload *.conf in /etc/finit.d/\n" " reload Reload *.conf in /etc/finit.d/\n"
" runlevel <0-9> Change runlevel: 0 halt, 6 reboot\n" " runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot\n"
" status Show status of services\n" " status Show status of services\n"
" start <JOB|NAME> Start stopped job or service\n" " start <JOB|NAME> Start stopped job or service\n"
" stop <JOB|NAME> Stop running job or service\n" " stop <JOB|NAME> Stop running job or service\n"
@@ -217,7 +224,7 @@ int main(int argc, char *argv[])
command_t command[] = { command_t command[] = {
{ "debug", toggle_debug }, { "debug", toggle_debug },
{ "reload", do_reload }, { "reload", do_reload },
{ "runlevel", set_runlevel }, { "runlevel", do_runlevel },
{ "status", show_status }, { "status", show_status },
{ "start", do_start }, { "start", do_start },
{ "stop", do_stop }, { "stop", do_stop },