summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-05-12 05:25:21 +0900
committerGitHub <noreply@github.com>2022-05-12 05:25:21 +0900
commit34f6ae24c5ca7975ed5bd6d47e42bda0e7bf97be (patch)
treed746a1a4101420e602567980626d0a1a17b506f1 /src/core
parent0cfb00d9da8af2387e89f5aa49adfd95b365aa28 (diff)
parent011a03a3fae25f2b715f2d88bc16b4cb8f8f2da2 (diff)
downloadsystemd-34f6ae24c5ca7975ed5bd6d47e42bda0e7bf97be.tar.gz
Merge pull request #23351 from keszybz/logind-message
logind: fix crash in logind on bad message string
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device.c3
-rw-r--r--src/core/job.c14
-rw-r--r--src/core/service.c3
-rw-r--r--src/core/transaction.c19
-rw-r--r--src/core/unit.h3
5 files changed, 23 insertions, 19 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 4885fa9295..44425cda3c 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -493,7 +493,8 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
LOG_WARNING, r,
"MESSAGE_ID=" SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE_STR,
"DEVICE=%s", path,
- LOG_MESSAGE("Failed to generate valid unit name from device path '%s', ignoring device: %m", path));
+ LOG_MESSAGE("Failed to generate valid unit name from device path '%s', ignoring device: %m",
+ path));
u = manager_get_unit(m, e);
if (u) {
diff --git a/src/core/job.c b/src/core/job.c
index 94ab381626..36d6f0a456 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -716,8 +716,8 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult
log_unit_struct(
u,
job_done_messages[result].log_level,
- "MESSAGE=%s was skipped because all trigger condition checks failed.",
- ident,
+ LOG_MESSAGE("%s was skipped because all trigger condition checks failed.",
+ ident),
"JOB_ID=%" PRIu32, job_id,
"JOB_TYPE=%s", job_type_to_string(t),
"JOB_RESULT=%s", job_result_to_string(result),
@@ -727,11 +727,11 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult
log_unit_struct(
u,
job_done_messages[result].log_level,
- "MESSAGE=%s was skipped because of a failed condition check (%s=%s%s).",
- ident,
- condition_type_to_string(c->type),
- c->negate ? "!" : "",
- c->parameter,
+ LOG_MESSAGE("%s was skipped because of a failed condition check (%s=%s%s).",
+ ident,
+ condition_type_to_string(c->type),
+ c->negate ? "!" : "",
+ c->parameter),
"JOB_ID=%" PRIu32, job_id,
"JOB_TYPE=%s", job_type_to_string(t),
"JOB_RESULT=%s", job_result_to_string(result),
diff --git a/src/core/service.c b/src/core/service.c
index 2d7a086852..9f7af9dffb 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -2365,7 +2365,8 @@ static void service_enter_restart(Service *s) {
log_unit_struct(UNIT(s), LOG_INFO,
"MESSAGE_ID=" SD_MESSAGE_UNIT_RESTART_SCHEDULED_STR,
LOG_UNIT_INVOCATION_ID(UNIT(s)),
- LOG_UNIT_MESSAGE(UNIT(s), "Scheduled restart job, restart counter is at %u.", s->n_restarts),
+ LOG_UNIT_MESSAGE(UNIT(s),
+ "Scheduled restart job, restart counter is at %u.", s->n_restarts),
"N_RESTARTS=%u", s->n_restarts);
/* Notify clients about changed restart counter */
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 7bb8dfb0f4..bafbb80b47 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -390,19 +390,20 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
STRV_FOREACH_PAIR(unit_id, job_type, array)
/* logging for j not k here to provide a consistent narrative */
log_struct(LOG_WARNING,
- "MESSAGE=%s: Found %s on %s/%s",
- j->unit->id,
- unit_id == array ? "ordering cycle" : "dependency",
- *unit_id, *job_type,
+ LOG_UNIT_MESSAGE(j->unit,
+ "Found %s on %s/%s",
+ unit_id == array ? "ordering cycle" : "dependency",
+ *unit_id, *job_type),
"%s", unit_ids);
if (delete) {
const char *status;
/* logging for j not k here to provide a consistent narrative */
log_struct(LOG_ERR,
- "MESSAGE=%s: Job %s/%s deleted to break ordering cycle starting with %s/%s",
- j->unit->id, delete->unit->id, job_type_to_string(delete->type),
- j->unit->id, job_type_to_string(j->type),
+ LOG_UNIT_MESSAGE(j->unit,
+ "Job %s/%s deleted to break ordering cycle starting with %s/%s",
+ delete->unit->id, job_type_to_string(delete->type),
+ j->unit->id, job_type_to_string(j->type)),
"%s", unit_ids);
if (log_get_show_color())
@@ -420,8 +421,8 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
}
log_struct(LOG_ERR,
- "MESSAGE=%s: Unable to break cycle starting with %s/%s",
- j->unit->id, j->unit->id, job_type_to_string(j->type),
+ LOG_UNIT_MESSAGE(j->unit, "Unable to break cycle starting with %s/%s",
+ j->unit->id, job_type_to_string(j->type)),
"%s", unit_ids);
return sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC,
diff --git a/src/core/unit.h b/src/core/unit.h
index 733eeecd7f..20c511c108 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -1046,7 +1046,8 @@ Condition *unit_find_failed_condition(Unit *u);
#define log_unit_struct_iovec(unit, level, iovec, n_iovec) log_unit_struct_iovec_errno(unit, level, 0, iovec, n_iovec)
-#define LOG_UNIT_MESSAGE(unit, fmt, ...) "MESSAGE=%s: " fmt, (unit)->id, ##__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) (unit)->manager->unit_log_format_string, (unit)->id
#define LOG_UNIT_INVOCATION_ID(unit) (unit)->manager->invocation_log_format_string, (unit)->invocation_id_string