_printf_(7, 8)
static int log_helper(void *userdata, int level, int error, const char *file, int line, const char *func, const char *format, ...) {
Unit *u = ASSERT_PTR(userdata);
- Manager *m = ASSERT_PTR(u->manager);
va_list ap;
int r;
va_start(ap, format);
r = log_object_internalv(level, error, file, line, func,
- /* object_field = */ m->unit_log_field,
+ /* object_field = */ unit_log_field(u),
/* object = */ u->id,
/* extra_field = */ NULL,
/* extra = */ NULL,
m->timestamps + MANAGER_TIMESTAMP_LOADER);
#endif
- /* Prepare log fields we can use for structured logging */
- if (MANAGER_IS_SYSTEM(m)) {
- m->unit_log_field = "UNIT=";
- m->invocation_log_field = "INVOCATION_ID=";
- } else {
- m->unit_log_field = "USER_UNIT=";
- m->invocation_log_field = "USER_INVOCATION_ID=";
- }
-
/* Reboot immediately if the user hits C-A-D more often than 7x per 2s */
m->ctrl_alt_del_ratelimit = (const RateLimit) { .interval = 2 * USEC_PER_SEC, .burst = 7 };
RateLimit ctrl_alt_del_ratelimit;
EmergencyAction cad_burst_action;
- const char *unit_log_field;
- const char *invocation_log_field;
-
int first_boot; /* tri-state */
/* Prefixes of e.g. RuntimeDirectory= */
break;
}
- unit_ids = merge_unit_ids(j->manager->unit_log_field, array); /* ignore error */
+ unit_ids = merge_unit_ids(unit_log_field(j->unit), array); /* ignore error */
STRV_FOREACH_PAIR(unit_id, job_type, array)
/* logging for j not k here to provide a consistent narrative */
va_start(ap, format);
if (u)
r = log_object_internalv(level, error, file, line, func,
- u->manager->unit_log_field,
+ unit_log_field(u),
u->id,
- u->manager->invocation_log_field,
+ unit_invocation_log_field(u),
u->invocation_id_string,
format, ap);
else
if (!set_iovec_string_field(iovec, &n_iovec, "MESSAGE_ID=", SD_MESSAGE_UNIT_RESOURCES_STR))
return log_oom();
- if (!set_iovec_string_field(iovec, &n_iovec, u->manager->unit_log_field, u->id))
+ if (!set_iovec_string_field(iovec, &n_iovec, unit_log_field(u), u->id))
return log_oom();
- if (!set_iovec_string_field(iovec, &n_iovec, u->manager->invocation_log_field, u->invocation_id_string))
+ if (!set_iovec_string_field(iovec, &n_iovec, unit_invocation_log_field(u), u->invocation_id_string))
return log_oom();
log_unit_struct_iovec(u, log_level, iovec, n_iovec);
return strcmp(a->id, b->id);
}
+const char* unit_log_field(const Unit *u) {
+ return MANAGER_IS_SYSTEM(ASSERT_PTR(u)->manager) ? "UNIT=" : "USER_UNIT=";
+}
+
+const char* unit_invocation_log_field(const Unit *u) {
+ return MANAGER_IS_SYSTEM(ASSERT_PTR(u)->manager) ? "INVOCATION_ID=" : "USER_INVOCATION_ID=";
+}
+
const ActivationDetailsVTable * const activation_details_vtable[_UNIT_TYPE_MAX] = {
[UNIT_PATH] = &activation_details_path_vtable,
[UNIT_TIMER] = &activation_details_timer_vtable,
int unit_compare_priority(Unit *a, Unit *b);
+const char* unit_log_field(const Unit *u);
+const char* unit_invocation_log_field(const Unit *u);
+
UnitMountDependencyType unit_mount_dependency_type_from_string(const char *s) _const_;
const char* unit_mount_dependency_type_to_string(UnitMountDependencyType t) _const_;
UnitDependency unit_mount_dependency_type_to_dependency_type(UnitMountDependencyType t) _pure_;
LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
_c ? _c->n_log_extra_fields : 0); \
!_do_log ? -ERRNO_VALUE(error) : \
- _u ? log_object_internal(_l, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \
+ _u ? log_object_internal(_l, error, PROJECT_FILE, __LINE__, __func__, unit_log_field(_u), _u->id, unit_invocation_log_field(_u), _u->invocation_id_string, ##__VA_ARGS__) : \
log_internal(_l, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
})
/* Like LOG_MESSAGE(), but with the unit name prefixed. */
#define LOG_UNIT_MESSAGE(unit, fmt, ...) LOG_MESSAGE("%s: " fmt, (unit)->id, ##__VA_ARGS__)
-#define LOG_UNIT_ID(unit) LOG_ITEM("%s%s", (unit)->manager->unit_log_field, (unit)->id)
-#define LOG_UNIT_INVOCATION_ID(unit) LOG_ITEM("%s%s", (unit)->manager->invocation_log_field, (unit)->invocation_id_string)
+#define LOG_UNIT_ID(unit) LOG_ITEM("%s%s", unit_log_field((unit)), (unit)->id)
+#define LOG_UNIT_INVOCATION_ID(unit) LOG_ITEM("%s%s", unit_invocation_log_field((unit)), (unit)->invocation_id_string)
const char* collect_mode_to_string(CollectMode m) _const_;
CollectMode collect_mode_from_string(const char *s) _pure_;
#define _LOG_CONTEXT_PUSH_UNIT(unit, u, c) \
const Unit *u = (unit); \
const ExecContext *c = unit_get_exec_context(u); \
- LOG_CONTEXT_PUSH_KEY_VALUE(u->manager->unit_log_field, u->id); \
- LOG_CONTEXT_PUSH_KEY_VALUE(u->manager->invocation_log_field, u->invocation_id_string); \
+ LOG_CONTEXT_PUSH_KEY_VALUE(unit_log_field(u), u->id); \
+ LOG_CONTEXT_PUSH_KEY_VALUE(unit_invocation_log_field(u), u->invocation_id_string); \
LOG_CONTEXT_PUSH_IOV(c ? c->log_extra_fields : NULL, c ? c->n_log_extra_fields : 0); \
LOG_CONTEXT_SET_LOG_LEVEL(c->log_level_max >= 0 ? c->log_level_max : log_get_max_level())