diff options
-rw-r--r-- | src/cmdline.opt | 18 | ||||
-rw-r--r-- | src/pies.c | 104 |
2 files changed, 63 insertions, 59 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index 389cea7..7d6f7d4 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -208,7 +208,21 @@ END OPTIONS_END void -parse_options(int argc, char *argv[], int *index) +parse_options (int *pargc, char ***pargv) { - GETOPT(argc, argv, *index) + int argc = *pargc; + char **argv = *pargv; + int index; + + if (init_process) + { + sysvinit_parse_argv (argc, argv); + index = argc; + } + else + { + GETOPT(argc, argv, index); + } + *pargc -= index; + *pargv += index; } @@ -1954,11 +1954,55 @@ set_mailer_argcv (void) 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,40 +2059,8 @@ 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 @@ -2076,7 +2069,6 @@ main (int argc, char **argv) logmsg (LOG_ERR, "extra command line arguments"); exit (EX_USAGE); } - } if (!instance) { @@ -2089,7 +2081,6 @@ main (int argc, char **argv) setenv ("PIES_INSTANCE", instance, 1); log_tag = grecs_strdup (instance); - if (!init_process) set_conf_file_names (instance); if (init_process || !DEFAULT_PREPROCESSOR) @@ -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) { |