mirror of
https://github.com/troglobit/finit.git
synced 2026-11-11 16:40:48 +00:00
initctl: add cond get foo, supports -v option
Fix issue #255 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
d04b04d73a
commit
9bce8f9584
1 file changed
+16
-3
+16
-3
@@ -391,7 +391,7 @@ static int do_cond_dump(char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_cond_act(char *arg, int creat)
|
static int do_cond_act(char *arg, int op)
|
||||||
{
|
{
|
||||||
char oneshot[256];
|
char oneshot[256];
|
||||||
size_t off;
|
size_t off;
|
||||||
@@ -409,17 +409,29 @@ static int do_cond_act(char *arg, int creat)
|
|||||||
snprintf(oneshot, sizeof(oneshot), _PATH_CONDUSR "%s", arg);
|
snprintf(oneshot, sizeof(oneshot), _PATH_CONDUSR "%s", arg);
|
||||||
off = strlen(_PATH_COND);
|
off = strlen(_PATH_COND);
|
||||||
|
|
||||||
if (creat) {
|
switch (op) {
|
||||||
|
case 2:
|
||||||
|
off = !fexist(oneshot);
|
||||||
|
if (verbose)
|
||||||
|
puts(off ? "off" : "on");
|
||||||
|
return off;
|
||||||
|
case 1:
|
||||||
if (symlink(_PATH_RECONF, oneshot) && errno != EEXIST)
|
if (symlink(_PATH_RECONF, oneshot) && errno != EEXIST)
|
||||||
err(1, "Failed asserting condition <%s>", &oneshot[off]);
|
err(1, "Failed asserting condition <%s>", &oneshot[off]);
|
||||||
} else {
|
break;
|
||||||
|
case 0:
|
||||||
if (erase(oneshot) && errno != ENOENT)
|
if (erase(oneshot) && errno != ENOENT)
|
||||||
err(1, "Failed deasserting condition <%s>", &oneshot[off]);
|
err(1, "Failed deasserting condition <%s>", &oneshot[off]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errx(1, "Unsupported operation (%d)", op);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_cond_get(char *arg) { return do_cond_act(arg, 2); }
|
||||||
static int do_cond_set(char *arg) { return do_cond_act(arg, 1); }
|
static int do_cond_set(char *arg) { return do_cond_act(arg, 1); }
|
||||||
static int do_cond_clr(char *arg) { return do_cond_act(arg, 0); }
|
static int do_cond_clr(char *arg) { return do_cond_act(arg, 0); }
|
||||||
|
|
||||||
@@ -1120,6 +1132,7 @@ int main(int argc, char *argv[])
|
|||||||
{ "status", NULL, do_cond_show, NULL, NULL }, /* default cmd */
|
{ "status", NULL, do_cond_show, NULL, NULL }, /* default cmd */
|
||||||
{ "dump", NULL, do_cond_dump, NULL, NULL },
|
{ "dump", NULL, do_cond_dump, NULL, NULL },
|
||||||
{ "set", NULL, do_cond_set, NULL, NULL },
|
{ "set", NULL, do_cond_set, NULL, NULL },
|
||||||
|
{ "get", NULL, do_cond_get, NULL, NULL },
|
||||||
{ "clr", NULL, do_cond_clr, NULL, NULL },
|
{ "clr", NULL, do_cond_clr, NULL, NULL },
|
||||||
{ "clear", NULL, do_cond_clr, NULL, NULL },
|
{ "clear", NULL, do_cond_clr, NULL, NULL },
|
||||||
{ NULL, NULL, NULL, NULL, NULL }
|
{ NULL, NULL, NULL, NULL, NULL }
|
||||||
|
|||||||
Reference in new issue
Block a user