]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: Move log context functions to log-context.h
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 18 Apr 2025 08:47:23 +0000 (10:47 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 18 Apr 2025 09:57:33 +0000 (11:57 +0200)
src/basic/log-context.c [new file with mode: 0644]
src/basic/log-context.h [new file with mode: 0644]
src/basic/log.c
src/basic/log.h
src/basic/meson.build
src/core/unit.h
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-device/device-monitor.c
src/portable/portable.c
src/test/test-log.c

diff --git a/src/basic/log-context.c b/src/basic/log-context.c
new file mode 100644 (file)
index 0000000..4ad0864
--- /dev/null
@@ -0,0 +1,180 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <threads.h>
+
+#include "env-util.h"
+#include "iovec-util.h"
+#include "log.h"
+#include "log-context.h"
+#include "strv.h"
+
+static int saved_log_context_enabled = -1;
+thread_local LIST_HEAD(LogContext, _log_context) = NULL;
+thread_local size_t _log_context_num_fields = 0;
+
+bool log_context_enabled(void) {
+        int r;
+
+        if (log_get_max_level() == LOG_DEBUG)
+                return true;
+
+        if (saved_log_context_enabled >= 0)
+                return saved_log_context_enabled;
+
+        r = secure_getenv_bool("SYSTEMD_ENABLE_LOG_CONTEXT");
+        if (r < 0 && r != -ENXIO)
+                log_debug_errno(r, "Failed to parse $SYSTEMD_ENABLE_LOG_CONTEXT, ignoring: %m");
+
+        saved_log_context_enabled = r > 0;
+
+        return saved_log_context_enabled;
+}
+
+static LogContext* log_context_attach(LogContext *c) {
+        assert(c);
+
+        _log_context_num_fields += strv_length(c->fields);
+        _log_context_num_fields += c->n_input_iovec;
+        _log_context_num_fields += !!c->key;
+
+        return LIST_PREPEND(ll, _log_context, c);
+}
+
+static LogContext* log_context_detach(LogContext *c) {
+        if (!c)
+                return NULL;
+
+        assert(_log_context_num_fields >= strv_length(c->fields) + c->n_input_iovec +!!c->key);
+        _log_context_num_fields -= strv_length(c->fields);
+        _log_context_num_fields -= c->n_input_iovec;
+        _log_context_num_fields -= !!c->key;
+
+        LIST_REMOVE(ll, _log_context, c);
+        return NULL;
+}
+
+LogContext* log_context_new(const char *key, const char *value) {
+        assert(key);
+        assert(endswith(key, "="));
+        assert(value);
+
+        LIST_FOREACH(ll, i, _log_context)
+                if (i->key == key && i->value == value)
+                        return log_context_ref(i);
+
+        LogContext *c = new(LogContext, 1);
+        if (!c)
+                return NULL;
+
+        *c = (LogContext) {
+                .n_ref = 1,
+                .key = (char *) key,
+                .value = (char *) value,
+        };
+
+        return log_context_attach(c);
+}
+
+LogContext* log_context_new_strv(char **fields, bool owned) {
+        if (!fields)
+                return NULL;
+
+        LIST_FOREACH(ll, i, _log_context)
+                if (i->fields == fields) {
+                        assert(!owned);
+                        return log_context_ref(i);
+                }
+
+        LogContext *c = new(LogContext, 1);
+        if (!c)
+                return NULL;
+
+        *c = (LogContext) {
+                .n_ref = 1,
+                .fields = fields,
+                .owned = owned,
+        };
+
+        return log_context_attach(c);
+}
+
+LogContext* log_context_new_iov(struct iovec *input_iovec, size_t n_input_iovec, bool owned) {
+        if (!input_iovec || n_input_iovec == 0)
+                return NULL;
+
+        LIST_FOREACH(ll, i, _log_context)
+                if (i->input_iovec == input_iovec && i->n_input_iovec == n_input_iovec) {
+                        assert(!owned);
+                        return log_context_ref(i);
+                }
+
+        LogContext *c = new(LogContext, 1);
+        if (!c)
+                return NULL;
+
+        *c = (LogContext) {
+                .n_ref = 1,
+                .input_iovec = input_iovec,
+                .n_input_iovec = n_input_iovec,
+                .owned = owned,
+        };
+
+        return log_context_attach(c);
+}
+
+static LogContext* log_context_free(LogContext *c) {
+        if (!c)
+                return NULL;
+
+        log_context_detach(c);
+
+        if (c->owned) {
+                strv_free(c->fields);
+                iovec_array_free(c->input_iovec, c->n_input_iovec);
+                free(c->key);
+                free(c->value);
+        }
+
+        return mfree(c);
+}
+
+DEFINE_TRIVIAL_REF_UNREF_FUNC(LogContext, log_context, log_context_free);
+
+LogContext* log_context_new_strv_consume(char **fields) {
+        LogContext *c = log_context_new_strv(fields, /*owned=*/ true);
+        if (!c)
+                strv_free(fields);
+
+        return c;
+}
+
+LogContext* log_context_new_iov_consume(struct iovec *input_iovec, size_t n_input_iovec) {
+        LogContext *c = log_context_new_iov(input_iovec, n_input_iovec, /*owned=*/ true);
+        if (!c)
+                iovec_array_free(input_iovec, n_input_iovec);
+
+        return c;
+}
+
+LogContext* log_context_head(void) {
+        return _log_context;
+}
+
+size_t log_context_num_contexts(void) {
+        size_t n = 0;
+
+        LIST_FOREACH(ll, c, _log_context)
+                n++;
+
+        return n;
+}
+
+size_t log_context_num_fields(void) {
+        return _log_context_num_fields;
+}
+
+void _reset_log_level(int *saved_log_level) {
+        assert(saved_log_level);
+
+        log_set_max_level(*saved_log_level);
+}
diff --git a/src/basic/log-context.h b/src/basic/log-context.h
new file mode 100644 (file)
index 0000000..7cff79c
--- /dev/null
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "macro.h"
+
+/*
+ * The log context allows attaching extra metadata to log messages written to the journal via log.h. We keep
+ * track of a thread local log context onto which we can push extra metadata fields that should be logged.
+ *
+ * LOG_CONTEXT_PUSH() will add the provided field to the log context and will remove it again when the
+ * current block ends. LOG_CONTEXT_PUSH_STRV() will do the same but for all fields in the given strv.
+ * LOG_CONTEXT_PUSHF() is like LOG_CONTEXT_PUSH() but takes a format string and arguments.
+ *
+ * Using the macros is as simple as putting them anywhere inside a block to add a field to all following log
+ * messages logged from inside that block.
+ *
+ * void myfunction(...) {
+ *         ...
+ *
+ *         LOG_CONTEXT_PUSHF("MYMETADATA=%s", "abc");
+ *
+ *         // Every journal message logged will now have the MYMETADATA=abc
+ *         // field included.
+ * }
+ *
+ * One special case to note is async code, where we use callbacks that are invoked to continue processing
+ * when some event occurs. For async code, there's usually an associated "userdata" struct containing all the
+ * information associated with the async operation. In this "userdata" struct, we can store a log context
+ * allocated with log_context_new() and freed with log_context_free(). We can then add and remove fields to
+ * the `fields` member of the log context object and all those fields will be logged along with each log
+ * message.
+ */
+
+struct iovec;
+
+typedef struct LogContext {
+        unsigned n_ref;
+        /* Depending on which destructor is used (log_context_free() or log_context_detach()) the memory
+         * referenced by this is freed or not */
+        char **fields;
+        struct iovec *input_iovec;
+        size_t n_input_iovec;
+        char *key;
+        char *value;
+        bool owned;
+        LIST_FIELDS(struct LogContext, ll);
+} LogContext;
+
+bool log_context_enabled(void);
+
+LogContext* log_context_new(const char *key, const char *value);
+LogContext* log_context_new_strv(char **fields, bool owned);
+LogContext* log_context_new_iov(struct iovec *input_iovec, size_t n_input_iovec, bool owned);
+
+/* Same as log_context_new(), but frees the given fields strv/iovec on failure. */
+LogContext* log_context_new_strv_consume(char **fields);
+LogContext* log_context_new_iov_consume(struct iovec *input_iovec, size_t n_input_iovec);
+
+LogContext *log_context_ref(LogContext *c);
+LogContext *log_context_unref(LogContext *c);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(LogContext*, log_context_unref);
+
+/* Returns the head of the log context list. */
+LogContext* log_context_head(void);
+/* Returns the number of attached log context objects. */
+size_t log_context_num_contexts(void);
+/* Returns the number of fields in all attached log contexts. */
+size_t log_context_num_fields(void);
+
+void _reset_log_level(int *saved_log_level);
+
+#define LOG_CONTEXT_SET_LOG_LEVEL(level) \
+        _cleanup_(_reset_log_level) _unused_ int _saved_log_level_ = log_set_max_level(level);
+
+#define LOG_CONTEXT_PUSH(...) \
+        LOG_CONTEXT_PUSH_STRV(STRV_MAKE(__VA_ARGS__))
+
+#define LOG_CONTEXT_PUSHF(...) \
+        LOG_CONTEXT_PUSH(snprintf_ok((char[LINE_MAX]) {}, LINE_MAX, __VA_ARGS__))
+
+#define _LOG_CONTEXT_PUSH_KEY_VALUE(key, value, c) \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new(key, value);
+
+#define LOG_CONTEXT_PUSH_KEY_VALUE(key, value) \
+        _LOG_CONTEXT_PUSH_KEY_VALUE(key, value, UNIQ_T(c, UNIQ))
+
+#define _LOG_CONTEXT_PUSH_STRV(strv, c) \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv(strv, /*owned=*/ false);
+
+#define LOG_CONTEXT_PUSH_STRV(strv) \
+        _LOG_CONTEXT_PUSH_STRV(strv, UNIQ_T(c, UNIQ))
+
+#define _LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec, c) \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_iov(input_iovec, n_input_iovec, /*owned=*/ false);
+
+#define LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec) \
+        _LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec, UNIQ_T(c, UNIQ))
+
+/* LOG_CONTEXT_CONSUME_STR()/LOG_CONTEXT_CONSUME_STRV()/LOG_CONTEXT_CONSUME_IOV() are identical to
+* LOG_CONTEXT_PUSH_STR()/LOG_CONTEXT_PUSH_STRV()/LOG_CONTEXT_PUSH_IOV() except they take ownership of the
+* given str/strv argument.
+*/
+
+#define _LOG_CONTEXT_CONSUME_STR(s, c, strv) \
+        _unused_ _cleanup_strv_free_ strv = strv_new(s);                                                \
+        if (!strv)                                                                                      \
+                free(s);                                                                                \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv_consume(TAKE_PTR(strv))
+
+#define LOG_CONTEXT_CONSUME_STR(s) \
+        _LOG_CONTEXT_CONSUME_STR(s, UNIQ_T(c, UNIQ), UNIQ_T(sv, UNIQ))
+
+#define _LOG_CONTEXT_CONSUME_STRV(strv, c) \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv_consume(strv);
+
+#define LOG_CONTEXT_CONSUME_STRV(strv) \
+        _LOG_CONTEXT_CONSUME_STRV(strv, UNIQ_T(c, UNIQ))
+
+#define _LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec, c) \
+        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_iov_consume(input_iovec, n_input_iovec);
+
+#define LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec) \
+        _LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec, UNIQ_T(c, UNIQ))
index f734a7811ad9d4c3a13cfe5aa34cf648dca6e3df..c244666f1fcbf535c6200b3cca604002e5d19387 100644 (file)
@@ -25,6 +25,7 @@
 #include "format-util.h"
 #include "iovec-util.h"
 #include "log.h"
+#include "log-context.h"
 #include "macro.h"
 #include "missing_syscall.h"
 #include "parse-util.h"
@@ -82,22 +83,6 @@ static bool assert_return_is_critical = BUILD_MODE_DEVELOPER;
  * use here. */
 static char *log_abort_msg = NULL;
 
-typedef struct LogContext {
-        unsigned n_ref;
-        /* Depending on which destructor is used (log_context_free() or log_context_detach()) the memory
-         * referenced by this is freed or not */
-        char **fields;
-        struct iovec *input_iovec;
-        size_t n_input_iovec;
-        char *key;
-        char *value;
-        bool owned;
-        LIST_FIELDS(struct LogContext, ll);
-} LogContext;
-
-static thread_local LIST_HEAD(LogContext, _log_context) = NULL;
-static thread_local size_t _log_context_num_fields = 0;
-
 static thread_local const char *log_prefix = NULL;
 
 #if LOG_MESSAGE_VERIFICATION || defined(__COVERITY__)
@@ -697,7 +682,7 @@ static void log_do_context(struct iovec *iovec, size_t iovec_len, size_t *n) {
         assert(iovec);
         assert(n);
 
-        LIST_FOREACH(ll, c, _log_context) {
+        LIST_FOREACH(ll, c, log_context_head()) {
                 STRV_FOREACH(s, c->fields) {
                         if (*n + 2 >= iovec_len)
                                 return;
@@ -747,7 +732,7 @@ static int write_to_journal(
         if (LOG_PRI(level) > log_target_max_level[LOG_TARGET_JOURNAL])
                 return 0;
 
-        iovec_len = MIN(6 + _log_context_num_fields * 3, IOVEC_MAX);
+        iovec_len = MIN(6 + log_context_num_fields() * 3, IOVEC_MAX);
         iovec = newa(struct iovec, iovec_len);
 
         log_do_header(header, sizeof(header), level, error, file, line, func, object_field, object, extra_field, extra);
@@ -1099,7 +1084,7 @@ int log_struct_internal(
                         int r;
                         bool fallback = false;
 
-                        iovec_len = MIN(17 + _log_context_num_fields * 3, IOVEC_MAX);
+                        iovec_len = MIN(17 + log_context_num_fields() * 3, IOVEC_MAX);
                         iovec = newa(struct iovec, iovec_len);
 
                         /* If the journal is available do structured logging.
@@ -1200,7 +1185,7 @@ int log_struct_iovec_internal(
                 struct iovec *iovec;
                 size_t n = 0, iovec_len;
 
-                iovec_len = MIN(1 + n_input_iovec * 2 + _log_context_num_fields * 3, IOVEC_MAX);
+                iovec_len = MIN(1 + n_input_iovec * 2 + log_context_num_fields() * 3, IOVEC_MAX);
                 iovec = newa(struct iovec, iovec_len);
 
                 log_do_header(header, sizeof(header), level, error, file, line, func, NULL, NULL, NULL, NULL);
@@ -1811,162 +1796,3 @@ const char* _log_set_prefix(const char *prefix, bool force) {
 
         return old;
 }
-
-static int saved_log_context_enabled = -1;
-
-bool log_context_enabled(void) {
-        int r;
-
-        if (log_get_max_level() == LOG_DEBUG)
-                return true;
-
-        if (saved_log_context_enabled >= 0)
-                return saved_log_context_enabled;
-
-        r = secure_getenv_bool("SYSTEMD_ENABLE_LOG_CONTEXT");
-        if (r < 0 && r != -ENXIO)
-                log_debug_errno(r, "Failed to parse $SYSTEMD_ENABLE_LOG_CONTEXT, ignoring: %m");
-
-        saved_log_context_enabled = r > 0;
-
-        return saved_log_context_enabled;
-}
-
-static LogContext* log_context_attach(LogContext *c) {
-        assert(c);
-
-        _log_context_num_fields += strv_length(c->fields);
-        _log_context_num_fields += c->n_input_iovec;
-        _log_context_num_fields += !!c->key;
-
-        return LIST_PREPEND(ll, _log_context, c);
-}
-
-static LogContext* log_context_detach(LogContext *c) {
-        if (!c)
-                return NULL;
-
-        assert(_log_context_num_fields >= strv_length(c->fields) + c->n_input_iovec +!!c->key);
-        _log_context_num_fields -= strv_length(c->fields);
-        _log_context_num_fields -= c->n_input_iovec;
-        _log_context_num_fields -= !!c->key;
-
-        LIST_REMOVE(ll, _log_context, c);
-        return NULL;
-}
-
-LogContext* log_context_new(const char *key, const char *value) {
-        assert(key);
-        assert(endswith(key, "="));
-        assert(value);
-
-        LIST_FOREACH(ll, i, _log_context)
-                if (i->key == key && i->value == value)
-                        return log_context_ref(i);
-
-        LogContext *c = new(LogContext, 1);
-        if (!c)
-                return NULL;
-
-        *c = (LogContext) {
-                .n_ref = 1,
-                .key = (char *) key,
-                .value = (char *) value,
-        };
-
-        return log_context_attach(c);
-}
-
-LogContext* log_context_new_strv(char **fields, bool owned) {
-        if (!fields)
-                return NULL;
-
-        LIST_FOREACH(ll, i, _log_context)
-                if (i->fields == fields) {
-                        assert(!owned);
-                        return log_context_ref(i);
-                }
-
-        LogContext *c = new(LogContext, 1);
-        if (!c)
-                return NULL;
-
-        *c = (LogContext) {
-                .n_ref = 1,
-                .fields = fields,
-                .owned = owned,
-        };
-
-        return log_context_attach(c);
-}
-
-LogContext* log_context_new_iov(struct iovec *input_iovec, size_t n_input_iovec, bool owned) {
-        if (!input_iovec || n_input_iovec == 0)
-                return NULL;
-
-        LIST_FOREACH(ll, i, _log_context)
-                if (i->input_iovec == input_iovec && i->n_input_iovec == n_input_iovec) {
-                        assert(!owned);
-                        return log_context_ref(i);
-                }
-
-        LogContext *c = new(LogContext, 1);
-        if (!c)
-                return NULL;
-
-        *c = (LogContext) {
-                .n_ref = 1,
-                .input_iovec = input_iovec,
-                .n_input_iovec = n_input_iovec,
-                .owned = owned,
-        };
-
-        return log_context_attach(c);
-}
-
-static LogContext* log_context_free(LogContext *c) {
-        if (!c)
-                return NULL;
-
-        log_context_detach(c);
-
-        if (c->owned) {
-                strv_free(c->fields);
-                iovec_array_free(c->input_iovec, c->n_input_iovec);
-                free(c->key);
-                free(c->value);
-        }
-
-        return mfree(c);
-}
-
-DEFINE_TRIVIAL_REF_UNREF_FUNC(LogContext, log_context, log_context_free);
-
-LogContext* log_context_new_strv_consume(char **fields) {
-        LogContext *c = log_context_new_strv(fields, /*owned=*/ true);
-        if (!c)
-                strv_free(fields);
-
-        return c;
-}
-
-LogContext* log_context_new_iov_consume(struct iovec *input_iovec, size_t n_input_iovec) {
-        LogContext *c = log_context_new_iov(input_iovec, n_input_iovec, /*owned=*/ true);
-        if (!c)
-                iovec_array_free(input_iovec, n_input_iovec);
-
-        return c;
-}
-
-size_t log_context_num_contexts(void) {
-        size_t n = 0;
-
-        LIST_FOREACH(ll, c, _log_context)
-                n++;
-
-        return n;
-}
-
-size_t log_context_num_fields(void) {
-        return _log_context_num_fields;
-}
index 3687c8e69bf91536d53c48f586603b2501979595..e6b6a4b4fec060b879143a96043c02763656bfe2 100644 (file)
@@ -411,112 +411,3 @@ static inline const char* _log_unset_prefixp(const char **p) {
 
 #define LOG_SET_PREFIX(prefix) \
         _cleanup_(_log_unset_prefixp) _unused_ const char *CONCATENATE(_cleanup_log_unset_prefix_, UNIQ) = _log_set_prefix(prefix, false);
-
-/*
- * The log context allows attaching extra metadata to log messages written to the journal via log.h. We keep
- * track of a thread local log context onto which we can push extra metadata fields that should be logged.
- *
- * LOG_CONTEXT_PUSH() will add the provided field to the log context and will remove it again when the
- * current block ends. LOG_CONTEXT_PUSH_STRV() will do the same but for all fields in the given strv.
- * LOG_CONTEXT_PUSHF() is like LOG_CONTEXT_PUSH() but takes a format string and arguments.
- *
- * Using the macros is as simple as putting them anywhere inside a block to add a field to all following log
- * messages logged from inside that block.
- *
- * void myfunction(...) {
- *         ...
- *
- *         LOG_CONTEXT_PUSHF("MYMETADATA=%s", "abc");
- *
- *         // Every journal message logged will now have the MYMETADATA=abc
- *         // field included.
- * }
- *
- * One special case to note is async code, where we use callbacks that are invoked to continue processing
- * when some event occurs. For async code, there's usually an associated "userdata" struct containing all the
- * information associated with the async operation. In this "userdata" struct, we can store a log context
- * allocated with log_context_new() and freed with log_context_free(). We can then add and remove fields to
- * the `fields` member of the log context object and all those fields will be logged along with each log
- * message.
- */
-
-typedef struct LogContext LogContext;
-
-bool log_context_enabled(void);
-
-LogContext* log_context_new(const char *key, const char *value);
-LogContext* log_context_new_strv(char **fields, bool owned);
-LogContext* log_context_new_iov(struct iovec *input_iovec, size_t n_input_iovec, bool owned);
-
-/* Same as log_context_new(), but frees the given fields strv/iovec on failure. */
-LogContext* log_context_new_strv_consume(char **fields);
-LogContext* log_context_new_iov_consume(struct iovec *input_iovec, size_t n_input_iovec);
-
-LogContext *log_context_ref(LogContext *c);
-LogContext *log_context_unref(LogContext *c);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(LogContext*, log_context_unref);
-
-/* Returns the number of attached log context objects. */
-size_t log_context_num_contexts(void);
-/* Returns the number of fields in all attached log contexts. */
-size_t log_context_num_fields(void);
-
-static inline void _reset_log_level(int *saved_log_level) {
-        assert(saved_log_level);
-
-        log_set_max_level(*saved_log_level);
-}
-
-#define LOG_CONTEXT_SET_LOG_LEVEL(level) \
-        _cleanup_(_reset_log_level) _unused_ int _saved_log_level_ = log_set_max_level(level);
-
-#define LOG_CONTEXT_PUSH(...) \
-        LOG_CONTEXT_PUSH_STRV(STRV_MAKE(__VA_ARGS__))
-
-#define LOG_CONTEXT_PUSHF(...) \
-        LOG_CONTEXT_PUSH(snprintf_ok((char[LINE_MAX]) {}, LINE_MAX, __VA_ARGS__))
-
-#define _LOG_CONTEXT_PUSH_KEY_VALUE(key, value, c) \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new(key, value);
-
-#define LOG_CONTEXT_PUSH_KEY_VALUE(key, value) \
-        _LOG_CONTEXT_PUSH_KEY_VALUE(key, value, UNIQ_T(c, UNIQ))
-
-#define _LOG_CONTEXT_PUSH_STRV(strv, c) \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv(strv, /*owned=*/ false);
-
-#define LOG_CONTEXT_PUSH_STRV(strv) \
-        _LOG_CONTEXT_PUSH_STRV(strv, UNIQ_T(c, UNIQ))
-
-#define _LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec, c) \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_iov(input_iovec, n_input_iovec, /*owned=*/ false);
-
-#define LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec) \
-        _LOG_CONTEXT_PUSH_IOV(input_iovec, n_input_iovec, UNIQ_T(c, UNIQ))
-
-/* LOG_CONTEXT_CONSUME_STR()/LOG_CONTEXT_CONSUME_STRV()/LOG_CONTEXT_CONSUME_IOV() are identical to
- * LOG_CONTEXT_PUSH_STR()/LOG_CONTEXT_PUSH_STRV()/LOG_CONTEXT_PUSH_IOV() except they take ownership of the
- * given str/strv argument.
- */
-
-#define _LOG_CONTEXT_CONSUME_STR(s, c, strv) \
-        _unused_ _cleanup_strv_free_ strv = strv_new(s);                                                \
-        if (!strv)                                                                                      \
-                free(s);                                                                                \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv_consume(TAKE_PTR(strv))
-
-#define LOG_CONTEXT_CONSUME_STR(s) \
-        _LOG_CONTEXT_CONSUME_STR(s, UNIQ_T(c, UNIQ), UNIQ_T(sv, UNIQ))
-
-#define _LOG_CONTEXT_CONSUME_STRV(strv, c) \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_strv_consume(strv);
-
-#define LOG_CONTEXT_CONSUME_STRV(strv) \
-        _LOG_CONTEXT_CONSUME_STRV(strv, UNIQ_T(c, UNIQ))
-
-#define _LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec, c) \
-        _unused_ _cleanup_(log_context_unrefp) LogContext *c = log_context_new_iov_consume(input_iovec, n_input_iovec);
-
-#define LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec) \
-        _LOG_CONTEXT_CONSUME_IOV(input_iovec, n_input_iovec, UNIQ_T(c, UNIQ))
index 8d0876fc5b7cbb6dbdf0cd2d38771c31016e86f7..c3ca1537b519e292d62b1b139e672fcada7eade1 100644 (file)
@@ -58,6 +58,7 @@ basic_sources = files(
         'locale-util.c',
         'lock-util.c',
         'log.c',
+        'log-context.c',
         'login-util.c',
         'keyring-util.c',
         'memfd-util.c',
index 384641f6a770e207ce3973678fbfcda7f897b234..7e59443415b3e98afe28ab45c06902b65a5c10ac 100644 (file)
@@ -22,6 +22,7 @@ typedef enum UnitMountDependencyType {
 #include "emergency-action.h"
 #include "install.h"
 #include "list.h"
+#include "log-context.h"
 #include "mount-util.h"
 #include "pidref.h"
 #include "unit-file.h"
index 6429267843c95047114aee2ca4b01c57a700d59d..547ed945dc77e03d94351390bba8f27b3a147569 100644 (file)
@@ -36,6 +36,7 @@
 #include "hexdecoct.h"
 #include "hostname-util.h"
 #include "io-util.h"
+#include "log-context.h"
 #include "macro.h"
 #include "memory-util.h"
 #include "missing_syscall.h"
index 1d5fa2c113c31215d62e23a4bff760284f1d77b3..992f531be261ac6d8ab1afcb2b937da04b6ef4b5 100644 (file)
@@ -22,6 +22,7 @@
 #include "hashmap.h"
 #include "io-util.h"
 #include "iovec-util.h"
+#include "log-context.h"
 #include "missing_socket.h"
 #include "mountpoint-util.h"
 #include "set.h"
index a70484eb66276293454028722ad1e548ab34038b..9536cd9846b7d4da6d91a891542fd10e6ea2819a 100644 (file)
@@ -26,6 +26,7 @@
 #include "install.h"
 #include "iovec-util.h"
 #include "locale-util.h"
+#include "log-context.h"
 #include "loop-util.h"
 #include "mkdir.h"
 #include "nulstr-util.h"
index b973ba94274df7518c44dc8bf579088d88550888..3fb08120991f039dbe053187c7733515c6122e6e 100644 (file)
@@ -8,6 +8,7 @@
 #include "iovec-util.h"
 #include "iovec-wrapper.h"
 #include "log.h"
+#include "log-context.h"
 #include "process-util.h"
 #include "string-util.h"
 #include "strv.h"