From 6286ede98584f0708b0b11cca2eeafd8de9b18e0 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 12 Jun 2022 23:37:03 +0200 Subject: [PATCH] initctl: add optional TYPE argument to 'cond dump' command Allow filtering of conditions in raw dump, i.e., the possibility to show only conditions of a certain type. The TYPE argument is not validated in any way, so any prefix match is allowed, e.g. initctl cond dump service/s Shows all conditions for services starting with 's'. Fixes issue #272 Signed-off-by: Joachim Wiberg --- README.md | 2 +- man/initctl.8 | 4 ++-- src/initctl.c | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61ddccec..11a26b59 100644 --- a/README.md +++ b/README.md @@ -464,7 +464,7 @@ Commands: cond get Get status of user-defined condition, see $? and -v cond clear Clear (deassert) user-defined condition -usr/COND cond status Show condition status, default cond command - cond dump Dump all conditions and their status + cond dump [TYPE] Dump all, or a type of, conditions and their status log [NAME] Show ten last Finit, or NAME, messages from syslog start [:ID] Start service by name, with optional ID diff --git a/man/initctl.8 b/man/initctl.8 index 7aa7f205..15dd33f0 100644 --- a/man/initctl.8 +++ b/man/initctl.8 @@ -145,8 +145,8 @@ Clear (deassert) user-defined condition, Show condition status, default .Cm cond command. -.It Nm Ar cond dump -Dump all conditions and their status +.It Nm Ar cond dump Op Cm TYPE +Dump all, or a given type of, conditions and their status .It Nm Ar ident Op Cm NAME Display indentities of all run/task/services, or only instances matching diff --git a/src/initctl.c b/src/initctl.c index 7fb8411a..8a31ee0f 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -320,6 +320,7 @@ int do_signal(int argc, char *argv[]) return client_send(&rq, sizeof(rq)); } +char *dump_filter; static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { const char *cond, *asserted; @@ -334,6 +335,10 @@ static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, st asserted = condstr(cond_get_path(fpath)); cond = &fpath[strlen(_PATH_COND)]; + + if (dump_filter && dump_filter[0] && strncmp(cond, dump_filter, strlen(dump_filter))) + return 0; + if (strncmp("pid/", cond, 4) == 0) { svc_t *svc; @@ -365,6 +370,7 @@ static int do_cond_dump(char *arg) print_header("%-*s %-*s %-6s %s", pw, "PID", iw, "IDENT", "STATUS", "CONDITION"); + dump_filter = arg; if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) { WARNX("Failed parsing %s", _PATH_COND); return 1; @@ -1004,7 +1010,7 @@ static int usage(int rc) " cond get Get status of user-defined condition, see $? and -v\n" " cond clear Clear (deassert) user-defined condition -usr/COND\n" " cond status Show condition status, default cond command\n" - " cond dump Dump all conditions and their status\n" + " cond dump [TYPE] Dump all, or a type of, conditions and their status\n" "\n" " log [NAME] Show ten last Finit, or NAME, messages from syslog\n" " start [:ID] Start service by name, with optional ID\n"