Skip to content

Commit

Permalink
core: automatically update StandardOuput=syslog to =journal (and simi…
Browse files Browse the repository at this point in the history
…lar 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
  • Loading branch information
poettering committed May 14, 2020
1 parent d2b8435 commit f3dc6af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
17 changes: 1 addition & 16 deletions src/core/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)) {

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/core/execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 36 additions & 8 deletions src/core/load-fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -5051,23 +5065,37 @@ 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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f3dc6af

Please sign in to comment.