From d2b843554add03b938416f33705e4896aee6995c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 May 2020 12:19:46 +0200 Subject: [PATCH 1/2] man: drop some left-over mentions of StandardOutput=syslog We dropped them from the StandardOuput= documentation long ago, but elswhere some references where lurking. --- man/sd-daemon.xml | 7 +++---- man/systemd.exec.xml | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/man/sd-daemon.xml b/man/sd-daemon.xml index 64ed5f3779..a01ec58786 100644 --- a/man/sd-daemon.xml +++ b/man/sd-daemon.xml @@ -70,10 +70,9 @@ These prefixes are intended to be used in conjunction with stderr-based logging (or stdout-based logging) as implemented by systemd. If a systemd service definition file is configured with - StandardError=journal, StandardError=syslog or - StandardError=kmsg (and similar with StandardOutput=), these - prefixes can be used to encode a log level in lines printed. This is similar to the kernel - printk()-style logging. See + StandardError=journal or StandardError=kmsg (and similar with + StandardOutput=), these prefixes can be used to encode a log level in lines + printed. This is similar to the kernel printk()-style logging. See klogctl2 for more information. diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 6b28dc5769..8f57cc8bfb 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -66,9 +66,9 @@ will also gain an automatic After= dependency on systemd-tmpfiles-setup.service8. - Units whose standard output or error output is connected to , - or (or their combinations with console output, see below) - automatically acquire dependencies of type After= on + Units whose standard output or error output is connected to or + (or their combinations with console output, see below) automatically acquire + dependencies of type After= on systemd-journald.socket. Units using LogNamespace= will automatically gain ordering and From f3dc6af20f410702beb8e45ddf77e92289fc90c7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 May 2020 12:20:39 +0200 Subject: [PATCH 2/2] core: automatically update StandardOuput=syslog to =journal (and similar for StandardError=) Let's go one step further and upgrade implicitly. Usually =syslog assignments are historic artifacts only. Let's upgrade the lines automatically, and politely suggest people update their unit files/configuration (and drop the lines altogether, without replacement). Fixes: #15807 --- src/core/execute.c | 17 +--------------- src/core/execute.h | 2 -- src/core/load-fragment.c | 44 ++++++++++++++++++++++++++++++++-------- src/core/unit.c | 6 ++---- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index ef4815440a..aa253a5ddf 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -219,17 +219,10 @@ static bool is_terminal_input(ExecInput i) { static bool is_terminal_output(ExecOutput o) { return IN_SET(o, EXEC_OUTPUT_TTY, - EXEC_OUTPUT_SYSLOG_AND_CONSOLE, EXEC_OUTPUT_KMSG_AND_CONSOLE, EXEC_OUTPUT_JOURNAL_AND_CONSOLE); } -static bool is_syslog_output(ExecOutput o) { - return IN_SET(o, - EXEC_OUTPUT_SYSLOG, - EXEC_OUTPUT_SYSLOG_AND_CONSOLE); -} - static bool is_kmsg_output(ExecOutput o) { return IN_SET(o, EXEC_OUTPUT_KMSG, @@ -361,7 +354,7 @@ static int connect_logger_as( params->flags & EXEC_PASS_LOG_UNIT ? unit->id : "", context->syslog_priority, !!context->syslog_level_prefix, - is_syslog_output(output), + false, is_kmsg_output(output), is_terminal_output(output)) < 0) return -errno; @@ -664,8 +657,6 @@ static int setup_output( /* We don't reset the terminal if this is just about output */ return open_terminal_as(exec_context_tty_path(context), O_WRONLY, fileno); - case EXEC_OUTPUT_SYSLOG: - case EXEC_OUTPUT_SYSLOG_AND_CONSOLE: case EXEC_OUTPUT_KMSG: case EXEC_OUTPUT_KMSG_AND_CONSOLE: case EXEC_OUTPUT_JOURNAL: @@ -4736,17 +4727,13 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { prefix, yes_no(c->tty_vt_disallocate)); if (IN_SET(c->std_output, - EXEC_OUTPUT_SYSLOG, EXEC_OUTPUT_KMSG, EXEC_OUTPUT_JOURNAL, - EXEC_OUTPUT_SYSLOG_AND_CONSOLE, EXEC_OUTPUT_KMSG_AND_CONSOLE, EXEC_OUTPUT_JOURNAL_AND_CONSOLE) || IN_SET(c->std_error, - EXEC_OUTPUT_SYSLOG, EXEC_OUTPUT_KMSG, EXEC_OUTPUT_JOURNAL, - EXEC_OUTPUT_SYSLOG_AND_CONSOLE, EXEC_OUTPUT_KMSG_AND_CONSOLE, EXEC_OUTPUT_JOURNAL_AND_CONSOLE)) { @@ -5764,8 +5751,6 @@ static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = { [EXEC_OUTPUT_INHERIT] = "inherit", [EXEC_OUTPUT_NULL] = "null", [EXEC_OUTPUT_TTY] = "tty", - [EXEC_OUTPUT_SYSLOG] = "syslog", - [EXEC_OUTPUT_SYSLOG_AND_CONSOLE] = "syslog+console", [EXEC_OUTPUT_KMSG] = "kmsg", [EXEC_OUTPUT_KMSG_AND_CONSOLE] = "kmsg+console", [EXEC_OUTPUT_JOURNAL] = "journal", diff --git a/src/core/execute.h b/src/core/execute.h index f96a2915eb..7e1015631f 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -52,8 +52,6 @@ typedef enum ExecOutput { EXEC_OUTPUT_INHERIT, EXEC_OUTPUT_NULL, EXEC_OUTPUT_TTY, - EXEC_OUTPUT_SYSLOG, - EXEC_OUTPUT_SYSLOG_AND_CONSOLE, EXEC_OUTPUT_KMSG, EXEC_OUTPUT_KMSG_AND_CONSOLE, EXEC_OUTPUT_JOURNAL, diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 9c24bb780a..33b1d47da6 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1099,6 +1099,7 @@ int config_parse_exec_output( const char *n; ExecContext *c = data; const Unit *u = userdata; + bool obsolete = false; ExecOutput eo; int r; @@ -1123,6 +1124,14 @@ int config_parse_exec_output( eo = EXEC_OUTPUT_NAMED_FD; + } else if (streq(rvalue, "syslog")) { + eo = EXEC_OUTPUT_JOURNAL; + obsolete = true; + + } else if (streq(rvalue, "syslog+console")) { + eo = EXEC_OUTPUT_JOURNAL_AND_CONSOLE; + obsolete = true; + } else if ((n = startswith(rvalue, "file:"))) { r = unit_full_printf(u, n, &resolved); @@ -1154,6 +1163,11 @@ int config_parse_exec_output( } } + if (obsolete) + log_syntax(unit, LOG_NOTICE, filename, line, 0, + "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.", + rvalue, exec_output_to_string(eo)); + if (streq(lvalue, "StandardOutput")) { if (eo == EXEC_OUTPUT_NAMED_FD) free_and_replace(c->stdio_fdname[STDOUT_FILENO], resolved); @@ -5051,22 +5065,36 @@ int config_parse_output_restricted( void *userdata) { ExecOutput t, *eo = data; + bool obsolete = false; assert(filename); assert(lvalue); assert(rvalue); assert(data); - t = exec_output_from_string(rvalue); - if (t < 0) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output type, ignoring: %s", rvalue); - return 0; + if (streq(rvalue, "syslog")) { + t = EXEC_OUTPUT_JOURNAL; + obsolete = true; + } else if (streq(rvalue, "syslog+console")) { + t = EXEC_OUTPUT_JOURNAL_AND_CONSOLE; + obsolete = true; + } else { + t = exec_output_from_string(rvalue); + if (t < 0) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output type, ignoring: %s", rvalue); + return 0; + } + + if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND)) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue); + return 0; + } } - if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND)) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue); - return 0; - } + if (obsolete) + log_syntax(unit, LOG_NOTICE, filename, line, 0, + "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.", + rvalue, exec_output_to_string(t)); *eo = t; return 0; diff --git a/src/core/unit.c b/src/core/unit.c index 7c8bae9a0d..84a5e5a948 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1123,12 +1123,10 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { if (!IN_SET(c->std_output, EXEC_OUTPUT_JOURNAL, EXEC_OUTPUT_JOURNAL_AND_CONSOLE, - EXEC_OUTPUT_KMSG, EXEC_OUTPUT_KMSG_AND_CONSOLE, - EXEC_OUTPUT_SYSLOG, EXEC_OUTPUT_SYSLOG_AND_CONSOLE) && + EXEC_OUTPUT_KMSG, EXEC_OUTPUT_KMSG_AND_CONSOLE) && !IN_SET(c->std_error, EXEC_OUTPUT_JOURNAL, EXEC_OUTPUT_JOURNAL_AND_CONSOLE, - EXEC_OUTPUT_KMSG, EXEC_OUTPUT_KMSG_AND_CONSOLE, - EXEC_OUTPUT_SYSLOG, EXEC_OUTPUT_SYSLOG_AND_CONSOLE) && + EXEC_OUTPUT_KMSG, EXEC_OUTPUT_KMSG_AND_CONSOLE) && !c->log_namespace) return 0;