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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-01-02 06:14:42 +01:00
1 parent df42c2f6fe
commit cdede817fd
2 files changed
+33

No files matched your search

+7
View File
@@ -118,6 +118,13 @@ Show condition status, default
command. command.
.It Nm Ar cond dump .It Nm Ar cond dump
Dump all conditions and their status 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 .It Nm Ar log Op Cm NAME
Show ten last Finit, or Show ten last Finit, or
.Cm NAME , .Cm NAME ,
+26
View File
@@ -803,6 +803,30 @@ static int show_status(char *arg)
return 0; 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) static int transform(char *nm)
{ {
char *names[] = { char *names[] = {
@@ -899,6 +923,7 @@ static int usage(int rc)
" stop <NAME>[:ID] Stop/Pause a running service by name\n" " stop <NAME>[:ID] Stop/Pause a running service by name\n"
" reload <NAME>[:ID] Reload service by name (SIGHUP or restart)\n" " reload <NAME>[:ID] Reload service by name (SIGHUP or restart)\n"
" restart <NAME>[:ID] Restart (stop/start) service by name\n" " restart <NAME>[:ID] Restart (stop/start) service by name\n"
" ident [NAME] Show matching identities for NAME, or all\n"
" status <NAME>[:ID] Show service status, by name\n" " status <NAME>[:ID] Show service status, by name\n"
" status Show status of services, default command\n" " status Show status of services, default command\n"
"\n" "\n"
@@ -992,6 +1017,7 @@ int main(int argc, char *argv[])
}; };
struct cmd command[] = { struct cmd command[] = {
{ "status", NULL, show_status }, /* default cmd */ { "status", NULL, show_status }, /* default cmd */
{ "ident", NULL, show_ident },
{ "debug", NULL, toggle_debug }, { "debug", NULL, toggle_debug },
{ "devel", NULL, do_devel }, { "devel", NULL, do_devel },