From d93dda3afef4d8bfae8e4d20122adfa5e2cc41f8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 27 Nov 2019 12:13:59 +0100 Subject: [PATCH] systemctl: show logs for correct namespace of service --- src/login/loginctl.c | 2 ++ src/machine/machinectl.c | 1 + src/shared/logs-show.c | 3 ++- src/shared/logs-show.h | 1 + src/systemctl/systemctl.c | 4 ++++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 6fea2c9e33..2e39f55763 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -576,6 +576,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li show_journal_by_unit( stdout, i.scope, + NULL, arg_output, 0, i.timestamp.monotonic, @@ -660,6 +661,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) show_journal_by_unit( stdout, i.slice, + NULL, arg_output, 0, i.timestamp.monotonic, diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 2377416b44..61234582a3 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -626,6 +626,7 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) { show_journal_by_unit( stdout, i->unit, + NULL, arg_output, 0, i->timestamp.monotonic, diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index ce0a4acf9c..605412aec5 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1453,6 +1453,7 @@ int add_match_this_boot(sd_journal *j, const char *machine) { int show_journal_by_unit( FILE *f, const char *unit, + const char *log_namespace, OutputMode mode, unsigned n_columns, usec_t not_before, @@ -1473,7 +1474,7 @@ int show_journal_by_unit( if (how_many <= 0) return 0; - r = sd_journal_open(&j, journal_open_flags); + r = sd_journal_open_namespace(&j, log_namespace, journal_open_flags | SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE); if (r < 0) return log_error_errno(r, "Failed to open journal: %m"); diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 1e0c4ea146..345efa4b2b 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -46,6 +46,7 @@ int add_matches_for_user_unit( int show_journal_by_unit( FILE *f, const char *unit, + const char *namespace, OutputMode mode, unsigned n_columns, usec_t not_before, diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 60872bc537..5547058296 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4007,6 +4007,8 @@ typedef struct UnitStatusInfo { int exit_code, exit_status; + const char *log_namespace; + usec_t condition_timestamp; bool condition_result; LIST_HEAD(UnitCondition, conditions); @@ -4545,6 +4547,7 @@ static void print_status_info( show_journal_by_unit( stdout, i->id, + i->log_namespace, arg_output, 0, i->inactive_exit_timestamp_monotonic, @@ -5491,6 +5494,7 @@ static int show_one( { "ExecMainExitTimestamp", "t", NULL, offsetof(UnitStatusInfo, exit_timestamp) }, { "ExecMainCode", "i", NULL, offsetof(UnitStatusInfo, exit_code) }, { "ExecMainStatus", "i", NULL, offsetof(UnitStatusInfo, exit_status) }, + { "LogNamespace", "s", NULL, offsetof(UnitStatusInfo, log_namespace) }, { "ConditionTimestamp", "t", NULL, offsetof(UnitStatusInfo, condition_timestamp) }, { "ConditionResult", "b", NULL, offsetof(UnitStatusInfo, condition_result) }, { "Conditions", "a(sbbsi)", map_conditions, 0 },