From cdede817fd0dfe2aa45af5df7bcb01399dc525e7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 2 Jan 2022 06:14:42 +0100 Subject: [PATCH] initctl: new command 'ident [NAME]' shows ids of all/named services As suggested in issue #197, this new command: 'initctl id [NAME]' lists identities of all, or named, services. E.g, # initctl id telnetd telnetd:23 telnetd:2323 The NAME argument is optional, when omitted it lists all enabled run/task/sysv/service in the system, with their full name, and any optional identitty. E.g. # initctl id dropbear tty:console mdnsd mini-snmpd smcrouted sntpd ssdpd sysklogd watchdogd httpd telnetd:23 telnetd:2323 Signed-off-by: Joachim Wiberg --- man/initctl.8 | 7 +++++++ src/initctl.c | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/man/initctl.8 b/man/initctl.8 index 09adcbb7..fbab638a 100644 --- a/man/initctl.8 +++ b/man/initctl.8 @@ -118,6 +118,13 @@ Show condition status, default command. .It Nm Ar cond dump Dump all conditions and their status +.It Nm Ar ident Op Cm NAME +Display indentities of all run/task/services, or only instances +matching +.Cm NAME . +A partial string, e.g., +.Cm NAM , +will not match anything .It Nm Ar log Op Cm NAME Show ten last Finit, or .Cm NAME , diff --git a/src/initctl.c b/src/initctl.c index f6677fd8..e1605330 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -803,6 +803,30 @@ static int show_status(char *arg) return 0; } +static int show_ident(char *arg) +{ + svc_t *svc; + + for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { + char ident[MAX_IDENT_LEN]; + size_t len; + char *pos; + + svc_ident(svc, ident, sizeof(ident)); + pos = strchr(ident, ':'); + if (pos) + len = pos - ident; + else + len = strlen(ident); + if (arg && arg[0] && strncasecmp(ident, arg, len)) + continue; + + puts(ident); + } + + return 0; +} + static int transform(char *nm) { char *names[] = { @@ -899,6 +923,7 @@ static int usage(int rc) " stop [:ID] Stop/Pause a running service by name\n" " reload [:ID] Reload service by name (SIGHUP or restart)\n" " restart [:ID] Restart (stop/start) service by name\n" + " ident [NAME] Show matching identities for NAME, or all\n" " status [:ID] Show service status, by name\n" " status Show status of services, default command\n" "\n" @@ -992,6 +1017,7 @@ int main(int argc, char *argv[]) }; struct cmd command[] = { { "status", NULL, show_status }, /* default cmd */ + { "ident", NULL, show_ident }, { "debug", NULL, toggle_debug }, { "devel", NULL, do_devel },