aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-12-20 00:50:52 +0200
committerSergey Poznyakoff <gray@gnu.org>2015-12-20 00:59:25 +0200
commitd479bd2f63445524253e16d8575a0592c266908d (patch)
treeaae2188767328ee7dac100e14ad58ec75eeb35e5
parent84e4b3d5274c599ed30482bfe2ca8af080d936af (diff)
downloadpies-d479bd2f63445524253e16d8575a0592c266908d.tar.gz
pies-d479bd2f63445524253e16d8575a0592c266908d.tar.bz2
Bugfixes in init mode
* src/ctl.c (ctl_open): Add missing return. * src/pies.c (config_parse): Return if tree is null. (main) [INIT_EMU]: Print more info. Override default init_fifo. Don't use syslog and control socket if running as init process. * src/pies.h (init_fifo): New extern. * src/progman.c (open_redirector): Return -1 if running as init process. (prog_start): Always initialize redir[]. * src/sysvinit.c (init_fifo): New variable. Use it instead if the INIT_FIFO macro. (inittrans): Call create_fifo once, when transiting from boot to normal state.
-rw-r--r--src/ctl.c4
-rw-r--r--src/pies.c44
-rw-r--r--src/pies.h1
-rw-r--r--src/progman.c18
-rw-r--r--src/sysvinit.c34
5 files changed, 67 insertions, 34 deletions
diff --git a/src/ctl.c b/src/ctl.c
index bd8fa53..a640d1f 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1192,2 +1192,3 @@ ctl_open ()
str, strerror (errno));
+ return;
}
@@ -1199,3 +1200,4 @@ ctl_open ()
{
- logmsg (LOG_CRIT, _("can't create control socket %s"), control.url->string);
+ logmsg (LOG_CRIT, _("can't create control socket %s"),
+ control.url->string);
exit (EX_UNAVAILABLE);
diff --git a/src/pies.c b/src/pies.c
index 9466aa2..5c3d7e6 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -24,3 +24,3 @@ int preprocess_only; /* Preprocess config, do nothing more */
int lint_mode; /* Test configuration syntax and exit */
-int log_to_stderr_only; /* Use only stderr for logging */
+int log_to_stderr_only; /* Use only stderr for logging */
int log_facility = LOG_USER;
@@ -1818,5 +1818,9 @@ config_parse (char const *name)
struct grecs_node *tree = grecs_parse (name);
- if (!tree)
- config_error ();
+ if (!tree)
+ {
+ config_error ();
+ return;
+ }
+
for (node = tree; node; node = node->next)
@@ -2307,3 +2311,4 @@ main (int argc, char **argv)
struct grecs_list_entry *ep;
-
+ int diag_flags;
+
set_program_name (argv[0]);
@@ -2324,5 +2329,15 @@ main (int argc, char **argv)
{
- 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);
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);
+ }
}
@@ -2331,3 +2346,8 @@ main (int argc, char **argv)
/* Set default logging */
- diag_setup (DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR));
+ if (init_process)
+ diag_flags = DIAG_TO_STDERR;
+ else
+ diag_flags = DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR);
+
+ diag_setup (diag_flags);
@@ -2344,2 +2364,6 @@ main (int argc, char **argv)
add_config (CONF_PIES, piesinit ? piesinit : "/etc/pies.init");
+
+ init_fifo = getenv ("INIT_FIFO");
+ if (!init_fifo)
+ init_fifo = "/tmp/initctl";
}
@@ -2519,5 +2543,7 @@ main (int argc, char **argv)
- ctl_open ();
if (!init_process)
- create_pidfile (pidfile);
+ {
+ ctl_open ();
+ create_pidfile (pidfile);
+ }
diff --git a/src/pies.h b/src/pies.h
index cc28c69..56fb72d 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -527,2 +527,3 @@ void sysvinit_sysdep_begin (void);
extern char *sysvinit_environ_hint[];
+extern char *init_fifo;
diff --git a/src/progman.c b/src/progman.c
index 4864531..8c33db8 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -434,3 +434,6 @@ open_redirector (struct prog *master, int stream)
fd_set fdset;
-
+
+ if (init_process)
+ return -1;
+
switch (master->v.p.comp->redir[stream].type)
@@ -1162,7 +1165,4 @@ prog_start (struct prog *prog)
- if (!init_process)
- {
- redir[RETR_OUT] = open_redirector (prog, RETR_OUT);
- redir[RETR_ERR] = open_redirector (prog, RETR_ERR);
- }
+ redir[RETR_OUT] = open_redirector (prog, RETR_OUT);
+ redir[RETR_ERR] = open_redirector (prog, RETR_ERR);
@@ -1283,4 +1283,6 @@ prog_start (struct prog *prog)
- close (redir[RETR_OUT]);
- close (redir[RETR_ERR]);
+ if (redir[RETR_OUT] != -1)
+ close (redir[RETR_OUT]);
+ if (redir[RETR_ERR])
+ close (redir[RETR_ERR]);
prog->pid = pid;
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 4fd4559..faa504a 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -401,2 +401,3 @@ sysvinit_setenv (char const *data, int size)
+char *init_fifo = INIT_FIFO;
static void create_fifo (void);
@@ -417,3 +418,3 @@ sysvinit_fifo_handler (int fd, void *data)
{
- logmsg (LOG_ERR, _("error reading from %s: %s"), INIT_FIFO,
+ logmsg (LOG_ERR, _("error reading from %s: %s"), init_fifo,
strerror (errno));
@@ -424,3 +425,3 @@ sysvinit_fifo_handler (int fd, void *data)
{
- logmsg (LOG_ERR, _("end of file on %s: reopening"), INIT_FIFO);
+ logmsg (LOG_ERR, _("end of file on %s: reopening"), init_fifo);
size = 0;
@@ -472,3 +473,3 @@ create_fifo ()
- if (stat (INIT_FIFO, &st) < 0)
+ if (stat (init_fifo, &st) < 0)
{
@@ -476,3 +477,3 @@ create_fifo ()
{
- logmsg (LOG_ERR, "cannot stat fifo %s: %s", INIT_FIFO,
+ logmsg (LOG_ERR, "cannot stat fifo %s: %s", init_fifo,
strerror (errno));
@@ -480,5 +481,5 @@ create_fifo ()
}
- else if (mkfifo (INIT_FIFO, 0600))
+ else if (mkfifo (init_fifo, 0600))
{
- logmsg (LOG_ERR, "cannot create fifo %s: %s", INIT_FIFO,
+ logmsg (LOG_ERR, "cannot create fifo %s: %s", init_fifo,
strerror (errno));
@@ -491,3 +492,3 @@ create_fifo ()
{
- logmsg (LOG_ERR, "not a fifo: %s", INIT_FIFO);
+ logmsg (LOG_ERR, "not a fifo: %s", init_fifo);
return;
@@ -495,3 +496,3 @@ create_fifo ()
- chmod (INIT_FIFO, 0600);
+ chmod (init_fifo, 0600);
}
@@ -506,3 +507,3 @@ create_fifo ()
}
- debug (1, ("reopening %s", INIT_FIFO));
+ debug (1, ("reopening %s", init_fifo));
}
@@ -513,6 +514,6 @@ create_fifo ()
too. */
- fd = open (INIT_FIFO, O_RDWR|O_NONBLOCK);
+ fd = open (init_fifo, O_RDWR|O_NONBLOCK);
if (fd == -1)
{
- logmsg (LOG_ERR, "cannot open %s: %s", INIT_FIFO,
+ logmsg (LOG_ERR, "cannot open %s: %s", init_fifo,
strerror (errno));
@@ -633,5 +634,6 @@ inittrans ()
case normal:
- /* boot -> normal */
newlevel = dfl_level ? dfl_level : getinitdefault ();
- create_fifo ();
+ if (trans)
+ /* boot -> normal */
+ create_fifo ();
}
@@ -705,6 +707,6 @@ telinit (const char *arg)
alarm (5);
- fd = open (INIT_FIFO, O_WRONLY);
+ fd = open (init_fifo, O_WRONLY);
if (fd < 0)
{
- logmsg (LOG_ERR, _("can't open %s: %s"), INIT_FIFO, strerror (errno));
+ logmsg (LOG_ERR, _("can't open %s: %s"), init_fifo, strerror (errno));
exit (EX_UNAVAILABLE);
@@ -714,3 +716,3 @@ telinit (const char *arg)
logmsg (LOG_ERR, _("error writing to %s: %s"),
- INIT_FIFO, strerror (errno));
+ init_fifo, strerror (errno));
exit (EX_UNAVAILABLE);

Return to:

Send suggestions and report system problems to the System administrator.