Fix #329: add support for multiple args to initctl cond set/clr

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2023-01-07 14:00:16 +01:00
1 parent 4542fdb5bb
commit 2a62fa3d85
3 files changed
+22 -11

No files matched your search

+2 -2
View File
@@ -535,9 +535,9 @@ Commands:
disable <CONF> Disable .conf in /etc/finit.d/enabled disable <CONF> Disable .conf in /etc/finit.d/enabled
reload Reload *.conf in /etc/finit.d (activate changes) reload Reload *.conf in /etc/finit.d (activate changes)
cond set <COND> Set (assert) user-defined condition +usr/COND cond set <COND> Set (assert) user-defined conditions +usr/COND
cond get <COND> Get status of user-defined condition, see $? and -v cond get <COND> Get status of user-defined condition, see $? and -v
cond clear <COND> Clear (deassert) user-defined condition -usr/COND cond clear <COND> Clear (deassert) user-defined conditions -usr/COND
cond status Show condition status, default cond command cond status Show condition status, default cond command
cond dump [TYPE] Dump all, or a type of, conditions and their status cond dump [TYPE] Dump all, or a type of, conditions and their status
+2 -2
View File
@@ -127,7 +127,7 @@ Reload
.Cm *.conf in .Cm *.conf in
.Pa /etc/finit.d , .Pa /etc/finit.d ,
i.e., activates changes. i.e., activates changes.
.It Nm Ar cond set Ar COND .It Nm Ar cond set Ar COND Op COND ...
Set (assert) user-defined condition, Set (assert) user-defined condition,
.Cm +usr/COND .Cm +usr/COND
.It Nm Ar cond get Ar COND .It Nm Ar cond get Ar COND
@@ -144,7 +144,7 @@ status of the condition, or give
the the
.Fl v .Fl v
option for a more verbose output. option for a more verbose output.
.It Nm Ar cond clr | clear Ar 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
.It Nm Ar cond status .It Nm Ar cond status
+18 -7
View File
@@ -408,17 +408,25 @@ 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 do_cond_act(char *arg, condop_t op) /*
* cond get allows only one argument
* cond set|clr iterate over multiple args
*/
static int do_cond_act(char *args, condop_t op)
{ {
char path[256]; char path[256];
char *arg;
if (!args || !args[0])
ERRX(2, "Invalid condition (empty)");
arg = strtok(args, " \t");
while (arg) {
size_t off; size_t off;
if (arg && strncmp(arg, COND_USR, strlen(COND_USR)) == 0) if (strncmp(arg, COND_USR, strlen(COND_USR)) == 0)
arg += strlen(COND_USR); arg += strlen(COND_USR);
if (!arg || !arg[0])
ERRX(2, "Invalid condition (empty)");
/* allowed to read any condition, but not set/clr */ /* allowed to read any condition, but not set/clr */
if (op != COND_GET) { if (op != COND_GET) {
if (strchr(arg, '/')) if (strchr(arg, '/'))
@@ -449,6 +457,9 @@ static int do_cond_act(char *arg, condop_t op)
break; break;
} }
arg = strtok(NULL, " \t");
}
return 0; return 0;
} }
@@ -1263,9 +1274,9 @@ static int usage(int rc)
fprintf(stderr, fprintf(stderr,
"\n" "\n"
" cond set <COND> Set (assert) user-defined condition +usr/COND\n" " cond set <COND> Set (assert) user-defined conditions +usr/COND\n"
" cond get <COND> Get status of user-defined condition, see $? and -v\n" " cond get <COND> Get status of user-defined condition, see $? and -v\n"
" cond clear <COND> Clear (deassert) user-defined condition -usr/COND\n" " cond clear <COND> Clear (deassert) user-defined conditions -usr/COND\n"
" cond status Show condition status, default cond command\n" " cond status Show condition status, default cond command\n"
" cond dump [TYPE] Dump all, or a type of, conditions and their status\n" " cond dump [TYPE] Dump all, or a type of, conditions and their status\n"
"\n" "\n"