diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-07 17:40:47 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-07 18:06:19 +0200 |
commit | e92cf71a8f4d51810de7c0f7a613402737d66168 (patch) | |
tree | 775bba0b6bfb026fc458e4c681744fb7661f349e /src/pies.c | |
parent | 5d2eff82abf052d5edb8f201559cb6e17bbf158f (diff) | |
download | pies-e92cf71a8f4d51810de7c0f7a613402737d66168.tar.gz pies-e92cf71a8f4d51810de7c0f7a613402737d66168.tar.bz2 |
Add function for parsing /etc/inittab.
* src/limits.c (free_limits): New function.
* src/pies.c (config_syntax): Move to pies.h
(config_syntax_tab): New type "inittab"
(free_action,component_free): New functions.
(component_finish): Call component_free to discard the
failed component.
(main): In sysvinit mode, default to reading two configuration files:
/etc/inittab and /etc/pies.init.
Don't exit on configuration errors in this mode.
* src/pies.h (str_to_config_syntax)
(add_config,free_redirector)
(component_free,free_limits)
(inittab_parse): New protos.
* src/progman.c (free_redirector): New function.
* src/sysvinit.c (inittab_parse): New function.
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 105 |
1 files changed, 87 insertions, 18 deletions
@@ -60,13 +60,6 @@ struct obstack pp_stk; struct quoting_options *pp_qopt; -enum config_syntax - { - CONF_PIES, - CONF_META1, - CONF_INETD - }; - struct config_file { struct config_file *next; @@ -86,6 +79,7 @@ static struct config_syntax_descr config_syntax_tab[] = { { "pies" , CONF_PIES }, { "meta1", CONF_META1 }, { "inetd", CONF_INETD }, + { "inittab", CONF_INITTAB }, { NULL } }; @@ -328,6 +322,20 @@ static struct tokendef sig_tokendef[] = { #undef S +void +free_action (struct action *act) +{ + if (!act) + return; + if (act->nstat > 0) + free (act->status); + free (act->addr); + free (act->message); + free (act->command); + + free (act); +} + static struct action * create_action (struct component *comp, grecs_locus_t *locus, @@ -373,14 +381,14 @@ create_action (struct component *comp, continue; } } - else if (strtotok_ci (sig_tokendef, arg, &n)) + else if (strtotok_ci (sig_tokendef, arg, (int*) &n)) { grecs_error (locus, 0, _("%s: not a signal code"), arg); continue; } n |= STATUS_SIG_BIT; } - else if (strtotok_ci (ex_tokendef, arg, &n)) + else if (strtotok_ci (ex_tokendef, arg, (int *) &n)) { grecs_error (locus, 0, _("%s: not a return code"), arg); continue; @@ -1343,7 +1351,6 @@ component_verify (struct component *comp, grecs_locus_t *locus) { COMPERR (grecs_error, "%s", _("socket must be specified in this mode")); - /* FIXME: Memory leak */ return 1; } break; @@ -1369,9 +1376,11 @@ component_verify (struct component *comp, grecs_locus_t *locus) { COMPERR (grecs_error, "%s", _("socket must be specified in this mode")); - /* FIXME: Memory leak */ return 1; } + default: + /* FIXME: more checks perhaps */ + break; } if (comp->mode == pies_comp_inetd) @@ -1438,6 +1447,51 @@ component_create (const char *name) } void +component_free (struct component *comp) +{ + size_t i; + + free (comp->tag); + free (comp->program); + if (comp->argv) + { + for (i = 0; i < comp->argc; i++) + free (comp->argv[i]); + free (comp->argv); + } + if (comp->env) + { + for (i = 0; comp->env[i]; i++) + free (comp->env[i]); + free (comp->env); + } + free (comp->dir); + grecs_list_free (comp->prereq); + grecs_list_free (comp->depend); + free (comp->rmfile); + free_limits (comp->limits); + free (comp->runlevels); + free (comp->service); + pies_url_destroy (&comp->socket_url); + free (comp->pass_fd_socket); + free (comp->tcpmux); + free (comp->access_denied_message); + free (comp->max_instances_message); + free (comp->max_ip_connections_message); + free_redirector (&comp->redir[0]); + free_redirector (&comp->redir[1]); + if (comp->act_head) + { + struct action *act; + + for (act = comp->act_head; act; act = act->next) + free_action (act); + } + + free (comp); +} + +void component_finish (struct component *comp, grecs_locus_t *locus) { if (component_verify (comp, locus) == 0) @@ -1447,6 +1501,8 @@ component_finish (struct component *comp, grecs_locus_t *locus) if (progman_lookup_component (comp->tag) == NULL) register_prog (comp); } + else + component_free (comp); } static int @@ -2115,6 +2171,13 @@ set_state_file_names (const char *base) qotdfile = mkfilename (statedir, base, ".qotd"); } +static void +config_error () +{ + if (!init_process) + exit (EX_CONFIG); +} + int main (int argc, char **argv) { @@ -2142,6 +2205,8 @@ main (int argc, char **argv) config_init (); if (init_process) { + add_config (CONF_INITTAB, "/etc/inittab"); + add_config (CONF_PIES, "/etc/pies.init"); for (index = 1; index < argc; index++) { if (!strcmp(argv[index], "single") || !strcmp(argv[index], "-s")) @@ -2162,9 +2227,7 @@ main (int argc, char **argv) #endif else if (strchr("0123456789sS", argv[index][0]) && !argv[index][1]) { - dfl_level = argv[index][0]; - if (dfl_level == 's') - dfl_level = 'S'; + dfl_level = toupper (argv[index][0]); } } } @@ -2182,7 +2245,8 @@ main (int argc, char **argv) log_tag = instance; - set_conf_file_names (instance); + if (!init_process) + set_conf_file_names (instance); if (init_process || !DEFAULT_PREPROCESSOR) grecs_preprocessor = NULL; @@ -2211,19 +2275,24 @@ main (int argc, char **argv) { struct grecs_node *tree = grecs_parse (file->name); if (!tree || grecs_tree_process (tree, pies_keywords)) - exit (EX_CONFIG); + config_error (); grecs_tree_free (tree); break; } case CONF_INETD: if (inetd_parse_conf (file->name)) - exit (EX_CONFIG); + config_error (); break; case CONF_META1: if (meta1_config_parse (file->name)) - exit (EX_CONFIG); + config_error (); + break; + + case CONF_INITTAB: + if (inittab_parse (file->name)) + config_error (); break; } } |