mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
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:
1 parent
4542fdb5bb
commit
2a62fa3d85
3 files changed
+48
-37
No files matched your search
@@ -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
@@ -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
|
||||||
|
|||||||
+44
-33
@@ -408,45 +408,56 @@ 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];
|
||||||
size_t off;
|
char *arg;
|
||||||
|
|
||||||
if (arg && strncmp(arg, COND_USR, strlen(COND_USR)) == 0)
|
if (!args || !args[0])
|
||||||
arg += strlen(COND_USR);
|
|
||||||
|
|
||||||
if (!arg || !arg[0])
|
|
||||||
ERRX(2, "Invalid condition (empty)");
|
ERRX(2, "Invalid condition (empty)");
|
||||||
|
|
||||||
/* allowed to read any condition, but not set/clr */
|
arg = strtok(args, " \t");
|
||||||
if (op != COND_GET) {
|
while (arg) {
|
||||||
|
size_t off;
|
||||||
|
|
||||||
|
if (strncmp(arg, COND_USR, strlen(COND_USR)) == 0)
|
||||||
|
arg += strlen(COND_USR);
|
||||||
|
|
||||||
|
/* allowed to read any condition, but not set/clr */
|
||||||
|
if (op != COND_GET) {
|
||||||
|
if (strchr(arg, '/'))
|
||||||
|
ERRX(2, "Invalid condition (slashes)");
|
||||||
|
if (strchr(arg, '.'))
|
||||||
|
ERRX(2, "Invalid condition (periods)");
|
||||||
|
}
|
||||||
|
|
||||||
if (strchr(arg, '/'))
|
if (strchr(arg, '/'))
|
||||||
ERRX(2, "Invalid condition (slashes)");
|
snprintf(path, sizeof(path), _PATH_COND "%s", arg);
|
||||||
if (strchr(arg, '.'))
|
else
|
||||||
ERRX(2, "Invalid condition (periods)");
|
snprintf(path, sizeof(path), _PATH_CONDUSR "%s", arg);
|
||||||
}
|
off = strlen(_PATH_COND);
|
||||||
|
|
||||||
if (strchr(arg, '/'))
|
switch (op) {
|
||||||
snprintf(path, sizeof(path), _PATH_COND "%s", arg);
|
case COND_GET:
|
||||||
else
|
off = !fexist(path);
|
||||||
snprintf(path, sizeof(path), _PATH_CONDUSR "%s", arg);
|
if (verbose)
|
||||||
off = strlen(_PATH_COND);
|
puts(off ? "off" : "on");
|
||||||
|
return off;
|
||||||
|
case COND_SET:
|
||||||
|
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
|
||||||
|
ERR(73, "Failed asserting condition <%s>", &path[off]);
|
||||||
|
break;
|
||||||
|
case COND_CLR:
|
||||||
|
if (erase(path) && errno != ENOENT)
|
||||||
|
ERR(73, "Failed deasserting condition <%s>", &path[off]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (op) {
|
arg = strtok(NULL, " \t");
|
||||||
case COND_GET:
|
|
||||||
off = !fexist(path);
|
|
||||||
if (verbose)
|
|
||||||
puts(off ? "off" : "on");
|
|
||||||
return off;
|
|
||||||
case COND_SET:
|
|
||||||
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
|
|
||||||
ERR(73, "Failed asserting condition <%s>", &path[off]);
|
|
||||||
break;
|
|
||||||
case COND_CLR:
|
|
||||||
if (erase(path) && errno != ENOENT)
|
|
||||||
ERR(73, "Failed deasserting condition <%s>", &path[off]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"
|
||||||
|
|||||||
Reference in new issue
Block a user