initctl: Add support for showing current runlevel

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-06-21 18:30:01 +02:00
parent d0da3b8b98
commit 59731988fd
+10 -3
View File
@@ -82,7 +82,7 @@ static int toggle_debug(char *UNUSED(arg))
return do_send(&rq, sizeof(rq));
}
static int set_runlevel(char *arg)
static int do_runlevel(char *arg)
{
struct init_request rq = {
.magic = INIT_MAGIC,
@@ -90,6 +90,13 @@ static int set_runlevel(char *arg)
.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));
}
@@ -200,7 +207,7 @@ static int usage(int rc)
"Commands:\n"
" debug Toggle Finit debug\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"
" start <JOB|NAME> Start stopped 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[] = {
{ "debug", toggle_debug },
{ "reload", do_reload },
{ "runlevel", set_runlevel },
{ "runlevel", do_runlevel },
{ "status", show_status },
{ "start", do_start },
{ "stop", do_stop },