aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-10-31 17:59:39 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-10-31 17:59:39 +0200
commit6cc676f7f8d86849607b7f707c8682e7efdb65c3 (patch)
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')
-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
@@ -332,12 +332,18 @@ cmd_help (struct ctlio *io, size_t argc, char **argv)
ctlio_printf (io, "%-9s%s", cp->verb, cp->descr);
ctlio_eol (io);
}
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",
[pies_comp_inetd] = "inetd",
[pies_comp_pass_fd] = "pass_fd",
[pies_comp_wait] = "wait",
@@ -389,12 +395,13 @@ term_to_idx (char const *str, char const **a, size_t s)
/* Prog conditionals */
enum pcond_type
{
pcond_true,
pcond_component,
+ pcond_type,
pcond_mode,
pcond_status,
pcond_not,
pcond_and,
pcond_or
};
@@ -404,12 +411,13 @@ struct pcond_node
enum pcond_type type;
union
{
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;
};
static struct pcond_node *
@@ -424,27 +432,28 @@ pcond_node_alloc (enum pcond_type t)
static int
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:
return 1;
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);
case pcond_and:
if (!pcond_eval (node->v.binary[0], p))
@@ -470,13 +479,14 @@ pcond_free (struct pcond_node *node)
{
case pcond_true:
break;
case pcond_component:
free (node->v.tag);
-
+
+ case pcond_type:
case pcond_mode:
case pcond_status:
break;
case pcond_not:
pcond_free (node->v.unary);
@@ -522,12 +532,30 @@ pcond_parse_unary (struct pcond_parser_state *state, struct pcond_node **ret)
}
--state->argc;
term = *state->argv++;
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)
{
ctlio_reply (state->io, "551", "unfinished statement");
return -1;
@@ -712,12 +740,13 @@ list_prog (struct prog *prog, void *data)
struct ctlio *io = env->io;
size_t i;
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:
FORMAT_IDX (io, "Mode", pies_comp_mode_str, prog->v.p.comp->mode);
FORMAT_IDX (io, "Status", status_str, prog->v.p.status);
@@ -893,13 +922,13 @@ ctl_open ()
logmsg (LOG_CRIT, _("%s: cannot create URL: %s"),
str, strerror (errno));
}
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);
exit (EX_UNAVAILABLE);
}

Return to:

Send suggestions and report system problems to the System administrator.