mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
initctl: Follow priciple of least surprise for "cond get"
The accepted standard in Unix is to report successful executions with
exitcode 0. Therefore, map a "initctl cond get" of a condition to the
following exitcodes:
- On: 0
- Off: 1
- Flux: 255
Fixes: c3c662fe64 ("initctl: ensure 'cond get' support flux state")
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
This commit is contained in:
1 parent
4f8a5a6531
commit
c23a867485
2 files changed
+20
-16
No files matched your search
+1
-1
@@ -145,7 +145,7 @@ 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: 0 - off, 1 - on, 255 - flux. For a more
|
status of the condition: 0 - on, 1 - off, 255 - flux. For a more
|
||||||
verbose output, use the
|
verbose output, use the
|
||||||
.Fl v
|
.Fl v
|
||||||
option.
|
option.
|
||||||
|
|||||||
+19
-15
@@ -409,24 +409,24 @@ 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)
|
static cond_state_t cond_read(char *path)
|
||||||
{
|
{
|
||||||
int now, gen;
|
int now, gen;
|
||||||
|
|
||||||
if (fngetint(path, &gen) == -1)
|
if (fngetint(path, &gen) == -1)
|
||||||
return 0;
|
return COND_OFF;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we cannot read the reconf generation, then either sth is
|
* if we cannot read the reconf generation, then either sth is
|
||||||
* very wrong, or we are called very early/late boot/shutdown.
|
* very wrong, or we are called very early/late boot/shutdown.
|
||||||
*/
|
*/
|
||||||
if (fngetint(_PATH_RECONF, &now) == -1)
|
if (fngetint(_PATH_RECONF, &now) == -1)
|
||||||
return 255; /* classify as flux */
|
return COND_FLUX; /* classify as flux */
|
||||||
|
|
||||||
if (now != gen)
|
if (now != gen)
|
||||||
return 255;
|
return COND_FLUX;
|
||||||
|
|
||||||
return 1;
|
return COND_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -435,9 +435,9 @@ static int cond_read(char *path)
|
|||||||
*/
|
*/
|
||||||
static int do_cond_act(char *args, condop_t op)
|
static int do_cond_act(char *args, condop_t op)
|
||||||
{
|
{
|
||||||
|
cond_state_t cstate;
|
||||||
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)");
|
||||||
@@ -465,16 +465,20 @@ static int do_cond_act(char *args, condop_t op)
|
|||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case COND_GET:
|
case COND_GET:
|
||||||
rc = cond_read(path);
|
cstate = cond_read(path);
|
||||||
if (verbose) {
|
if (verbose)
|
||||||
if (rc == 255)
|
puts(condstr(cstate));
|
||||||
puts("flux");
|
|
||||||
else if (rc == 0)
|
switch (cstate) {
|
||||||
puts("off");
|
case COND_ON:
|
||||||
else
|
return 0;
|
||||||
puts("on");
|
case COND_OFF:
|
||||||
|
return 1;
|
||||||
|
case COND_FLUX:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return rc;
|
return 255;
|
||||||
|
|
||||||
case COND_SET:
|
case COND_SET:
|
||||||
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
|
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
|
||||||
|
|||||||
Reference in new issue
Block a user