mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
initctl: new command, list installed plugins
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user