X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fexecute.c;h=ead6c0fa423fd2c322bbedd37686a0ca4c2d7b28;hp=f3cf0261568377b9bce62c620eef015aaf909c25;hb=9a34ec5fbb4b55413dc9d610b636fe760d34ecd7;hpb=8783d2feaeb74fa37494b84024521a6e8a9b9276 diff --git a/src/execute.c b/src/execute.c index f3cf02615..ead6c0fa4 100644 --- a/src/execute.c +++ b/src/execute.c @@ -301,10 +301,15 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i 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); @@ -346,7 +351,8 @@ static int setup_error(const ExecContext *context, int socket_fd, const char *id * 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 */ @@ -777,7 +783,11 @@ int exec_spawn(ExecCommand *command, /* child */ - reset_all_signal_handlers(); + /* We reset exactly these two signals, since they are + * the only ones we set to SIG_IGN in the main + * daemon. All others */ + default_signals(SIGNALS_CRASH_HANLDER, + SIGNALS_IGNORE, -1); if (sigemptyset(&ss) < 0 || sigprocmask(SIG_SETMASK, &ss, NULL) < 0) { @@ -1076,11 +1086,6 @@ void exec_context_init(ExecContext *c) { 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 = c->std_error = - (log_get_target() == LOG_TARGET_CONSOLE ? EXEC_OUTPUT_INHERIT : - log_get_target() == LOG_TARGET_KMSG ? EXEC_OUTPUT_KMSG : EXEC_OUTPUT_SYSLOG); } void exec_context_done(ExecContext *c) {