summaryrefslogtreecommitdiffabout
path: root/src/ctl.c
authorSergey Poznyakoff <gray@gnu.org.ua>2015-10-31 15:59:39 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-10-31 15:59:39 (GMT)
commit6cc676f7f8d86849607b7f707c8682e7efdb65c3 (patch) (side-by-side diff)
tree8fa2cc847d60ecabe9013c053a96ebbb0fefd575 /src/ctl.c
parentc221897e72debfb161365c28f08d7f4bac5511e5 (diff)
downloadpies-6cc676f7f8d86849607b7f707c8682e7efdb65c3.tar.gz
pies-6cc676f7f8d86849607b7f707c8682e7efdb65c3.tar.bz2
control socket: list types
* src/ctl.c: list prog types and search on them * src/progman.c (progman_foreach): Iterate over all elements, not only components. * src/sysvinit.c (runlevel_setup_prog): Check if prog is a component.
Diffstat (limited to 'src/ctl.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/ctl.c b/src/ctl.c
index b1649f5..002a764 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -335,6 +335,12 @@ cmd_help (struct ctlio *io, size_t argc, char **argv)
ctlio_eot (io);
}
+static char const *pies_type_str[] = {
+ [TYPE_COMPONENT] = "component",
+ [TYPE_REDIRECTOR] = "redirector",
+ [TYPE_COMMAND] = "command"
+};
+
static char const *pies_comp_mode_str[] = {
[pies_comp_exec] = "exec",
[pies_comp_accept] = "accept",
@@ -392,6 +398,7 @@ enum pcond_type
{
pcond_true,
pcond_component,
+ pcond_type,
pcond_mode,
pcond_status,
pcond_not,
@@ -407,6 +414,7 @@ struct pcond_node
char *tag;
enum pies_comp_mode mode;
enum prog_status status;
+ enum prog_type type;
struct pcond_node *unary;
struct pcond_node *binary[2];
} v;
@@ -427,8 +435,6 @@ pcond_eval (struct pcond_node *node, struct prog *p)
{
if (!node)
return 0;
- if (!IS_COMPONENT (p))
- return 0;
switch (node->type)
{
case pcond_true:
@@ -436,12 +442,15 @@ pcond_eval (struct pcond_node *node, struct prog *p)
case pcond_component:
return strcmp (p->tag, node->v.tag) == 0;
+
+ case pcond_type:
+ return p->type == node->v.type;
case pcond_mode:
- return p->v.p.comp->mode == node->v.mode;
+ return IS_COMPONENT (p) && p->v.p.comp->mode == node->v.mode;
case pcond_status:
- return p->v.p.status == node->v.status;
+ return IS_COMPONENT (p) && p->v.p.status == node->v.status;
case pcond_not:
return !pcond_eval (node->v.unary, p);
@@ -473,7 +482,8 @@ pcond_free (struct pcond_node *node)
case pcond_component:
free (node->v.tag);
-
+
+ case pcond_type:
case pcond_mode:
case pcond_status:
break;
@@ -525,6 +535,24 @@ pcond_parse_unary (struct pcond_parser_state *state, struct pcond_node **ret)
if (strcasecmp (term, "all") == 0)
pn = pcond_node_alloc (pcond_true);
+ else if (strcasecmp (term, "type") == 0)
+ {
+ if (!state->argc)
+ {
+ ctlio_reply (state->io, "551", "unfinished statement");
+ return -1;
+ }
+ --state->argc;
+ term = *state->argv++;
+ n = TERM_TO_IDX (term, pies_type_str);
+ if (n == -1)
+ {
+ ctlio_reply (state->io, "551", "undefined type: %s", term);
+ return -1;
+ }
+ pn = pcond_node_alloc (pcond_type);
+ pn->v.type = n;
+ }
else if (strcasecmp (term, "mode") == 0)
{
if (!state->argc)
@@ -715,6 +743,7 @@ list_prog (struct prog *prog, void *data)
if (!pcond_eval (env->cond, prog))
return 0;
ctlio_reply (io, "151", "%s", prog->tag);
+ FORMAT_IDX (io, "Type", pies_type_str, prog->type);
switch (prog->type)
{
case TYPE_COMPONENT:
@@ -896,7 +925,7 @@ ctl_open ()
free (str);
}
- fd = create_socket (control.url, SOCK_STREAM, NULL, 0600);
+ fd = create_socket (control.url, SOCK_STREAM, NULL, 077);
if (fd == -1)
{
logmsg (LOG_CRIT, _("can't create control socket %s"), control.url->string);

Return to:

Send suggestions and report system problems to the System administrator.