initctl: ensure 'cond get' support flux state

The 'initctl cond' commands were initiallý added to only manage usr
conditions.  Recently the 'cond get' command was expanded to allow
reading general conditions as well.

However, since general conditions support three states the command
returned 'on' for conditions that were in flux.  This patch fixes
that oversight.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-01-15 06:34:05 +01:00
parent 7c2764790c
commit c3c662fe64
2 changed files with 35 additions and 8 deletions
+3 -4
View File
@@ -139,11 +139,10 @@ or
then any condition can be read.
.Pp
The command is geared for scripting, check the exit code to get the
status of the condition, or give
.Nm
the
status of the condition: 0 - off, 1 - on, 255 - flux. For a more
verbose output, use the
.Fl v
option for a more verbose output.
option.
.It Nm Ar cond clr | clear Ar COND Op COND ...
Clear (deassert) user-defined condition,
.Cm -usr/COND
+32 -4
View File
@@ -408,6 +408,26 @@ static int do_cond_dump(char *arg)
typedef enum { COND_CLR, COND_SET, COND_GET } condop_t;
static int cond_read(char *path)
{
int now, gen;
if (fngetint(path, &gen) == -1)
return 0;
/*
* if we cannot read the reconf generation, then either sth is
* very wrong, or we are called very early/late boot/shutdown.
*/
if (fngetint(_PATH_RECONF, &now) == -1)
return 255; /* classify as flux */
if (now != gen)
return 255;
return 1;
}
/*
* cond get allows only one argument
* cond set|clr iterate over multiple args
@@ -416,6 +436,7 @@ static int do_cond_act(char *args, condop_t op)
{
char path[256];
char *arg;
int rc;
if (!args || !args[0])
ERRX(2, "Invalid condition (empty)");
@@ -443,10 +464,17 @@ static int do_cond_act(char *args, condop_t op)
switch (op) {
case COND_GET:
off = !fexist(path);
if (verbose)
puts(off ? "off" : "on");
return off;
rc = cond_read(path);
if (verbose) {
if (rc == 255)
puts("flux");
else if (rc == 0)
puts("off");
else
puts("on");
}
return rc;
case COND_SET:
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
ERR(73, "Failed asserting condition <%s>", &path[off]);