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. then any condition can be read.
.Pp .Pp
The command is geared for scripting, check the exit code to get the The command is geared for scripting, check the exit code to get the
status of the condition, or give status of the condition: 0 - off, 1 - on, 255 - flux. For a more
.Nm verbose output, use the
the
.Fl v .Fl v
option for a more verbose output. option.
.It Nm Ar cond clr | clear Ar COND Op COND ... .It Nm Ar cond clr | clear Ar COND Op COND ...
Clear (deassert) user-defined condition, Clear (deassert) user-defined condition,
.Cm -usr/COND .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; 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 get allows only one argument
* cond set|clr iterate over multiple args * 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 path[256];
char *arg; char *arg;
int rc;
if (!args || !args[0]) if (!args || !args[0])
ERRX(2, "Invalid condition (empty)"); ERRX(2, "Invalid condition (empty)");
@@ -443,10 +464,17 @@ static int do_cond_act(char *args, condop_t op)
switch (op) { switch (op) {
case COND_GET: case COND_GET:
off = !fexist(path); rc = cond_read(path);
if (verbose) if (verbose) {
puts(off ? "off" : "on"); if (rc == 255)
return off; puts("flux");
else if (rc == 0)
puts("off");
else
puts("on");
}
return rc;
case COND_SET: case COND_SET:
if (symlink(_PATH_RECONF, path) && errno != EEXIST) if (symlink(_PATH_RECONF, path) && errno != EEXIST)
ERR(73, "Failed asserting condition <%s>", &path[off]); ERR(73, "Failed asserting condition <%s>", &path[off]);