Fix #197: initctl status foo should show overview of foo:1, foo:2 ..

When the system has multiple services 'foo' the initctl command
'status foo' should give a focused overview of all matching foo:*,
whereas a 'status foo:2' should show the detailed view of that
particular instance.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-01-02 06:11:57 +01:00
parent b53f2f4a60
commit df42c2f6fe
2 changed files with 23 additions and 4 deletions
+5 -1
View File
@@ -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
+18 -3
View File
@@ -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);