summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-21 00:42:30 +0900
committerGitHub <noreply@github.com>2023-03-21 00:42:30 +0900
commit719bbb365bd22410f743ae900d42ffe6ea9edeb4 (patch)
treebcf89a9927cc308bab69e593e94c19b852660103
parent00546c18fd2555e6140f17b307c45ac487e0c5ad (diff)
parent5803c24da5cf543a55c4fce9009a9c5f2b18519a (diff)
downloadsystemd-719bbb365bd22410f743ae900d42ffe6ea9edeb4.tar.gz
Merge pull request #26875 from yuwata/core-transaction
core/transaction: several fixes for merge_unit_ids()
-rw-r--r--src/core/transaction.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 7d0e1ecc5e..059558ebc0 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -323,22 +323,28 @@ _pure_ static bool unit_matters_to_anchor(Unit *u, Job *job) {
return false;
}
-static char* merge_unit_ids(const char* unit_log_field, char **pairs) {
- char *ans = NULL;
- size_t size = 0, next;
+static char* merge_unit_ids(const char* unit_log_field, char * const* pairs) {
+ _cleanup_free_ char *ans = NULL;
+ size_t size = 0;
STRV_FOREACH_PAIR(unit_id, job_type, pairs) {
+ size_t next;
+
+ if (size > 0)
+ ans[size - 1] = '\n';
+
next = strlen(unit_log_field) + strlen(*unit_id);
if (!GREEDY_REALLOC(ans, size + next + 1))
- return mfree(ans);
+ return NULL;
sprintf(ans + size, "%s%s", unit_log_field, *unit_id);
- if (*(unit_id+1))
- ans[size + next] = '\n';
size += next + 1;
}
- return ans;
+ if (!ans)
+ return strdup("");
+
+ return TAKE_PTR(ans);
}
static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsigned generation, sd_bus_error *e) {
@@ -394,7 +400,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
"Found %s on %s/%s",
unit_id == array ? "ordering cycle" : "dependency",
*unit_id, *job_type),
- "%s", unit_ids);
+ "%s", strna(unit_ids));
if (delete) {
const char *status;
@@ -404,7 +410,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
"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);
+ "%s", strna(unit_ids));
if (log_get_show_color())
status = ANSI_HIGHLIGHT_RED " SKIP " ANSI_NORMAL;
@@ -423,7 +429,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
log_struct(LOG_ERR,
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);
+ "%s", strna(unit_ids));
return sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC,
"Transaction order is cyclic. See system logs for details.");