summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-20 01:08:13 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-20 01:08:13 +0200
commitff876e283a61320b718ec752d93b1fd40a5fdd0c (patch)
tree2968b5ff4e6efa27bbc02c2f54cf3f4ada6d1f0f /src
parentca9a0317a45f8a4ab702e9b8ce4542d8452a47ad (diff)
execute: reopen console in the spawned processes, if necessary
Diffstat (limited to 'src')
-rw-r--r--src/execute.c17
-rw-r--r--src/service.c5
2 files changed, 9 insertions, 13 deletions
diff --git a/src/execute.c b/src/execute.c
index f3cf026156..53f6d9ad06 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 necessary. */
+ if (getpid() == 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 &&
+ getpid () != 1)
return STDERR_FILENO;
/* Duplicate form stdout if possible */
@@ -1076,11 +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 = 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) {
diff --git a/src/service.c b/src/service.c
index 2fcb304e86..3e2a499ec8 100644
--- a/src/service.c
+++ b/src/service.c
@@ -632,11 +632,6 @@ static int service_load_sysv_path(Service *s, const char *path) {
s->valid_no_process = true;
s->kill_mode = KILL_PROCESS_GROUP;
- /* For SysV services log output should go to the console */
- s->exec_context.std_input = EXEC_INPUT_NULL;
- s->exec_context.std_output = EXEC_OUTPUT_TTY;
- s->exec_context.std_error = EXEC_OUTPUT_TTY;
-
u->meta.load_state = UNIT_LOADED;
r = 0;