From 210ca71cb5d9f41df3b23eef28d6742bd90a0362 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 19 Feb 2024 20:55:51 +0800 Subject: [PATCH] core/execute: clean up log_exec_full_errno and friends Also drop unused log_exec_struct_iovec(). --- src/core/exec-invoke.c | 1 - src/core/execute.h | 92 +++++++++++++++++------------------------- src/core/executor.c | 1 - 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 02f66ead2d..1bd21a2bdf 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4795,7 +4795,6 @@ int exec_invoke( *exit_status = EXIT_EXEC; log_exec_struct_errno(context, params, LOG_NOTICE, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, - LOG_EXEC_INVOCATION_ID(params), LOG_EXEC_MESSAGE(params, "Unable to locate executable '%s': %m", command->path), diff --git a/src/core/execute.h b/src/core/execute.h index eea6b7518a..21dddedffe 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -616,23 +616,26 @@ bool exec_needs_ipc_namespace(const ExecContext *context); #define LOG_EXEC_INVOCATION_ID_FIELD_FORMAT(ep) \ ((ep)->runtime_scope == RUNTIME_SCOPE_USER ? "USER_INVOCATION_ID=%s" : "INVOCATION_ID=%s") -#define log_exec_full_errno_zerook(ec, ep, level, error, ...) \ - ({ \ - const ExecContext *_c = (ec); \ - const ExecParameters *_p = (ep); \ - const int _l = (level); \ - bool _do_log = !(log_get_max_level() < LOG_PRI(_l) || \ - !(_c->log_level_max < 0 || \ - _c->log_level_max >= LOG_PRI(_l))); \ - LOG_CONTEXT_PUSH_IOV(_c->log_extra_fields, \ - _c->n_log_extra_fields); \ - !_do_log ? -ERRNO_VALUE(error) : \ - log_object_internal(_l, error, PROJECT_FILE, \ - __LINE__, __func__, \ - LOG_EXEC_ID_FIELD(_p), \ - _p->unit_id, \ - LOG_EXEC_INVOCATION_ID_FIELD(_p), \ - _p->invocation_id_string, ##__VA_ARGS__); \ +/* Like LOG_MESSAGE(), but with the unit name prefixed. */ +#define LOG_EXEC_MESSAGE(ep, fmt, ...) LOG_MESSAGE("%s: " fmt, (ep)->unit_id, ##__VA_ARGS__) +#define LOG_EXEC_ID(ep) LOG_EXEC_ID_FIELD_FORMAT(ep), (ep)->unit_id +#define LOG_EXEC_INVOCATION_ID(ep) LOG_EXEC_INVOCATION_ID_FIELD_FORMAT(ep), (ep)->invocation_id_string + +#define log_exec_full_errno_zerook(ec, ep, level, error, ...) \ + ({ \ + const ExecContext *_c = (ec); \ + const ExecParameters *_p = (ep); \ + const int _l = (level); \ + bool _do_log = _c->log_level_max >= 0 && \ + _c->log_level_max < LOG_PRI(_l); \ + LOG_CONTEXT_PUSH_IOV(_c->log_extra_fields, \ + _c->n_log_extra_fields); \ + !_do_log ? -ERRNO_VALUE(error) : \ + log_object_internal(_l, error, \ + PROJECT_FILE, __LINE__, __func__, \ + LOG_EXEC_ID(_p), \ + LOG_EXEC_INVOCATION_ID(_p), \ + ##__VA_ARGS__); \ }) #define log_exec_full_errno(ec, ep, level, error, ...) \ @@ -656,48 +659,29 @@ bool exec_needs_ipc_namespace(const ExecContext *context); #define log_exec_warning_errno(ec, ep, error, ...) log_exec_full_errno(ec, ep, LOG_WARNING, error, __VA_ARGS__) #define log_exec_error_errno(ec, ep, error, ...) log_exec_full_errno(ec, ep, LOG_ERR, error, __VA_ARGS__) -#define log_exec_struct_errno(ec, ep, level, error, ...) \ - ({ \ - const ExecContext *_c = (ec); \ - const ExecParameters *_p = (ep); \ - const int _l = (level); \ - bool _do_log = !(_c->log_level_max < 0 || \ - _c->log_level_max >= LOG_PRI(_l)); \ - LOG_CONTEXT_PUSH_IOV(_c->log_extra_fields, \ - _c->n_log_extra_fields); \ - _do_log ? \ - log_struct_errno(_l, error, __VA_ARGS__, LOG_EXEC_ID_FIELD_FORMAT(_p), _p->unit_id) : \ - -ERRNO_VALUE(error); \ +#define log_exec_struct_errno(ec, ep, level, error, ...) \ + ({ \ + const ExecContext *_c = (ec); \ + const ExecParameters *_p = (ep); \ + const int _l = (level); \ + bool _do_log = _c->log_level_max >= 0 && \ + _c->log_level_max < LOG_PRI(_l); \ + LOG_CONTEXT_PUSH_IOV(_c->log_extra_fields, \ + _c->n_log_extra_fields); \ + !_do_log ? -ERRNO_VALUE(error) : \ + log_struct_errno(_l, error, \ + LOG_EXEC_ID(_p), \ + LOG_EXEC_INVOCATION_ID(_p), \ + __VA_ARGS__); \ }) #define log_exec_struct(ec, ep, level, ...) log_exec_struct_errno(ec, ep, level, 0, __VA_ARGS__) -#define log_exec_struct_iovec_errno(ec, ep, level, error, iovec, n_iovec) \ - ({ \ - const ExecContext *_c = (ec); \ - const ExecParameters *_p = (ep); \ - const int _l = (level); \ - bool _do_log = !(_c->log_level_max < 0 || \ - _c->log_level_max >= LOG_PRI(_l)); \ - LOG_CONTEXT_PUSH_IOV(_c->log_extra_fields, \ - _c->n_log_extra_fields); \ - _do_log ? \ - log_struct_iovec_errno(_l, error, iovec, n_iovec) : \ - -ERRNO_VALUE(error); \ - }) - -#define log_exec_struct_iovec(ec, ep, level, iovec, n_iovec) log_exec_struct_iovec_errno(ec, ep, level, 0, iovec, n_iovec) - -/* Like LOG_MESSAGE(), but with the unit name prefixed. */ -#define LOG_EXEC_MESSAGE(ep, fmt, ...) LOG_MESSAGE("%s: " fmt, (ep)->unit_id, ##__VA_ARGS__) -#define LOG_EXEC_ID(ep) LOG_EXEC_ID_FIELD_FORMAT(ep), (ep)->unit_id -#define LOG_EXEC_INVOCATION_ID(ep) LOG_EXEC_INVOCATION_ID_FIELD_FORMAT(ep), (ep)->invocation_id_string - -#define _LOG_CONTEXT_PUSH_EXEC(ec, ep, p, c) \ - const ExecContext *c = (ec); \ - const ExecParameters *p = (ep); \ +#define _LOG_CONTEXT_PUSH_EXEC(ec, ep, p, c) \ + const ExecContext *c = (ec); \ + const ExecParameters *p = (ep); \ LOG_CONTEXT_PUSH_KEY_VALUE(LOG_EXEC_ID_FIELD(p), p->unit_id); \ - LOG_CONTEXT_PUSH_KEY_VALUE(LOG_EXEC_INVOCATION_ID_FIELD(p), p->invocation_id_string); \ + LOG_CONTEXT_PUSH_KEY_VALUE(LOG_EXEC_INVOCATION_ID_FIELD(p), p->invocation_id_string); \ LOG_CONTEXT_PUSH_IOV(c->log_extra_fields, c->n_log_extra_fields) #define LOG_CONTEXT_PUSH_EXEC(ec, ep) \ diff --git a/src/core/executor.c b/src/core/executor.c index 162561e9d4..bd0c742533 100644 --- a/src/core/executor.c +++ b/src/core/executor.c @@ -245,7 +245,6 @@ static int run(int argc, char *argv[]) { log_exec_struct_errno(&context, ¶ms, LOG_ERR, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, - LOG_EXEC_INVOCATION_ID(¶ms), LOG_EXEC_MESSAGE(¶ms, "Failed at step %s spawning %s: %m", status, command.path), "EXECUTABLE=%s", command.path); -- 2.25.1