Skip to content

Commit

Permalink
journal: Make journal+console apply to native journal and syslog mess…
Browse files Browse the repository at this point in the history
…ages

When StandardOutput=journal+console, let's make sure that any messages
received via the native journal socket and syslog are forwarded to the
console as well (or kmsg or syslog).

Fixes systemd#32550
  • Loading branch information
DaanDeMeyer committed Apr 29, 2024
1 parent b2173f5 commit f09fc51
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/journal/journald-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "time-util.h"

typedef struct ClientContext ClientContext;
typedef struct StdoutStream StdoutStream;

#include "journald-server.h"

Expand Down Expand Up @@ -59,6 +60,8 @@ struct ClientContext {

Set *log_filter_allowed_patterns;
Set *log_filter_denied_patterns;

StdoutStream *stream;
};

int client_context_get(
Expand Down
1 change: 1 addition & 0 deletions src/journal/journald-kmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "journal-internal.h"
#include "journald-kmsg.h"
#include "journald-server.h"
#include "journald-stream.h"
#include "journald-syslog.h"
#include "log.h"
#include "parse-util.h"
Expand Down
6 changes: 3 additions & 3 deletions src/journal/journald-native.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ static int server_process_entry(
if (r <= 0)
goto finish;

if (s->forward_to_syslog)
if (s->forward_to_syslog || stdout_stream_forward_to_syslog(context->stream))
server_forward_syslog(s, syslog_fixup_facility(priority), identifier, message, ucred, tv);

if (s->forward_to_kmsg)
if (s->forward_to_kmsg || stdout_stream_forward_to_kmsg(context->stream))
server_forward_kmsg(s, priority, identifier, message, ucred);

if (s->forward_to_console)
if (s->forward_to_console || stdout_stream_forward_to_console(context->stream))
server_forward_console(s, priority, identifier, message, ucred);

if (s->forward_to_wall)
Expand Down
15 changes: 15 additions & 0 deletions src/journal/journald-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ struct StdoutStream {
char id_field[STRLEN("_STREAM_ID=") + SD_ID128_STRING_MAX];
};

bool stdout_stream_forward_to_console(StdoutStream *s) {
return s && s->forward_to_console;
}

bool stdout_stream_forward_to_kmsg(StdoutStream *s) {
return s && s->forward_to_kmsg;
}

bool stdout_stream_forward_to_syslog(StdoutStream *s) {
return s && s->forward_to_syslog;
}

StdoutStream* stdout_stream_free(StdoutStream *s) {
if (!s)
return NULL;
Expand Down Expand Up @@ -272,6 +284,9 @@ static int stdout_stream_log(
if (r < 0)
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
"Failed to acquire client context, ignoring: %m");

if (s->context)
s->context->stream = s;
}

priority = s->priority;
Expand Down
4 changes: 4 additions & 0 deletions src/journal/journald-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ StdoutStream* stdout_stream_free(StdoutStream *s);
int stdout_stream_install(Server *s, int fd, StdoutStream **ret);
void stdout_stream_destroy(StdoutStream *s);
void stdout_stream_send_notify(StdoutStream *s);

bool stdout_stream_forward_to_console(StdoutStream *s);
bool stdout_stream_forward_to_kmsg(StdoutStream *s);
bool stdout_stream_forward_to_syslog(StdoutStream *s);
6 changes: 3 additions & 3 deletions src/journal/journald-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ void server_process_syslog_message(

syslog_parse_identifier(&msg, &identifier, &pid);

if (s->forward_to_syslog)
if (s->forward_to_syslog || stdout_stream_forward_to_syslog(context->stream))
forward_syslog_raw(s, priority, buf, raw_len, ucred, tv);

if (s->forward_to_kmsg)
if (s->forward_to_kmsg || stdout_stream_forward_to_kmsg(context->stream))
server_forward_kmsg(s, priority, identifier, msg, ucred);

if (s->forward_to_console)
if (s->forward_to_console || stdout_stream_forward_to_console(context->stream))
server_forward_console(s, priority, identifier, msg, ucred);

if (s->forward_to_wall)
Expand Down

0 comments on commit f09fc51

Please sign in to comment.