summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2013-02-15 22:43:23 +0100
committerMichal Schmidt <mschmidt@redhat.com>2013-02-16 01:18:02 +0100
commit47c1d80d844689c81faf2eede95803c1ed6eb4af (patch)
tree905b40a9a1c3c414ba612c86b702cb1e8906d80e
parent4a01181e460686d8b4a543b1dfa7f77c9e3c5ab8 (diff)
execute: robustness against journald failures
Almost every unit logs to the journal. If journald gets a permanent failure, units would not be able to start (exit code 209/STDOUT). Add a fallback to /dev/null to avoid making the system entirely unusable in such a case.
-rw-r--r--src/core/execute.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index 3376adc34a..b878c331d5 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -323,6 +323,7 @@ static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty
static int setup_output(const ExecContext *context, int socket_fd, const char *ident, const char *unit_id, bool apply_tty_stdin) {
ExecOutput o;
ExecInput i;
+ int r;
assert(context);
assert(ident);
@@ -367,7 +368,12 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
case EXEC_OUTPUT_KMSG_AND_CONSOLE:
case EXEC_OUTPUT_JOURNAL:
case EXEC_OUTPUT_JOURNAL_AND_CONSOLE:
- return connect_logger_as(context, o, ident, unit_id, STDOUT_FILENO);
+ r = connect_logger_as(context, o, ident, unit_id, STDOUT_FILENO);
+ if (r < 0) {
+ log_error("Failed to connect stdout of %s to the journal socket: %s", unit_id, strerror(-r));
+ r = open_null_as(O_WRONLY, STDOUT_FILENO);
+ }
+ return r;
case EXEC_OUTPUT_SOCKET:
assert(socket_fd >= 0);
@@ -381,6 +387,7 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
static int setup_error(const ExecContext *context, int socket_fd, const char *ident, const char *unit_id, bool apply_tty_stdin) {
ExecOutput o, e;
ExecInput i;
+ int r;
assert(context);
assert(ident);
@@ -422,7 +429,12 @@ static int setup_error(const ExecContext *context, int socket_fd, const char *id
case EXEC_OUTPUT_KMSG_AND_CONSOLE:
case EXEC_OUTPUT_JOURNAL:
case EXEC_OUTPUT_JOURNAL_AND_CONSOLE:
- return connect_logger_as(context, e, ident, unit_id, STDERR_FILENO);
+ r = connect_logger_as(context, e, ident, unit_id, STDERR_FILENO);
+ if (r < 0) {
+ log_error("Failed to connect stderr of %s to the journal socket: %s", unit_id, strerror(-r));
+ r = open_null_as(O_WRONLY, STDERR_FILENO);
+ }
+ return r;
case EXEC_OUTPUT_SOCKET:
assert(socket_fd >= 0);