aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-24 13:07:28 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-02-24 13:07:28 +0200
commit4049c8b3ba918949106ef8e96ac5e767f4b9406b (patch)
treefa531f5217f88fb344fc409d5ad3be410e45d9b3 /src
parent59e25f1ffcdf5bd4f6b8d9da92718f82bcc259b1 (diff)
downloadpies-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')
-rw-r--r--src/cmdline.opt18
-rw-r--r--src/pies.c124
2 files changed, 73 insertions, 69 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
208OPTIONS_END 208OPTIONS_END
209 209
210void 210void
211parse_options(int argc, char *argv[], int *index) 211parse_options (int *pargc, char ***pargv)
212{ 212{
213 GETOPT(argc, argv, *index) 213 int argc = *pargc;
214 char **argv = *pargv;
215 int index;
216
217 if (init_process)
218 {
219 sysvinit_parse_argv (argc, argv);
220 index = argc;
221 }
222 else
223 {
224 GETOPT(argc, argv, index);
225 }
226 *pargc -= index;
227 *pargv += index;
214} 228}
diff --git a/src/pies.c b/src/pies.c
index c52b00b..6ea04d0 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -557,8 +557,8 @@ _cb_command (enum grecs_callback_command cmd,
557 557
558static int 558static int
559_cb_umask (enum grecs_callback_command cmd, 559_cb_umask (enum grecs_callback_command cmd,
560 grecs_locus_t *locus, 560 grecs_locus_t *locus,
561 void *varptr, grecs_value_t *value, void *cb_data) 561 void *varptr, grecs_value_t *value, void *cb_data)
562{ 562{
563 mode_t *pmode = varptr; 563 mode_t *pmode = varptr;
564 char *p; 564 char *p;
@@ -1953,12 +1953,56 @@ set_mailer_argcv (void)
1953 mailer_argv[i] = NULL; 1953 mailer_argv[i] = NULL;
1954 wordsplit_free (&ws); 1954 wordsplit_free (&ws);
1955} 1955}
1956
1957 1956
1957static inline int
1958init_emu (void)
1959{
1960#ifdef INIT_EMU
1961# warning "pies compiled with init emulation code"
1962 char *emu = getenv ("INIT_EMU");
1963 if (emu)
1964 {
1965 char *inittab = strtok (emu, ":");
1966 char *piesinit = strtok (NULL, ":");
1967
1968 config_file_add_type (CONF_INITTAB, inittab);
1969 config_file_add_type (CONF_PIES,
1970 piesinit ? piesinit : "/etc/pies.init");
1971
1972 init_fifo = getenv ("INIT_FIFO");
1973 if (!init_fifo)
1974 init_fifo = "/tmp/initctl";
1975
1976 init_process = 1;
1977 fprintf (stderr, "%s: running in init emulation mode\n", program_name);
1978 return 1;
1979 }
1980 else
1981 {
1982 fprintf (stderr, "%s: Notice:\n", program_name);
1983 fprintf (stderr,
1984 " To enable init emulation code, define environment variable\n"
1985 " INIT_EMU=<inittab>[:<config>]\n"
1986 " where <inittab> and <config> are names of the inittab and\n"
1987 " Pies configuration files, correspondingly.\n"
1988 "\n"
1989 " To override the default FIFO name, define:\n"
1990 " INIT_FIFO=<pathname>\n");
1991 fprintf (stderr, "%s: End of notice\n", program_name);
1992 }
1993#endif
1994 return 0;
1995}
1996
1958static void 1997static void
1959set_conf_file_names (const char *base) 1998set_conf_file_names (const char *base)
1960{ 1999{
1961 if (!config_list) 2000 if (init_process)
2001 {
2002 config_file_add_type (CONF_INITTAB, "/etc/inittab");
2003 config_file_add_type (CONF_PIES, "/etc/pies.init");
2004 }
2005 else if (!config_list && !init_emu ())
1962 { 2006 {
1963 char *name = mkfilename (SYSCONFDIR, base, ".conf"); 2007 char *name = mkfilename (SYSCONFDIR, base, ".conf");
1964 config_file_add (current_syntax, name); 2008 config_file_add (current_syntax, name);
@@ -2002,25 +2046,6 @@ main (int argc, char **argv)
2002 set_quoting_style (NULL, shell_quoting_style); 2046 set_quoting_style (NULL, shell_quoting_style);
2003 2047
2004 init_process = getpid () == 1; 2048 init_process = getpid () == 1;
2005#ifdef INIT_EMU
2006# warning "pies compiled with init emulation code"
2007 if (!init_process)
2008 {
2009 init_process = getenv ("INIT_EMU") != NULL;
2010 if (init_process)
2011 fprintf (stderr, "%s: running in init emulation mode\n", program_name);
2012 else
2013 {
2014 fprintf (stderr,
2015 "%s: to enable init emulation code,\n", program_name);
2016 fprintf (stderr,
2017 "%s: define environment variable INIT_EMU=<inittab>[:<pies_init_file>]\n", program_name);
2018 fprintf (stderr,
2019 "%s: define variable INIT_FIFO=<pathname> to override the default FIFO name\n",
2020 program_name);
2021 }
2022 }
2023#endif
2024 2049
2025 /* Set default logging */ 2050 /* Set default logging */
2026 if (init_process) 2051 if (init_process)
@@ -2034,48 +2059,15 @@ main (int argc, char **argv)
2034 diag_setup (diag_flags); 2059 diag_setup (diag_flags);
2035 2060
2036 config_init (); 2061 config_init ();
2037 if (init_process)
2038 {
2039#ifdef INIT_EMU
2040 char *emu = getenv ("INIT_EMU");
2041 if (emu)
2042 {
2043 char *inittab = strtok (emu, ":");
2044 char *piesinit = strtok (NULL, ":");
2045 config_file_add_type (CONF_INITTAB, inittab);
2046 config_file_add_type (CONF_PIES,
2047 piesinit ? piesinit : "/etc/pies.init");
2048
2049 init_fifo = getenv ("INIT_FIFO");
2050 if (!init_fifo)
2051 init_fifo = "/tmp/initctl";
2052 }
2053 else
2054 {
2055 config_file_add_type (CONF_INITTAB, "/etc/inittab");
2056 config_file_add_type (CONF_PIES, "/etc/pies.init");
2057 }
2058#else
2059 config_file_add_type (CONF_INITTAB, "/etc/inittab");
2060 config_file_add_type (CONF_PIES, "/etc/pies.init");
2061#endif
2062 sysvinit_parse_argv (argc, argv);
2063 }
2064 else
2065 {
2066 int index;
2067 2062
2068 parse_options (argc, argv, &index); 2063 parse_options (&argc, &argv);
2069 argc -= index;
2070 argv += index;
2071 2064
2072 if (argc && !(command == COM_RESTART_COMPONENT 2065 if (argc && !(command == COM_RESTART_COMPONENT
2073 || command == COM_TRACE_DEPEND 2066 || command == COM_TRACE_DEPEND
2074 || command == COM_TRACE_PREREQ)) 2067 || command == COM_TRACE_PREREQ))
2075 { 2068 {
2076 logmsg (LOG_ERR, "extra command line arguments"); 2069 logmsg (LOG_ERR, "extra command line arguments");
2077 exit (EX_USAGE); 2070 exit (EX_USAGE);
2078 }
2079 } 2071 }
2080 2072
2081 if (!instance) 2073 if (!instance)
@@ -2089,8 +2081,7 @@ main (int argc, char **argv)
2089 setenv ("PIES_INSTANCE", instance, 1); 2081 setenv ("PIES_INSTANCE", instance, 1);
2090 log_tag = grecs_strdup (instance); 2082 log_tag = grecs_strdup (instance);
2091 2083
2092 if (!init_process) 2084 set_conf_file_names (instance);
2093 set_conf_file_names (instance);
2094 2085
2095 if (init_process || !DEFAULT_PREPROCESSOR) 2086 if (init_process || !DEFAULT_PREPROCESSOR)
2096 grecs_preprocessor = NULL; 2087 grecs_preprocessor = NULL;
@@ -2197,8 +2188,7 @@ main (int argc, char **argv)
2197 exit (EX_USAGE); 2188 exit (EX_USAGE);
2198 } 2189 }
2199 2190
2200 logmsg (LOG_INFO, 2191 logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version);
2201 _("%s %s starting"), proginfo.package, proginfo.version);
2202 2192
2203 if (!foreground) 2193 if (!foreground)
2204 { 2194 {

Return to:

Send suggestions and report system problems to the System administrator.