diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-24 13:07:28 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-24 13:07:28 +0200 |
commit | 4049c8b3ba918949106ef8e96ac5e767f4b9406b (patch) | |
tree | fa531f5217f88fb344fc409d5ad3be410e45d9b3 /src/pies.c | |
parent | 59e25f1ffcdf5bd4f6b8d9da92718f82bcc259b1 (diff) | |
download | pies-4049c8b3ba918949106ef8e96ac5e767f4b9406b.tar.gz pies-4049c8b3ba918949106ef8e96ac5e767f4b9406b.tar.bz2 |
Cleanup initialization code
* src/cmdline.opt (parse_options): Change signature.
Handle sysvinit case.
* src/pies.c (set_conf_file_names): Handle sysvinit case.
(main): Move some parts of sysvinit-specific initialization
to set_conf_file_names.
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 124 |
1 files changed, 57 insertions, 67 deletions
@@ -557,8 +557,8 @@ _cb_command (enum grecs_callback_command cmd, static int _cb_umask (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) + grecs_locus_t *locus, + void *varptr, grecs_value_t *value, void *cb_data) { mode_t *pmode = varptr; char *p; @@ -1953,12 +1953,56 @@ set_mailer_argcv (void) mailer_argv[i] = NULL; wordsplit_free (&ws); } - +static inline int +init_emu (void) +{ +#ifdef INIT_EMU +# warning "pies compiled with init emulation code" + char *emu = getenv ("INIT_EMU"); + if (emu) + { + char *inittab = strtok (emu, ":"); + char *piesinit = strtok (NULL, ":"); + + config_file_add_type (CONF_INITTAB, inittab); + config_file_add_type (CONF_PIES, + piesinit ? piesinit : "/etc/pies.init"); + + init_fifo = getenv ("INIT_FIFO"); + if (!init_fifo) + init_fifo = "/tmp/initctl"; + + init_process = 1; + fprintf (stderr, "%s: running in init emulation mode\n", program_name); + return 1; + } + else + { + fprintf (stderr, "%s: Notice:\n", program_name); + fprintf (stderr, + " To enable init emulation code, define environment variable\n" + " INIT_EMU=<inittab>[:<config>]\n" + " where <inittab> and <config> are names of the inittab and\n" + " Pies configuration files, correspondingly.\n" + "\n" + " To override the default FIFO name, define:\n" + " INIT_FIFO=<pathname>\n"); + fprintf (stderr, "%s: End of notice\n", program_name); + } +#endif + return 0; +} + static void set_conf_file_names (const char *base) { - if (!config_list) + if (init_process) + { + config_file_add_type (CONF_INITTAB, "/etc/inittab"); + config_file_add_type (CONF_PIES, "/etc/pies.init"); + } + else if (!config_list && !init_emu ()) { char *name = mkfilename (SYSCONFDIR, base, ".conf"); config_file_add (current_syntax, name); @@ -2002,25 +2046,6 @@ main (int argc, char **argv) set_quoting_style (NULL, shell_quoting_style); init_process = getpid () == 1; -#ifdef INIT_EMU -# warning "pies compiled with init emulation code" - if (!init_process) - { - init_process = getenv ("INIT_EMU") != NULL; - if (init_process) - fprintf (stderr, "%s: running in init emulation mode\n", program_name); - else - { - fprintf (stderr, - "%s: to enable init emulation code,\n", program_name); - fprintf (stderr, - "%s: define environment variable INIT_EMU=<inittab>[:<pies_init_file>]\n", program_name); - fprintf (stderr, - "%s: define variable INIT_FIFO=<pathname> to override the default FIFO name\n", - program_name); - } - } -#endif /* Set default logging */ if (init_process) @@ -2034,48 +2059,15 @@ main (int argc, char **argv) diag_setup (diag_flags); config_init (); - if (init_process) - { -#ifdef INIT_EMU - char *emu = getenv ("INIT_EMU"); - if (emu) - { - char *inittab = strtok (emu, ":"); - char *piesinit = strtok (NULL, ":"); - config_file_add_type (CONF_INITTAB, inittab); - config_file_add_type (CONF_PIES, - piesinit ? piesinit : "/etc/pies.init"); - - init_fifo = getenv ("INIT_FIFO"); - if (!init_fifo) - init_fifo = "/tmp/initctl"; - } - else - { - config_file_add_type (CONF_INITTAB, "/etc/inittab"); - config_file_add_type (CONF_PIES, "/etc/pies.init"); - } -#else - config_file_add_type (CONF_INITTAB, "/etc/inittab"); - config_file_add_type (CONF_PIES, "/etc/pies.init"); -#endif - sysvinit_parse_argv (argc, argv); - } - else - { - int index; - parse_options (argc, argv, &index); - argc -= index; - argv += index; + parse_options (&argc, &argv); - if (argc && !(command == COM_RESTART_COMPONENT - || command == COM_TRACE_DEPEND - || command == COM_TRACE_PREREQ)) - { - logmsg (LOG_ERR, "extra command line arguments"); - exit (EX_USAGE); - } + if (argc && !(command == COM_RESTART_COMPONENT + || command == COM_TRACE_DEPEND + || command == COM_TRACE_PREREQ)) + { + logmsg (LOG_ERR, "extra command line arguments"); + exit (EX_USAGE); } if (!instance) @@ -2089,8 +2081,7 @@ main (int argc, char **argv) setenv ("PIES_INSTANCE", instance, 1); log_tag = grecs_strdup (instance); - if (!init_process) - set_conf_file_names (instance); + set_conf_file_names (instance); if (init_process || !DEFAULT_PREPROCESSOR) grecs_preprocessor = NULL; @@ -2197,8 +2188,7 @@ main (int argc, char **argv) exit (EX_USAGE); } - logmsg (LOG_INFO, - _("%s %s starting"), proginfo.package, proginfo.version); + logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version); if (!foreground) { |