From 0c930fc6d3fde82e800c685ec1df92ddfa23fe09 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 21 Jan 2016 08:31:31 +0200 Subject: Cleanup: redo configuration file handling and dependency tracking. Implement clean configuration reload on SIGHUP. Use SIGUSR1 to restart the program (previously initiated by SIGHUP). * src/Makefile.am (pies_SOURCES): Add comp.c * src/comp.c: New file. * src/acl.c (pies_acl_free): Don't coredump on NULL arg. (_parse_from): Set cmp function for the sockaddr list. (_acl_common_section_parser): Set cmp function for the ACL (pies_acl_cmp): New function. * src/acl.h (pies_acl_cmp): New proto. * src/cmdline.opt: Remove option --dump-prereq. Add options --trace-prereq and --trace-depend. * src/ctl.c: Use prog_tag to access tag of struct prog. * src/depmap.c (depmap_clear) (depmap_clear_all): New functions. * src/inetd.c (inetd_conf_file): Don't register prog right away. This is done later in component_config_commit. (inetd_parse_conf): Rename to inetd_config_parse. * src/limits.c (limits_cmp): New function. * src/pies.c (config_file): Replace with struct config_syntax. (str_to_config_syntax): Return a pointer to struct config_syntax. (add_config): Rename to config_file_add. (config_file_add_type): New function. (return_code_keywords, create_action): Change handling of actions. (return_code_section_parser): Likewise. (component_verify, component_create) (component_free, component_finish): Move to comp.c (config_parse): Remove. (pies_config_parse): New function. (pies_read_config,pies_reload): New function. (pies_reload): Rename to request_reload. (pies_status): Rename to request_status. (pies_stop): Rename to request_stop. (main): Change configuration file handling. SIGHUP reloads configuration, instead of restarting the program. (default_sigv,sig_handler): Handle SIGUSR1. * src/pies.h (component): New members: prev, next, listidx, arridx, ref_count, prog. Remove act_head, act_tail, act_temp. Add new prototypes. * src/prog.h (prog): Remove tag and prereq. * src/progman.c (prog_tag): New function. (destroy_prog): Update component reference count. (register_redir): Likewise. (register_prog0): Take one argument. Update component reference count. (register_prog): Update comp->prog (prog_rebuild_prerequisites): Remove. (component_fixup_depend): Remove. (fixup_prerequisites,rebuild_prerequisites) (print_dep,progman_dump_prereq) (progman_dump_depmap,progman_build_depmap): Remove. (prog_start_prerequisites): Scan depmap to find prerequisites. (prog_stop_dependents): Likewise. (progman_wait): Remove. (progman_wait_until): New function. (progman_stop): Rewrite using progman_wait_until. (react): Rewrite using grecs_list * src/sysvinit.c: Use prog_tag when needed. * src/userprivs.c (pies_privs_cmp, pies_privs_free): New functions. * grecs: Update. * lib/safe_strcmp.c: New file. * lib/Makefile.am: Add safe_strcmp.c * lib/libpies.h (safe_strcmp): New proto. --- src/sysvinit.c | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'src/sysvinit.c') diff --git a/src/sysvinit.c b/src/sysvinit.c index 375a0d5..a4e0d63 100644 --- a/src/sysvinit.c +++ b/src/sysvinit.c @@ -1,5 +1,5 @@ /* This file is part of GNU Pies. - Copyright (C) 2013 Sergey Poznyakoff + Copyright (C) 2013-2016 Sergey Poznyakoff GNU Pies is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -279,7 +279,7 @@ runlevel_setup_prog (struct prog *prog, void *data) prog->v.p.status = status_enabled; else prog->v.p.status = status_disabled; - debug (1, ("%s: %s", prog->tag, + debug (1, ("%s: %s", prog_tag (prog), prog->v.p.status == status_enabled ? "enabled" : "disabled")); } @@ -876,16 +876,17 @@ inittab_parse (const char *file) { if (ws.ws_wordc >= 5) { - enum config_syntax synt; + struct config_syntax *synt = + str_to_config_syntax (ws.ws_wordv[3]); - if (str_to_config_syntax (ws.ws_wordv[3], &synt)) + if (!synt) logmsg (LOG_ERR, "%s:%u: %s", file, line_no, _("unknown syntax type")); else - add_config (synt, ws.ws_wordv[4]); + config_file_add (synt, ws.ws_wordv[4]); } else if (ws.ws_wordc == 4) - add_config (CONF_PIES, ws.ws_wordv[3]); + config_file_add_type (CONF_PIES, ws.ws_wordv[3]); } else if (strcmp (ws.ws_wordv[2], "stop") == 0) { @@ -933,27 +934,9 @@ inittab_parse (const char *file) continue; } - comp = calloc (1, sizeof (*comp)); - if (!comp) - { - logmsg (LOG_ERR, "%s:%u: %s", file, line_no, - _("not enough memory")); - err = 1; - continue; - } - + comp = component_create (id); comp->mode = ap->mode; - comp->tag = strdup (id); - comp->runlevels = strdup (runlevels); - - if (!comp->tag || !comp->runlevels) - { - component_free (comp); - logmsg (LOG_ERR, "%s:%u: %s", file, line_no, - _("not enough memory")); - err = 1; - continue; - } + comp->runlevels = grecs_strdup (runlevels); if (wordsplit (process, &ws, WRDSF_DEFFLAGS)) { @@ -963,11 +946,8 @@ inittab_parse (const char *file) err = 1; continue; } - comp->argc = ws.ws_wordc; - comp->argv = ws.ws_wordv; - comp->program = strdup (ws.ws_wordv[0]); - ws.ws_wordc = 0; - ws.ws_wordv = NULL; + wordsplit_getwords (&ws, &comp->argc, &comp->argv); + comp->program = grecs_strdup (comp->argv[0]); wordsplit_free (&ws); comp->flags |= CF_SIGGROUP; @@ -978,7 +958,6 @@ inittab_parse (const char *file) err = 1; continue; } - register_prog (comp); } free (buf); -- cgit v1.2.1