diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-10-04 18:46:44 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-10-04 18:46:44 +0000 |
commit | b4c17d850875ea0e6a8361efe5bd7567db3823ac (patch) | |
tree | 01fd247aa814f1dc5feb30a752981be210573dca /pies | |
parent | 51327c214c679dcdd5204af429cf34972bc77383 (diff) | |
download | pies-b4c17d850875ea0e6a8361efe5bd7567db3823ac.tar.gz pies-b4c17d850875ea0e6a8361efe5bd7567db3823ac.tar.bz2 |
Bugfix.
* pies/pies.c (return_code_section_parser): Fix to work with tag
of any type.
* pies/pies.rcin: Minor change.
Diffstat (limited to 'pies')
-rw-r--r-- | pies/pies.c | 194 | ||||
-rw-r--r-- | pies/pies.rcin | 18 |
2 files changed, 137 insertions, 75 deletions
diff --git a/pies/pies.c b/pies/pies.c index 1efedd0..c685bbc 100644 --- a/pies/pies.c +++ b/pies/pies.c @@ -147,6 +147,112 @@ static struct mu_kwd ex_kwtab[] = { { NULL } }; +static struct action * +create_action(struct component *comp, + mu_debug_t debug, mu_config_value_t *val, int argc, + const char *(*getarg) (mu_config_value_t *, int, mu_debug_t)) +{ + int i; + int *retv; + int retc = 0; + int allflag = 0; + struct action *act; + + retv = xcalloc (argc, sizeof *retv); + if (argc == 0 || (argc == 1 && strcmp (getarg(val, 0, debug), "*") == 0)) + allflag = 1; + else + { + for (i = 0; i < argc; i++) + { + int n; + const char *arg = getarg(val, i, debug); + + if (isdigit (arg[0])) + { + char *p; + n = strtoul (arg, &p, 0); + if (*p) + { + mu_cfg_format_error (debug, MU_DEBUG_ERROR, + _("%s: not a number"), p); + continue; + } + } + else if (mu_kwd_xlat_name_ci (ex_kwtab, arg, &n)) + { + mu_cfg_format_error (debug, MU_DEBUG_ERROR, + _("%s: not a return code"), arg); + continue; + } + + if (n > MAX_RETURN_CODE) + mu_cfg_format_error (debug, MU_DEBUG_ERROR, + _("%s: invalid return code"), arg); + else + { + /* Alles in ordnung */ + retv[retc++] = n; + } + } + } + + if (retc == 0 && !allflag) + { + free (retv); + return NULL; + } + + act = xzalloc (sizeof *act); + if (allflag) + { + for (i = 0; i <= MAX_RETURN_CODE; i++) + if (comp->act[i] == NULL) + comp->act[i] = act; + } + else + for (i = 0; i < retc; i++) + comp->act[retv[i]] = act; + free (retv); + return act; +} + +const char * +_get_string_arg (mu_config_value_t *val, int num, mu_debug_t debug) +{ + if (num != 0) + return NULL; + return val->v.string; +} + +const char * +_get_array_arg (mu_config_value_t *val, int num, mu_debug_t debug) +{ + if (num < val->v.arg.c) + { + if (mu_cfg_assert_value_type (&val->v.arg.v[num], MU_CFG_STRING, + debug) == 0) + return val->v.arg.v[num].v.string; + } + return NULL; +} + +const char * +_get_list_arg (mu_config_value_t *val, int num, mu_debug_t debug) +{ + mu_config_value_t *elt; + int rc = mu_list_get (val->v.list, num, (void**)&elt); + if (rc) + { + mu_cfg_format_error (debug, MU_DEBUG_ERROR, + _("cannot get list item: %s"), + mu_strerror (rc)); + } + else if (mu_cfg_assert_value_type (elt, MU_CFG_STRING, debug) == 0) + return elt->v.string; + return NULL; +} + static int return_code_section_parser (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, @@ -155,83 +261,35 @@ return_code_section_parser (enum mu_cfg_section_stage stage, mu_cfg_tree_t *tree) { struct component *comp = *section_data; + size_t count; struct action *act; - int argc, i; - char **argv; - int *retv; - int retc = 0; - int allflag = 0; - int rc; switch (stage) { case mu_cfg_section_start: - if (mu_cfg_assert_value_type (node->label, MU_CFG_STRING, - tree->debug)) - return 1; - rc = mu_argcv_get (node->label->v.string, NULL, NULL, &argc, &argv); - if (rc) - { - mu_cfg_format_error (tree->debug, MU_DEBUG_ERROR, - _("cannot parse return codes: %s"), - mu_strerror (rc)); - return 1; - } - retv = xcalloc (argc, sizeof *retv); - if (argc == 0 || (argc == 1 && strcmp (argv[0], "*") == 0)) - allflag = 1; - else + switch (node->label->type) { - for (i = 0; i < argc; i++) - { - int n; + case MU_CFG_STRING: + act = create_action(comp, tree->debug, node->label, + 1, + _get_string_arg); + break; + + case MU_CFG_ARRAY: + act = create_action(comp, tree->debug, node->label, + node->label->v.arg.c, + _get_array_arg); + break; - if (isdigit (argv[i][0])) - { - char *p; - n = strtoul (argv[i], &p, 0); - if (*p) - { - mu_cfg_format_error (tree->debug, MU_DEBUG_ERROR, - _("%s: not a number"), p); - continue; - } - } - else if (mu_kwd_xlat_name_ci (ex_kwtab, argv[i], &n)) - { - mu_cfg_format_error (tree->debug, MU_DEBUG_ERROR, - _("%s: not a return code"), argv[i]); - continue; - } - - if (n > MAX_RETURN_CODE) - mu_cfg_format_error (tree->debug, MU_DEBUG_ERROR, - _("%s: invalid return code"), argv[i]); - else - { - /* Alles in ordnung */ - retv[retc++] = n; - } - } - } - - mu_argcv_free (argc, argv); - if (retc == 0 && !allflag) - { - free (retv); - return 1; + case MU_CFG_LIST: + mu_list_count (node->label->v.list, &count); + act = create_action(comp, tree->debug, node->label, + count, + _get_list_arg); } - act = xzalloc (sizeof *act); - if (allflag) - { - for (i = 0; i <= MAX_RETURN_CODE; i++) - if (comp->act[i] == NULL) - comp->act[i] = act; - } - else - for (i = 0; i < retc; i++) - comp->act[retv[i]] = act; + if (!act) + return 1; *section_data = act; break; diff --git a/pies/pies.rcin b/pies/pies.rcin index e36ee1b..91c1fa7 100644 --- a/pies/pies.rcin +++ b/pies/pies.rcin @@ -2,18 +2,22 @@ # Special handling for exit codes that mean the program was used incorrectly # or misconfigured. -return-code EX_USAGE EX_CONFIG { +return-code (EX_USAGE, EX_CONFIG) { action disable; - notify root; + notify "root"; message - "From: <>\n" + "From: Pies <>\n" "X-Agent: ${canonical-program-name} (${package} ${version})\n" "Subject: Component ${component} disabled.\n" "\n" - "Component \"${component}\" terminated with code ${retcode}, which means\n" - "some configuration problem.\n" - "It will not be restarted automatically. Please fix its configuration\n" - "and restart it at your earliest convenience."; + "Component \"${component}\" has terminated with code ${retcode},\n" + "which means it encountered some configuration problem.\n" + "I will not restart it automatically. Please fix its configuration\n" + "and restart it manually at your earliest convenience.\n" + "\n" + "To restart, run `pies --start ${component}'\n" + "---\n" + "Wuff-wuff,\nPies"; } component pmult { |