diff --git a/README.md b/README.md index becac292..b0464788 100644 --- a/README.md +++ b/README.md @@ -429,8 +429,6 @@ Commands: touch Mark .conf in /etc/finit.d/ for reload reload Reload *.conf in /etc/finit.d/ (activates changes) - cond set Set (assert) condition => +COND - cond clear Clear (deassert) condition => -COND cond show Show condition status cond dump Dump all conditions and their status diff --git a/docs/conditions.md b/docs/conditions.md index e289cc66..7722cfbf 100644 --- a/docs/conditions.md +++ b/docs/conditions.md @@ -47,17 +47,7 @@ service's PID file being created. Triggering ---------- -Conditions are triggered by built-in plugins, but can for debugging -purposes also be controlled using the `cond set` and `cond clear` -sub-commands to the `initctl` control tool: - -* `initctl cond set your/cond/here` - - To set a condition - -* `initctl cond clear your/cond/here` - - To clear a condition +Conditions can only be triggered by built-in plugins. Conditions retain their current state until the next reconfiguration or runlevel change. At that point all set conditions transition into the @@ -133,12 +123,13 @@ To fake interface `vlan1` suddenly appearing, and test what happens to ```shell ~ # initctl debug - ~ # initctl cond set net/vlan1/exist + ~ # mkdir -p /var/run/finit/cond/net/vlan1 + ~ # cp /var/run/finit/cond /var/run/finit/cond/net/vlan1/exist ``` Then watch the console for the debug messages and then check the output -from `initctl cond show` again. (The client will likely have failed to -start, but at least the condition is now satisfied.) +from `initctl cond show` again. The client will likely have failed to +start, but at least the condition is now satisfied. There is also the `initctl cond dump` command, which dumps all known conditions and their current status. @@ -147,9 +138,10 @@ conditions and their current status. Internals --------- -Conditions are implemented as simple files in the file system, in the -`/var/run/finit/cond/` sub-directory. Use the `initctl cond set/clear` -commands to add/remove files in this hierarchy. +As shown previously, conditions are implemented as simple files in the +file system, in the `/var/run/finit/cond/` sub-directory. The files +are created, updated, and removed by condition plugins. To debug them, +see the previous section. A condition is always in one of three states: diff --git a/src/api.c b/src/api.c index 6679b1ec..20df1914 100644 --- a/src/api.c +++ b/src/api.c @@ -181,47 +181,6 @@ ev_t ev_list[] = { { NULL, NULL } }; -static int do_handle_event(char *event) -{ - int i; - - for (i = 0; ev_list[i].event; i++) { - ev_t *e = &ev_list[i]; - size_t len = MAX(strlen(e->event), strlen(event)); - - if (!strncasecmp(e->event, event, len)) { - e->cb(); - return 0; - } - } - - if (event[0] == '-') - cond_clear(&event[1]); - else if (event[0] == '+') - cond_set(&event[1]); - else - cond_set(event); - return 0; -} - -static int do_handle_emit(char *buf, size_t len) -{ - int result = 0; - char *input, *event, *pos; - - input = sanitize(buf, len); - if (!input) - return -1; - - event = strtok_r(input, " ", &pos); - while (event) { - result += do_handle_event(event); - event = strtok_r(NULL, " ", &pos); - } - - return result; -} - static void send_svc(int sd, svc_t *svc) { svc_t empty; @@ -339,11 +298,6 @@ static void api_cb(uev_t *w, void *arg, int events) break; #endif - case INIT_CMD_EMIT: - _d("emit %s", rq.data); - result = do_handle_emit(rq.data, sizeof(rq.data)); - break; - case INIT_CMD_GET_RUNLEVEL: _d("get runlevel"); rq.runlevel = runlevel; diff --git a/src/finit.h b/src/finit.h index 683aa3b1..0b87bb41 100644 --- a/src/finit.h +++ b/src/finit.h @@ -75,7 +75,7 @@ #define INIT_CMD_RELOAD_SVC 12 /* SIGHUP service */ #define INIT_CMD_RESTART_SVC 13 /* STOP + START service */ #define INIT_CMD_QUERY_INETD 14 -#define INIT_CMD_EMIT 15 +#define INIT_CMD_UNUSED1 15 /* Unused, was INIT_CMD_EMIT */ #define INIT_CMD_GET_RUNLEVEL 16 #define INIT_CMD_WDOG_HELLO 128 /* Watchdog register and hello */ #define INIT_CMD_SVC_ITER 129 diff --git a/src/initctl.c b/src/initctl.c index 43195ff7..e9493b03 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -140,7 +140,6 @@ static int do_svc(int cmd, char *arg) return client_send(&rq, sizeof(rq)); } -static int do_emit (char *arg) { return do_svc(INIT_CMD_EMIT, arg); } static int do_reload (char *arg) { return do_svc(INIT_CMD_RELOAD, arg); } /* @@ -202,22 +201,6 @@ static void show_cond_one(const char *_conds) putchar('>'); } -static int do_cond_magic(char op, char *cond) -{ - char event[367]; /* sizeof(init_request.data) */ - - if (!cond || strlen(cond) < 1) - return 1; - - event[0] = op; - strlcpy(&event[1], cond, sizeof(event) - 1); - - return do_emit(event); -} - -static int do_cond_set (char *cond) { return do_cond_magic('+', cond); } -static int do_cond_clear(char *cond) { return do_cond_magic('-', cond); } - static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { int len; @@ -279,8 +262,6 @@ static int do_cond(char *cmd) char *arg; struct command command[] = { { "show", do_cond_show }, - { "set", do_cond_set }, - { "clear", do_cond_clear }, { "dump", do_cond_dump }, { NULL, NULL } }; @@ -596,8 +577,6 @@ static int usage(int rc) " reload Reload *.conf in /etc/finit.d/ (activates changes)\n" // " reload [:ID] Reload (SIGHUP) service by job# or name\n" "\n" - " cond set Set (assert) condition => +COND\n" - " cond clear Clear (deassert) condition => -COND\n" " cond show Show condition status\n" " cond dump Dump all conditions and their status\n" "\n"