X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fexecute.c;h=06eb15215df5f486c18e82e0e22c6303c9175ea7;hb=dde770cfc6a287772a936be58b73adf9a6c334f5;hp=51e768893c83ff763921306926249cb1422fdbbd;hpb=03fd9c49328be40b53f63b43614eb9bea3a2cf45;p=elogind.git diff --git a/src/execute.c b/src/execute.c index 51e768893..06eb15215 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 */ @@ -1076,10 +1082,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 = EXEC_OUTPUT_SYSLOG; - c->std_error = EXEC_OUTPUT_SYSLOG; } void exec_context_done(ExecContext *c) {