From d7bc1e3be9758395f7a119138b5bba79aaba70c8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 31 Dec 2025 19:21:13 +0100 Subject: [PATCH 1/3] core/exec-invoke: use RET_NERRNO to avoid clobbering errno Follow-up for 72ce1046e8aa872af8edcfba407e6f0489662fda string_table_lookup_to_string_fallback() might interfere with errno, hence store it in r first. --- src/core/exec-invoke.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index cf47d996b2..34b03f366e 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -5471,17 +5471,14 @@ int exec_invoke( .sched_flags = context->cpu_sched_reset_on_fork ? SCHED_FLAG_RESET_ON_FORK : 0, }; - r = sched_setattr(/* pid= */ 0, &attr, /* flags= */ 0); - if (r < 0) { - if (errno != EINVAL || sched_policy_supported(attr.sched_policy)) { - *exit_status = EXIT_SETSCHEDULER; - return log_error_errno(errno, "Failed to set up CPU scheduling: %m"); - } - + r = RET_NERRNO(sched_setattr(/* pid= */ 0, &attr, /* flags= */ 0)); + if (r == -EINVAL && !sched_policy_supported(context->cpu_sched_policy)) { _cleanup_free_ char *s = NULL; (void) sched_policy_to_string_alloc(context->cpu_sched_policy, &s); - - log_warning_errno(errno, "CPU scheduling policy %s is not supported, proceeding without.", strna(s)); + log_warning_errno(r, "CPU scheduling policy %s is not supported, proceeding without.", strna(s)); + } else if (r < 0) { + *exit_status = EXIT_SETSCHEDULER; + return log_error_errno(r, "Failed to set up CPU scheduling: %m"); } } From 271690624680e9672aa939e3c4f9ed20884196c5 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 18 Dec 2025 20:12:16 +0100 Subject: [PATCH 2/3] core/unit: do not check for unreachable job type Refer to 7cb0030f6cec6c0a83c7c11ecc4adfb55aaf0e0b for the rationale. --- src/core/unit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 4287179903..3fefa519fb 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3927,8 +3927,7 @@ bool unit_active_or_pending(Unit *u) { if (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) return true; - if (u->job && - IN_SET(u->job->type, JOB_START, JOB_RELOAD_OR_START, JOB_RESTART)) + if (u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART)) return true; return false; From 8e92910b980ebf33c32aa11e8e07db968379fe82 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Wed, 26 Nov 2025 11:38:34 +0100 Subject: [PATCH 3/3] core/transaction: when isolating, keep triggered units only if their triggers are actually active Follow-up for 32d6707dd1692d41e12f5469dfdcbc10f14d6619. Co-authored-by: Mike Yuan --- src/core/transaction.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/core/transaction.c b/src/core/transaction.c index 59c7f8c97f..90cc8ee41f 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -1178,6 +1178,28 @@ static bool shall_stop_on_isolate(Transaction *tr, Unit *u) { if (hashmap_contains(tr->jobs, u)) return false; + /* Keep units that are triggered by units we want to keep around. */ + Unit *other; + UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_TRIGGERED_BY) { + if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) + continue; + + /* Is the trigger about to go down? */ + Job *other_job = hashmap_get(tr->jobs, other); + + bool has_stop = false; + LIST_FOREACH(transaction, j, other_job) + if (j->type == JOB_STOP) { + has_stop = true; + break; + } + if (has_stop) + continue; + + if (other->ignore_on_isolate || other_job) + return false; + } + return true; } @@ -1191,7 +1213,6 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { HASHMAP_FOREACH_KEY(u, k, m->units) { _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL; - Unit *o; /* Ignore aliases. */ if (u->id != k) @@ -1204,16 +1225,6 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { if (!shall_stop_on_isolate(tr, u)) continue; - /* Keep units that are triggered by units we want to keep around. */ - bool keep = false; - UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY) - if (!shall_stop_on_isolate(tr, o)) { - keep = true; - break; - } - if (keep) - continue; - r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, TRANSACTION_MATTERS, &e); if (r < 0) log_unit_warning_errno(u, r, "Cannot add isolate job, ignoring: %s", bus_error_message(&e, r));