summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2015-12-19 22:50:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2015-12-19 22:59:25 (GMT)
commitd479bd2f63445524253e16d8575a0592c266908d (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -1190,6 +1190,7 @@ ctl_open ()
{
logmsg (LOG_CRIT, _("%s: cannot create URL: %s"),
str, strerror (errno));
+ return;
}
free (str);
}
@@ -1197,7 +1198,8 @@ ctl_open ()
fd = create_socket (control.url, SOCK_STREAM, NULL, 077);
if (fd == -1)
{
- 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
@@ -22,7 +22,7 @@
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;
char *log_tag;
struct pies_privs pies_privs;
@@ -1816,9 +1816,13 @@ config_parse (char const *name)
{
struct grecs_node *node;
struct grecs_node *tree = grecs_parse (name);
- if (!tree)
- config_error ();
+ if (!tree)
+ {
+ config_error ();
+ return;
+ }
+
for (node = tree; node; node = node->next)
{
node = grecs_find_node (node, "identity-provider");
@@ -2305,7 +2309,8 @@ main (int argc, char **argv)
pid_t pid;
extern char **environ;
struct grecs_list_entry *ep;
-
+ int diag_flags;
+
set_program_name (argv[0]);
#ifdef ENABLE_NLS
setlocale (LC_ALL, "");
@@ -2322,14 +2327,29 @@ main (int argc, char **argv)
# warning "pies compiled with init emulation code"
if (!init_process)
{
- 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);
+ }
}
#endif
/* 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);
config_init ();
if (init_process)
@@ -2342,6 +2362,10 @@ main (int argc, char **argv)
char *piesinit = strtok (NULL, ":");
add_config (CONF_INITTAB, inittab);
add_config (CONF_PIES, piesinit ? piesinit : "/etc/pies.init");
+
+ init_fifo = getenv ("INIT_FIFO");
+ if (!init_fifo)
+ init_fifo = "/tmp/initctl";
}
else
{
@@ -2517,9 +2541,11 @@ main (int argc, char **argv)
diag_setup (DIAG_TO_SYSLOG);
}
- ctl_open ();
if (!init_process)
- create_pidfile (pidfile);
+ {
+ ctl_open ();
+ create_pidfile (pidfile);
+ }
if (argv[0][0] != '/')
logmsg (LOG_NOTICE,
diff --git a/src/pies.h b/src/pies.h
index cc28c69..56fb72d 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -525,6 +525,7 @@ void sysvinit_runlevel_setup (int mask, int *wait);
void sysvinit_sysdep_begin (void);
extern char *sysvinit_environ_hint[];
+extern char *init_fifo;
#ifndef INIT_FIFO
# define INIT_FIFO "/dev/initctl"
diff --git a/src/progman.c b/src/progman.c
index 4864531..8c33db8 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -432,7 +432,10 @@ open_redirector (struct prog *master, int stream)
int prio;
char *tag;
fd_set fdset;
-
+
+ if (init_process)
+ return -1;
+
switch (master->v.p.comp->redir[stream].type)
{
case redir_null:
@@ -1160,11 +1163,8 @@ prog_start (struct prog *prog)
return;
}
- 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);
switch (pid = fork ())
{
@@ -1281,8 +1281,10 @@ prog_start (struct prog *prog)
else if (is_sysvinit (prog->v.p.comp))
sysvinit_acct (SYSV_ACCT_PROC_START, "", prog->tag, pid, "");
- 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;
prog->v.p.status = status_enabled;
debug (1, (_("%s started, pid=%lu"), prog->tag, (unsigned long) pid));
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 4fd4559..faa504a 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -399,6 +399,7 @@ sysvinit_setenv (char const *data, int size)
}
}
+char *init_fifo = INIT_FIFO;
static void create_fifo (void);
static int
@@ -415,14 +416,14 @@ sysvinit_fifo_handler (int fd, void *data)
rc = read (fd, buf.data + size, sizeof (struct sysvinit_request) - size);
if (rc == -1)
{
- logmsg (LOG_ERR, _("error reading from %s: %s"), INIT_FIFO,
+ logmsg (LOG_ERR, _("error reading from %s: %s"), init_fifo,
strerror (errno));
size = 0;
return 0;
}
if (rc == 0)
{
- logmsg (LOG_ERR, _("end of file on %s: reopening"), INIT_FIFO);
+ logmsg (LOG_ERR, _("end of file on %s: reopening"), init_fifo);
size = 0;
close (fd);
deregister_socket (fd);
@@ -470,17 +471,17 @@ create_fifo ()
static int fd = -1;
struct stat st, fst;
- if (stat (INIT_FIFO, &st) < 0)
+ if (stat (init_fifo, &st) < 0)
{
if (errno != ENOENT)
{
- logmsg (LOG_ERR, "cannot stat fifo %s: %s", INIT_FIFO,
+ logmsg (LOG_ERR, "cannot stat fifo %s: %s", init_fifo,
strerror (errno));
return;
}
- 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));
return;
}
@@ -489,11 +490,11 @@ create_fifo ()
{
if (!S_ISFIFO (st.st_mode))
{
- logmsg (LOG_ERR, "not a fifo: %s", INIT_FIFO);
+ logmsg (LOG_ERR, "not a fifo: %s", init_fifo);
return;
}
- chmod (INIT_FIFO, 0600);
+ chmod (init_fifo, 0600);
}
if (fd != -1)
@@ -504,17 +505,17 @@ create_fifo ()
deregister_socket (fd);
close (fd);
}
- debug (1, ("reopening %s", INIT_FIFO));
+ debug (1, ("reopening %s", init_fifo));
}
/* Opening the socket in read-write mode ensures we won't get EOF
on it when the caller party closes connection (at least on Linux).
Nevertheless, the svinit_fifo_handler is prepared for that eventuality,
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));
return;
}
@@ -631,9 +632,10 @@ inittrans ()
newlevel = 'S';
break;
case normal:
- /* boot -> normal */
newlevel = dfl_level ? dfl_level : getinitdefault ();
- create_fifo ();
+ if (trans)
+ /* boot -> normal */
+ create_fifo ();
}
if (newlevel && newlevel != runlevel)
{
@@ -703,16 +705,16 @@ telinit (const char *arg)
signal (SIGALRM, SIG_DFL);
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);
}
if (write (fd, &req, sizeof (req)) != sizeof (req))
{
logmsg (LOG_ERR, _("error writing to %s: %s"),
- INIT_FIFO, strerror (errno));
+ init_fifo, strerror (errno));
exit (EX_UNAVAILABLE);
}
alarm (0);

Return to:

Send suggestions and report system problems to the System administrator.