i == EXEC_INPUT_TTY_FAIL;
}
-static int fixup_input(const ExecContext *context, int socket_fd) {
- assert(context);
+static int fixup_input(ExecInput std_input, int socket_fd) {
- if (socket_fd < 0 && context->std_input == EXEC_INPUT_SOCKET)
+ if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
return EXEC_INPUT_NULL;
- return context->std_input;
-}
-
-static int fixup_output(const ExecContext *context, int socket_fd) {
- assert(context);
-
- if (socket_fd < 0 && context->std_output == EXEC_OUTPUT_SOCKET)
- return EXEC_OUTPUT_INHERIT;
-
- return context->std_output;
+ return std_input;
}
-static int fixup_error(const ExecContext *context, int socket_fd) {
- assert(context);
+static int fixup_output(ExecOutput std_output, int socket_fd) {
- if (socket_fd < 0 && context->std_error == EXEC_OUTPUT_SOCKET)
+ if (std_output == EXEC_OUTPUT_SOCKET && socket_fd < 0)
return EXEC_OUTPUT_INHERIT;
- return context->std_error;
+ return std_output;
}
static int setup_input(const ExecContext *context, int socket_fd) {
assert(context);
- i = fixup_input(context, socket_fd);
+ i = fixup_input(context->std_input, socket_fd);
switch (i) {
assert(context);
assert(ident);
- i = fixup_input(context, socket_fd);
- o = fixup_output(context, socket_fd);
+ i = fixup_input(context->std_input, socket_fd);
+ o = fixup_output(context->std_output, socket_fd);
/* This expects the input is already set up */
case EXEC_OUTPUT_INHERIT:
/* If the input is connected to a terminal, inherit that... */
- if (is_terminal_input(i) || i == EXEC_INPUT_SOCKET)
+ if (i != EXEC_INPUT_NULL)
return dup2(STDIN_FILENO, STDOUT_FILENO) < 0 ? -errno : STDOUT_FILENO;
- return STDIN_FILENO;
+ /* For PID 1 stdout is always connected to /dev/null,
+ * hence reopen the console if out parent is PID1. */
+ if (getppid() == 1)
+ return open_terminal_as(tty_path(context), O_WRONLY, STDOUT_FILENO);
+
+ return STDOUT_FILENO;
case EXEC_OUTPUT_NULL:
return open_null_as(O_WRONLY, STDOUT_FILENO);
assert(context);
assert(ident);
- i = fixup_input(context, socket_fd);
- o = fixup_output(context, socket_fd);
- e = fixup_error(context, socket_fd);
+ i = fixup_input(context->std_input, socket_fd);
+ o = fixup_output(context->std_output, socket_fd);
+ e = fixup_output(context->std_error, socket_fd);
/* This expects the input and output are already set up */
* the way and are not on a tty */
if (e == EXEC_OUTPUT_INHERIT &&
o == EXEC_OUTPUT_INHERIT &&
- !is_terminal_input(i))
+ i != EXEC_INPUT_NULL &&
+ getppid () != 1)
return STDERR_FILENO;
/* Duplicate form stdout if possible */
/* child */
- reset_all_signal_handlers();
+ /* We reset exactly these signals, since they are the
+ * only ones we set to SIG_IGN in the main daemon. All
+ * others we leave untouched because we set them to
+ * SIG_DFL or a valid handler initially, both of which
+ * will be demoted to SIG_DFL. */
+ default_signals(SIGNALS_CRASH_HANDLER,
+ SIGNALS_IGNORE, -1);
if (sigemptyset(&ss) < 0 ||
sigprocmask(SIG_SETMASK, &ss, NULL) < 0) {
c->cpu_sched_policy = SCHED_OTHER;
c->syslog_priority = LOG_DAEMON|LOG_INFO;
c->mount_flags = MS_SHARED;
-
- c->std_input = EXEC_INPUT_NULL;
- c->std_output = EXEC_OUTPUT_SYSLOG;
- c->std_error = EXEC_OUTPUT_SYSLOG;
}
void exec_context_done(ExecContext *c) {