From de4bf53536e1ac29b8f3fc50667a018ad5359394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Wed, 18 Jan 2017 16:08:32 +0100 Subject: [PATCH] initctl: Add 'initctl cond dump' to show all conditions in the system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove verbose of initctl cond, and replace it with 'initctl cond dump' Show all conditions if they are in flux/on even if there are no other services depending on this condition. Signed-off-by: Mattias Walström --- src/initctl.c | 59 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index d68eaa72..73f67564 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "config.h" #include "finit.h" @@ -269,35 +270,43 @@ static int do_cond_magic(char op, char *cond) static int do_cond_set (char *cond) { return do_cond_magic('+', cond); } static int do_cond_clear(char *cond) { return do_cond_magic('-', cond); } + +static int +dump_one_cond(const char *fpath, const struct stat *sb, + int tflag, struct FTW *ftwbuf) +{ + int len; + + if (tflag != FTW_F) + return 0; + + if (!strcmp(fpath, _PATH_COND"reconf")) + return 0; + + len = strlen(_PATH_COND); + printf("%-30s %s\n", &fpath[len], condstr(cond_get_path(fpath))); + + return 0; +} + +static int do_cond_dump(char *UNUSED(arg)) +{ + printf("Condition Status)\n"); + printf("===============================================================================\n"); + + if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) { + _e("Failed parse %s", _PATH_COND); + return 1; + } + + return 0; +} + static int do_cond_show(char *UNUSED(arg)) { svc_t *svc; enum cond_state cond; - if (verbose) { - glob_t gl; - - printf("Asserted conditions (taken from %s)\n", _PATH_COND); - printf("===============================================================================\n"); - - if (!glob(_PATH_COND "*/*/*", 0, NULL, &gl)) { - size_t i; - - for (i = 0; i < gl.gl_pathc; i++) { - char *cond, *name = gl.gl_pathv[i]; - struct stat st; - - if (stat(name, &st) || S_ISDIR(st.st_mode)) - continue; - - cond = name + strlen(_PATH_COND); - printf("\t%s\n", cond); - } - globfree(&gl); - } - puts(""); - } - printf("PID Service Status Condition (+ on, ~ flux, - off)\n"); printf("===============================================================================\n"); @@ -329,6 +338,7 @@ static int do_cond(char *cmd) { "set", do_cond_set }, { "clear", do_cond_clear }, { "show", do_cond_show }, + { "dump", do_cond_dump }, { NULL, NULL } }; @@ -498,6 +508,7 @@ static int usage(int rc) " cond set Set (assert) condition => +COND\n" " cond clear Clear (deassert) condition => -COND\n" " cond show Show condition status\n" + " cond dump Show all conditions and their status\n" " start [:ID] Start service by job# or name, with optional ID\n" " stop [:ID] Stop/Pause a running service by job# or name\n" " restart [:ID] Restart (stop/start) service by job# or name\n"