From 59731988fdb6f26734f6db33d97167430edfd7ef Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 21 Jun 2015 18:30:01 +0200 Subject: [PATCH] initctl: Add support for showing current runlevel Signed-off-by: Joachim Nilsson --- initctl.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/initctl.c b/initctl.c index e4763d16..bc68e2ef 100644 --- a/initctl.c +++ b/initctl.c @@ -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 Start stopped job or service\n" " stop 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 },