Skip to content

core: add method to enqueue multiple jobs in a single call - #42182

Merged
bluca merged 4 commits into
systemd:mainfrom
bluca:single-tx-jobs
Jun 22, 2026
Merged

bluca merged 4 commits into
systemd:mainfrom
bluca:single-tx-jobs

Conversation

@bluca

@bluca bluca commented May 19, 2026

Copy link
Copy Markdown
Member

Currently only a single job for a single unit can be enqueued atomically,
so there is no guarantee that, e.g., starting a unit and its socket
at the same time will happen in the same transaction. That forces
callers to 'know' the right order in which to start new units being
installed, or failures will occur. It also means some ordering
constraints are ignored, in case the separate calls are done
in the wrong manual order.

Add a new EnqueueUnitsJobs() D-Bus method that takes a list of units
to start.

@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown

Claude review of PR #42182 (7034441)

Must fix

  • Assertion failure in manager_propagate_reload — src/core/manager.c:2542 — tr->anchor_jobs not cleared before transaction_free(), which now asserts the set is empty
  • Missing error log on transaction failure — src/systemctl/systemctl-start-unit.c:511 — user sees non-zero exit with no error message when start_units_one_transaction() fails
  • set_move failure causes assertion crash in manager_add_jobs — src/core/manager.c:2375 — if set_move OOMs after transaction_activate, cleanup hits assert(set_isempty(tr->anchor_jobs))
  • Duplicate unit names cause set_put failure — src/core/transaction.c:1057 — if same unit name appears twice in input array, set_put returns -EEXIST and the call fails unexpectedly

Suggestions

  • Dangling pointer risk in anchor_jobs update — src/core/transaction.c:707 — silent void cast of set_remove_and_put hides -EEXIST case that could leave freed pointer in set
  • Isolate mode not excluded from batch path (dismissed)
  • Unchecked sd_bus_message_exit_container — src/portable/portablectl.c:786 — inconsistent with enter_container error handling in same function
  • mktemp -u TOCTOU race in test — test was rewritten
  • Masked unit handling regression in batch path — src/systemctl/systemctl-start-unit.c:512 — masked units during try-restart may cause hard failure instead of silent skip; more broadly the atomic batch turns long-standing best-effort multi-unit start/stop (where a bad unit still let the good ones proceed) into all-or-nothing
  • Error from batch operation silently ignored in portablectl detach — src/portable/portablectl.c:1070 — error checking now added
  • Fragile error assertion pattern in test — test/units/TEST-07-PID1.multi-units-transaction.sh:167 — rewritten to use robust capture-and-check pattern
  • INVALID_ARGS fallback too broad — src/systemctl/systemctl-start-unit.c:506 — genuine argument bugs silently masked by fallback to per-unit calls
  • No input size limit on EnqueueUnitsJobs — src/core/dbus-manager.c:869 — no cap on names array unlike other bulk methods
  • Redundant path_extract_filename in portablectl fallback — src/portable/portablectl.c:804 — names already extracted, re-extraction is a no-op allocation
  • Missing per-unit SELinux check in EnqueueUnitsJobs — src/core/dbus-manager.c:900 — generic manager-level MAC check instead of per-unit, unlike method_enqueue_marked_jobs
  • stopped_units pushed unconditionally in batch path — src/systemctl/systemctl-start-unit.c:498 — all names added regardless of which units actually got stop jobs
  • need_daemon_reload() N round-trips in batch reply — src/systemctl/systemctl-start-unit.c:248 — synchronous D-Bus property read per job in reply loop; consider deferring or batching
  • transaction_is_destructive OOM returns raw errno — src/core/transaction.c:574 — returns -ENOMEM instead of bus error, inconsistent with surrounding error pattern
  • manager_add_jobs duplicates manager_add_job_full — src/core/manager.c:2270 — near-identical transaction-building body; consider making the single-unit path a thin wrapper
  • Over-broad INVALID_ARGS fallback in portablectl — src/portable/portablectl.c:793 — same over-broad feature detection as systemctl; key fallback on UNKNOWN_METHOD only
  • maybe_stop_disable_clean aborts detach on stop error — src/portable/portablectl.c:1064 — a real stop error now skips disable+wait+clean, leaving the image half-detached
  • Missing job-sender tracking in EnqueueUnitsJobs — src/core/dbus-manager.c:921 — unlike the single-unit path, anchor jobs are not tracked against the caller (bus_job_track_sender), so jobs for gc-eligible units (e.g. device units) may become garbage-collectable

Nits

  • transaction.h include widens include graph (dismissed)
  • Unnecessary cast (char) names** — src/systemctl/systemctl-start-unit.c:214 — strv_length() already accepts char * const *
  • sleep 3 makes test slow — test/units/TEST-07-PID1.issue-8102.sh:46 — ordering guarantee doesn't depend on sleep duration
  • Log message inconsistency — src/portable/portablectl.c:776 — batch path logs job type while fallback logs D-Bus method name
  • SET_FOREACH non-deterministic order in response — src/core/dbus-manager.c:925 — response array order does not match request order
  • strv_length for > 1 check — src/systemctl/systemctl-start-unit.c:491 — full traversal where names[0] && names[1] suffices
  • Unnecessary sleep in test error assertions — test/units/TEST-07-PID1.multi-units-transaction.sh:226 — synchronous busctl call makes post-sleep redundant
  • Unnecessary casts in manager_add_jobs — src/core/manager.c:2284 — strv_isempty and strv_length already accept char * const *
  • Busctl reply leaked to stdout — test/units/TEST-07-PID1.multi-units-transaction.sh:143 — missing >/dev/null unlike other successful busctl calls in file
  • Disable-before-stop ordering change — src/portable/portablectl.c:1052 — units are now disabled before being stopped, reversing the idiomatic lifecycle order
  • ret_jobs parameter misnamed — src/core/manager.c:2279 — caller-preallocated in/out Set should not carry the ret_ prefix
  • Brace inconsistency in fallback if-chain (dismissed) — src/systemctl/systemctl-start-unit.c:511 — first branch unbraced while the rest of the chain is braced

Workflow run

@github-actions github-actions Bot added documentation systemctl tests portable Anything to do with systemd-portable and portablectl and portables please-review PR is ready for (re-)review by a maintainer labels May 19, 2026
Comment thread src/core/manager.c Resolved
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread src/core/transaction.c Resolved
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread src/portable/portablectl.c Resolved
Comment thread test/units/TEST-07-PID1.issue-8102.sh Resolved
Comment thread src/core/manager.h Resolved
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread test/units/TEST-07-PID1.issue-8102.sh Resolved
Comment thread src/portable/portablectl.c Resolved
@bluca
bluca force-pushed the single-tx-jobs branch from bec8a90 to e417674 Compare May 19, 2026 19:04
@bluca bluca linked an issue May 19, 2026 that may be closed by this pull request
Comment thread src/core/manager.c Resolved
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread src/portable/portablectl.c Resolved
Comment thread src/core/dbus-manager.c Resolved
@bluca
bluca force-pushed the single-tx-jobs branch from e417674 to 72968ad Compare May 19, 2026 19:47
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/portable/portablectl.c Resolved
Comment thread src/systemctl/systemctl-start-unit.c Resolved
Comment thread src/core/dbus-manager.c Resolved
@poettering

Copy link
Copy Markdown
Member

needs rebase

Comment thread man/org.freedesktop.systemd1.xml Resolved
* path; preserve that by falling back so each unit is evaluated
* individually. */
log_debug_errno(r, "Batched %s aborted due to masked unit (%s), falling back to per-unit calls.",
method, bus_error_message(&error, r));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually we should probably have a flag to make the call fail in this case, one day

Comment thread src/systemctl/systemctl-start-unit.c Resolved
@poettering

Copy link
Copy Markdown
Member

need rebase.

@poettering

Copy link
Copy Markdown
Member

lgtm

@poettering poettering removed the please-review PR is ready for (re-)review by a maintainer label Jun 22, 2026
@poettering

Copy link
Copy Markdown
Member

so i guess this isn't even a compat breakage, right? because you fall back to the one-by-one thing when the combined transaction failed? because i was about to suggest this should already have a NEWS entry announcing the compat break... but i guess we don't need that then

@poettering

Copy link
Copy Markdown
Member

hmm, can you update the "systemctl start" man page entry a tiny bit, and explain how this works now?

also, maybe then add "Replaces: #7877" and close it, once you added that

Currently only a single job for a single unit can be enqueued atomically,
so there is no guarantee that, e.g., starting a unit and its socket
at the same time will happen in the same transaction. That forces
callers to 'know' the right order in which to start new units being
installed, or failures will occur. It also means some ordering
constraints are ignored, in case the separate calls are done
in the wrong manual order.

Add a new EnqueueUnitJobMany() D-Bus method that takes a list of units
to start.

Fixes systemd#8102

Co-authored-by: Michal Koutný <[email protected]>
@bluca

bluca commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

so i guess this isn't even a compat breakage, right? because you fall back to the one-by-one thing when the combined transaction failed? because i was about to suggest this should already have a NEWS entry announcing the compat break... but i guess we don't need that then

It falls back in some cases, like the method is not available, but not for all cases. I can change that if you prefer?

@poettering

Copy link
Copy Markdown
Member

It falls back in some cases, like the method is not available, but not for all cases. I can change that if you prefer?

no i think i like it, because it reduces the compat problem a bit

Comment thread man/systemctl.xml Resolved
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Jun 22, 2026
@bluca
bluca merged commit 32a162d into systemd:main Jun 22, 2026
48 of 54 checks passed
@bluca
bluca deleted the single-tx-jobs branch June 22, 2026 20:35
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-review documentation downstream/azure portable Anything to do with systemd-portable and portablectl and portables systemctl tests

Development

Successfully merging this pull request may close these issues.

pid1: accept single transaction to operate multiple units man: systemctl doesn't start/stop multiple units in single transaction

3 participants