diff --git a/man/initctl.8 b/man/initctl.8 index 15dd33f0..08e0f8ff 100644 --- a/man/initctl.8 +++ b/man/initctl.8 @@ -202,6 +202,8 @@ List cgroup config overview List processes based on cgroups .It Nm Ar top Show top-like listing based on cgroups +.It Nm Ar plugins +List installed plugins .It Nm Ar runlevel Op Ar 0-9 Show or set runlevel: 0 halt, 6 reboot .It Nm Ar reboot diff --git a/src/api.c b/src/api.c index 43d6e014..21b7087d 100644 --- a/src/api.c +++ b/src/api.c @@ -429,6 +429,14 @@ static void api_cb(uev_t *w, void *arg, int events) result = do_reload(rq.data, sizeof(rq.data)); break; + case INIT_CMD_GET_PLUGINS: + result = plugin_list(rq.data, sizeof(rq.data)); + break; + + case INIT_CMD_PLUGIN_DEPS: + result = plugin_deps(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 a528e363..e8c561e3 100644 --- a/src/finit.h +++ b/src/finit.h @@ -83,8 +83,8 @@ #define INIT_CMD_STOP_SVC 11 #define INIT_CMD_RELOAD_SVC 12 /* SIGHUP service */ #define INIT_CMD_RESTART_SVC 13 /* START service, clearing blocks */ -#define INIT_CMD_UNUSED2 14 /* Unused, was INIT_CMD_QUERY_INETD */ -#define INIT_CMD_UNUSED1 15 /* Unused, was INIT_CMD_EMIT */ +#define INIT_CMD_GET_PLUGINS 14 /* Fill data[] with loaded plugins */ +#define INIT_CMD_PLUGIN_DEPS 15 /* Fill data[] with plugin deps */ #define INIT_CMD_GET_RUNLEVEL 16 #define INIT_CMD_REBOOT 20 #define INIT_CMD_HALT 21 diff --git a/src/initctl.c b/src/initctl.c index fd7e8789..6cdb904f 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -605,6 +605,44 @@ static int show_version(char *arg) return 0; } +static int plugins_list(char *arg) +{ + struct init_request rq = { + .magic = INIT_MAGIC, + .cmd = INIT_CMD_GET_PLUGINS, + }; + char buf[sizeof(rq.data)]; + char *ptr; + int rc; + + rc = client_send(&rq, sizeof(rq)); + if (rc) { + if (rc == 255) + return 69; + else + ERRX(69, "No such command"); + } + memcpy(buf, rq.data, sizeof(buf)); + + if (heading) + print_header("%-18s %s", "PLUGIN", "DEPENDENCIES"); + + ptr = strtok(buf, " "); + while (ptr) { + rq.cmd = INIT_CMD_PLUGIN_DEPS; + strlcpy(rq.data, ptr, sizeof(rq.data)); + rc = client_send(&rq, sizeof(rq)); + if (rc) + printf("%s\n", ptr); + else + printf("%-18s %s\n", ptr, rq.data); + + ptr = strtok(NULL, " "); + } + + return 0; +} + /** * runlevel_string - Convert a bit encoded runlevel to .conf syntax * @levels: Bit encoded runlevels @@ -1053,6 +1091,8 @@ static int usage(int rc) " ps List processes based on cgroups\n" " top Show top-like listing based on cgroups\n"); fprintf(stderr, + "\n" + " plugins List installed plugins\n" "\n" " runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot\n" " reboot Reboot system\n" @@ -1184,6 +1224,8 @@ int main(int argc, char *argv[]) { "ps", NULL, show_cgps, &cgrp, NULL }, { "top", NULL, show_cgtop, &cgrp, NULL }, + { "plugins", NULL, plugins_list, NULL, NULL }, + { "runlevel", NULL, do_runlevel, NULL, NULL }, { "reboot", NULL, do_reboot, NULL, NULL }, { "halt", NULL, do_halt, NULL, NULL }, diff --git a/src/plugin.c b/src/plugin.c index d345624d..8458cc8c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -383,6 +383,48 @@ static int load_plugins(char *path) } #endif /* ENABLE_STATIC */ +int plugin_list(char *buf, size_t len) +{ +#ifndef ENABLE_STATIC + plugin_t *p, *tmp; + + buf[0] = 0; + PLUGIN_ITERATOR(p, tmp) { + if (buf[0]) + strlcat(buf, " ", len); + strlcat(buf, p->name, len); + } +#else + buf[0] = 0; +#endif + return 0; +} + +int plugin_deps(char *buf, size_t len) +{ +#ifndef ENABLE_STATIC + plugin_t *p; + + p = plugin_find(buf); + buf[0] = 0; + if (p) { + int i; + + for (i = 0; i < PLUGIN_DEP_MAX; i++) { + if (!p->depends[i]) + continue; + + if (buf[0]) + strlcat(buf, " ", len); + strlcat(buf, p->depends[i], len); + } + } +#else + buf[0] = 0; +#endif + return 0; +} + int plugin_init(uev_ctx_t *ctx) { load_plugins(PLUGIN_PATH); diff --git a/src/plugin.h b/src/plugin.h index 93d2a1c9..f528fd1f 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -146,6 +146,9 @@ typedef struct plugin { /* Public plugin API */ int plugin_io_init (plugin_t *plugin); +int plugin_list (char *buf, size_t len); +int plugin_deps (char *buf, size_t len); + int plugin_register (plugin_t *plugin); int plugin_unregister (plugin_t *plugin);