diff --git a/man/initctl.8 b/man/initctl.8 index 21709420..09adcbb7 100644 --- a/man/initctl.8 +++ b/man/initctl.8 @@ -132,7 +132,11 @@ Reload service by name (SIGHUP or restart) .It Nm Ar restart Cm NAME[:ID] Restart (stop/start) service by name .It Nm Ar status Cm NAME[:ID] -Show service status, by name +Show service status, by name. If only +.Cm NAME +is given and multiple instances exits, a summary of all matching +instances are shown. Only an exact match displays the detailed status +for a particular instance .It Nm Ar status Show status of all services, default command .It Nm Ar cgroup diff --git a/src/initctl.c b/src/initctl.c index 8e07325f..f6677fd8 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -703,18 +703,31 @@ static int show_status(char *arg) { char ident[MAX_IDENT_LEN]; char buf[512]; + int num = 0; svc_t *svc; runlevel = runlevel_get(NULL); - if (arg && arg[0]) { + while (arg && arg[0]) { long now = jiffies(); char uptm[42] = "N/A"; char grbuf[128]; char path[256]; struct cg *cg; + int exact = 0; char *group; + for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { + svc_ident(svc, ident, sizeof(ident)); + if (string_match(ident, arg)) + num++; + if (string_case_compare(ident, arg)) + exact++; + } + + if (num > 1 && !exact) + break; + svc = client_svc_find(arg); if (!svc) return 255; @@ -768,9 +781,11 @@ static int show_status(char *arg) for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { char *lvls; - printf("%-*d ", pw, svc->pid); - svc_ident(svc, ident, sizeof(ident)); + if (num && !string_match(ident, arg)) + continue; + + printf("%-*d ", pw, svc->pid); printf("%-*s %s ", iw, ident, status(svc, 0)); lvls = runlevel_string(runlevel, svc->runlevels);