diff --git a/initctl.c b/initctl.c index cde2b3d1..4f40d20c 100644 --- a/initctl.c +++ b/initctl.c @@ -136,13 +136,38 @@ static int show_version(char *UNUSED(arg)) /* 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 * easily parse it. */ -static int show_status(char *UNUSED(arg)) +static int show_status(char *arg) { svc_t *svc; /* Fetch UTMP runlevel, needed for svc_status() call below */ runlevel = runlevel_get(); + if (arg && arg[0]) { + int id = 1; + char *ptr, *next; + + ptr = strchr(arg, ':'); + if (ptr) { + *ptr++ = 0; + next = strchr(ptr, ' '); + if (next) + *next = 0; + id = atonum(ptr); + } + + if (isdigit(arg[0])) + svc = svc_find_by_jobid(atonum(arg), id); + else + svc = svc_find_by_nameid(arg, id); + + if (!svc) + return 1; + + printf("%s\n", svc_status(svc)); + return 0; + } + if (!verbose) { printf("# Status PID Runlevels Service Description\n"); printf("====================================================================================\n"); @@ -229,6 +254,8 @@ static int usage(int rc) " stop [:ID] Stop/Pause a running service by job# or name\n" " restart [:ID] Restart (stop/start) service by job# or name\n" " reload [:ID] Reload (SIGHUP) service by job# or name\n" + " status [:ID] Show status of a service by job# or name\n" + " show [:ID] Alias to 'status [:ID]'\n" " version Show Finit version\n\n", __progname); return rc;