From f1c50becda3a6ef44e43f503e138f5f4a4884ce3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 Sep 2017 18:27:53 +0200 Subject: [PATCH] core: make sure to log invocation ID of units also when doing structured logging --- src/core/execute.c | 5 +++++ src/core/job.c | 2 ++ src/core/manager.c | 4 ++-- src/core/service.c | 2 ++ src/core/unit.c | 3 +++ src/core/unit.h | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 28c6b2f..6b43364 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -3150,6 +3150,7 @@ static int exec_child( "EXECUTABLE=%s", command->path, LOG_UNIT_MESSAGE(unit, "Executing: %s", line), LOG_UNIT_ID(unit), + LOG_UNIT_INVOCATION_ID(unit), NULL); log_close(); } @@ -3223,6 +3224,7 @@ int exec_spawn(Unit *unit, LOG_UNIT_MESSAGE(unit, "About to execute: %s", line), "EXECUTABLE=%s", command->path, LOG_UNIT_ID(unit), + LOG_UNIT_INVOCATION_ID(unit), NULL); pid = fork(); if (pid < 0) @@ -3254,6 +3256,7 @@ int exec_spawn(Unit *unit, log_struct_errno(LOG_ERR, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, LOG_UNIT_ID(unit), + LOG_UNIT_INVOCATION_ID(unit), LOG_UNIT_MESSAGE(unit, "%s: %m", error_message), "EXECUTABLE=%s", command->path, @@ -3262,6 +3265,7 @@ int exec_spawn(Unit *unit, log_struct_errno(LOG_INFO, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, LOG_UNIT_ID(unit), + LOG_UNIT_INVOCATION_ID(unit), LOG_UNIT_MESSAGE(unit, "Skipped spawning %s: %m", command->path), "EXECUTABLE=%s", command->path, @@ -3270,6 +3274,7 @@ int exec_spawn(Unit *unit, log_struct_errno(LOG_ERR, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, LOG_UNIT_ID(unit), + LOG_UNIT_INVOCATION_ID(unit), LOG_UNIT_MESSAGE(unit, "Failed at step %s spawning %s: %m", exit_status_to_string(exit_status, EXIT_STATUS_SYSTEMD), command->path), diff --git a/src/core/job.c b/src/core/job.c index 8e2039d..dd07330 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -808,6 +808,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) { LOG_MESSAGE("%s", buf), "RESULT=%s", job_result_to_string(result), LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), NULL); return; } @@ -816,6 +817,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) { LOG_MESSAGE("%s", buf), "RESULT=%s", job_result_to_string(result), LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), mid, NULL); } diff --git a/src/core/manager.c b/src/core/manager.c index 032e75d..5cf4bc4 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -631,13 +631,13 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { m->unit_log_format_string = "UNIT=%s"; m->invocation_log_field = "INVOCATION_ID="; - m->invocation_log_format_string = "INVOCATION_ID=" SD_ID128_FORMAT_STR; + m->invocation_log_format_string = "INVOCATION_ID=%s"; } else { m->unit_log_field = "USER_UNIT="; m->unit_log_format_string = "USER_UNIT=%s"; m->invocation_log_field = "USER_INVOCATION_ID="; - m->invocation_log_format_string = "USER_INVOCATION_ID=" SD_ID128_FORMAT_STR; + m->invocation_log_format_string = "USER_INVOCATION_ID=%s"; } m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1; diff --git a/src/core/service.c b/src/core/service.c index b0ce9bf..21fc4e2 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1956,6 +1956,7 @@ static void service_enter_restart(Service *s) { log_struct(LOG_INFO, "MESSAGE_ID=" SD_MESSAGE_UNIT_RESTART_SCHEDULED_STR, LOG_UNIT_ID(UNIT(s)), + LOG_UNIT_INVOCATION_ID(UNIT(s)), LOG_UNIT_MESSAGE(UNIT(s), "Scheduled restart job, restart counter is at %u.", s->n_restarts), "N_RESTARTS=%u", s->n_restarts, NULL); @@ -2951,6 +2952,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { "EXIT_CODE=%s", sigchld_code_to_string(code), "EXIT_STATUS=%i", status, LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), NULL); if (s->result == SERVICE_SUCCESS) diff --git a/src/core/unit.c b/src/core/unit.c index 68295d6..65a8c77 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1544,6 +1544,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) { log_struct(LOG_INFO, LOG_MESSAGE("%s", buf), LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), mid, NULL); } @@ -4242,6 +4243,7 @@ void unit_warn_if_dir_nonempty(Unit *u, const char* where) { log_struct(LOG_NOTICE, "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR, LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), LOG_UNIT_MESSAGE(u, "Directory %s to mount over is not empty, mounting anyway.", where), "WHERE=%s", where, NULL); @@ -4264,6 +4266,7 @@ int unit_fail_if_symlink(Unit *u, const char* where) { log_struct(LOG_ERR, "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR, LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u), LOG_UNIT_MESSAGE(u, "Mount on symlink %s not allowed.", where), "WHERE=%s", where, NULL); diff --git a/src/core/unit.h b/src/core/unit.h index 2759bd0..9aa00b0 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -710,3 +710,4 @@ int unit_fork_helper_process(Unit *u, pid_t *ret); #define LOG_UNIT_MESSAGE(unit, fmt, ...) "MESSAGE=%s: " fmt, (unit)->id, ##__VA_ARGS__ #define LOG_UNIT_ID(unit) (unit)->manager->unit_log_format_string, (unit)->id +#define LOG_UNIT_INVOCATION_ID(unit) (unit)->manager->invocation_log_format_string, (unit)->invocation_id_string -- 2.7.4