Commit Graph
87762 Commits
Author SHA1 Message Date
Michael Vogt d1d72563e0 logind: add io.systemd.Shutdown varlink Shutdown interface
The shutdown interface is currently only exposed via dbus. This commit
adds a comparable varlink implementation. It is inspired by the existing
dbus methods and implements PowerOff, Reboot, Halt, Kexec, SoftReboot.

It is (intentional) simpler than the dbus for now, i.e. strictly root
only. To match dbus we will need to the functionality
of verify_shutdown_creds() which is dbus-ish right now and would
need some refactor.

For the same reason it does not do the Can* methods - we will need
the verify_shutdown_creds() equivalent first.
2026-04-07 20:38:40 +02:00
Michael Vogt c2283986f9 logind: move reset_scheduled_shutdown() to new logind-shutdown.c
This function operates on generic Manager state and will be needed
by the varlink shutdown interface too. Move it out of logind-dbus.c
into a new logind-shutdown.c, alongside the SHUTDOWN_SCHEDULE_FILE
define and use `manager_reset_scheduled_shutdown() as the new
name.
2026-04-07 20:06:53 +02:00
noxiouz 874fbb870c coredumpctl: use loop_write() for dumping inline journal coredumps
Replace the bare write() call with loop_write(), which handles short
writes and EINTR retries. This also drops the now-unnecessary ssize_t
variable and the redundant r = log_error_errno(r, ...) self-assignment,
since loop_write() already stores its result in r.

Co-developed-by: Codex (GPT-5) <noreply@openai.com>
2026-04-07 17:56:36 +01:00
Zbigniew Jędrzejewski-Szmek 388428f9d8 Another batch of option/verb conversions (#41532)
Partially generated with Claude but then edited to fix conversions
errors.
2026-04-07 16:13:31 +02:00
LevitatingBusinessMan (Rein Fernhout) 0c510671f8 oci-registry: use overrideRegistry in fedora default
In registry.fedora.oci-registry use overrideRegistry instead of defaultRegistry.

fixes #41518
2026-04-07 13:52:47 +01:00
Daan De Meyer e4f535fdca vmspawn: Always enable CXL on supported architectures
Drop the --cxl= option and unconditionally enable cxl=on the QEMU
machine type whenever the host architecture supports it (x86_64 and
aarch64). The flag was only added for testing parity with mkosi's CXL=
setting and there is no reason to leave it as an opt-in toggle: with no
pxb-cxl device or cxl-fmw window attached, enabling it on the machine
only reserves a small MMIO region and emits an empty CEDT, so the cost
is negligible while removing one knob users would otherwise have to
flip explicitly to exercise the CXL code paths in QEMU.
2026-04-07 12:47:31 +02:00
Zbigniew Jędrzejewski-Szmek 54a0317f97 repart: fix option spelling and file path in comments and manpage (#41534)
Two minor fixes in comments and documentation:

 - Update comment that mentions file renamed in 211d2f972d
 - Do not reference `SizeMin=` where `SizeMinBytes=` is meant

No functional changes.
2026-04-07 11:42:25 +02:00
noxiouz 6e76281b2f journald-native: fix field-count limit off-by-one
Reject entries once the configured maximum field count is reached.

The previous check used n > ENTRY_FIELD_COUNT_MAX before appending a new field,
which let one extra field through in boundary cases. Switch the check to
n >= ENTRY_FIELD_COUNT_MAX so an entry at the limit is rejected before adding
another property.

Co-developed-by: Codex (GPT-5) <noreply@openai.com>
2026-04-07 11:22:45 +02:00
Jonas Rebmann 07745c222c repart: Do not refer to SizeMinBytes= as SizeMin=
No SizeMin= option exists for repart.d; it seems that SizeMinBytes= was
intended.

Update all references accordingly.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
2026-04-07 11:15:54 +02:00
Jonas Rebmann 3d67b5a084 test-specifier: update comment to moved file
src/partition/repart.c was renamed to src/repart/repart.c in commit
211d2f972d ("Rename src/partition to src/repart"), update the comment
accordingly.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
2026-04-07 11:03:48 +02:00
Zbigniew Jędrzejewski-Szmek 88aa9672b9 boot-check-no-failures: convert to the new option parser
--help is identical except for whitespace changes.
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek c074adda05 battery-check: convert to the new option parser
--help is identical except for whitespace changes.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek 3ec64fa2ba updatectl: convert to the new option and verb parsers
Cosmetic differences in --help only.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek 358827d09e tpm2-setup: convert to the new option parser
--help is identical except for whitespace changes.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek 3ed2abf287 tpm2-clear: convert to the new option parser
--help is identical except for whitespace changes.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek 35d7a0f047 test-offline-passwd: convert to the new option parser
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek e106ebbcab sysusers: convert to the new option parser
Cosmetic differences in --help only.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek 386dc2175d tmpfiles: convert to the new option parser
The --image fallthrough into -E is replaced by duplicating the
exclude_default_prefixes() call inline.

Cosmetic differences in --help only.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:53 +02:00
Zbigniew Jędrzejewski-Szmek fd5c19e8d0 varlinkctl: convert to the new verb macros
The description of --exec is moved to a separate footer. It requires
special formatting and doesn't fit in the autogenerated table of
verbs.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:52 +02:00
Zbigniew Jędrzejewski-Szmek e1eae0cf78 varlinkctl: convert to the new option parser
The -E short option previously used fallthrough into the --more case;
since macro-generated case labels don't support fallthrough (with some
older compilers), the --more logic is now duplicated inline in the -E
handler.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:52 +02:00
Zbigniew Jędrzejewski-Szmek e3d25c82ab imdsd: convert to the new option parser
Previously -w was ambiguously described in --help as taking an argument,
but it is in fact an argumentless alias for --wait=yes.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:52 +02:00
Zbigniew Jędrzejewski-Szmek e59fea0088 shared/options: quote the metavar in --help output
imdsd uses --extra-header='NAME: VALUE'. We could include the quotes
in the metavar string, but I think it's nicer to only do that in the
printed output, so that later, when we add introspection, the value
there will not include the quotes.
2026-04-07 10:55:52 +02:00
Zbigniew Jędrzejewski-Szmek 6adc9abc4a imds: convert to the new option parser
Cosmetic changes in --help output only.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 10:55:52 +02:00
Christian Brauner ea8439e1cf Two small fixes (#41506) 2026-04-07 09:11:07 +02:00
Christian Brauner 1025ca530b sd-json, ssh-proxy: two bugfixes (#41529)
- Fix sd_json_variant_unsigned() dispatching to the wrong accessor
    for json variant references.
  - Fix a use-after-free of a borrowed varlink reply reference in
    ssh-proxy.
2026-04-07 08:53:36 +02:00
Christian Brauner 7ed34c0498 vmspawn: use machine name in runtime directory path (#41530)
Replace the random hex suffix in the runtime directory with the machine
name, changing the layout from /run/systemd/vmspawn.<random> to
/run/systemd/vmspawn/<machine-name>/.

This makes runtime directories machine-discoverable from the filesystem
and groups all vmspawn instances under a shared parent directory,
similar to how nspawn uses /run/systemd/nspawn/.

Use runtime_directory_generic() instead of runtime_directory() since
vmspawn is not a service with RuntimeDirectory= set and the
$RUNTIME_DIRECTORY check in the latter never succeeds. The directory is
always created by vmspawn itself and cleaned up via
rm_rf_physical_and_freep on exit. The parent vmspawn/ directory is
intentionally left behind as a shared namespace.
2026-04-07 00:23:19 +02:00
Christian Brauner ccecae0efd vmspawn: use machine name in runtime directory path
Replace the random hex suffix in the runtime directory with the machine
name, changing the layout from /run/systemd/vmspawn.<random> to
/run/systemd/vmspawn/<machine-name>/.

This makes runtime directories machine-discoverable from the filesystem
and groups all vmspawn instances under a shared parent directory, similar
to how nspawn uses /run/systemd/nspawn/.

Use runtime_directory_generic() instead of runtime_directory() since
vmspawn is not a service with RuntimeDirectory= set and the
$RUNTIME_DIRECTORY check in the latter never succeeds. The directory is
always created by vmspawn itself and cleaned up via
rm_rf_physical_and_freep on exit. The parent vmspawn/ directory is
intentionally left behind as a shared namespace.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 22:09:55 +02:00
Christian Brauner 5b5423efa3 sd-json: fix sd_json_variant_unsigned() dispatching to wrong accessor for references
sd_json_variant_unsigned() incorrectly calls sd_json_variant_integer()
for reference-type variants instead of recursing to itself. This silently
returns 0 for unsigned values in the range INT64_MAX+1 through
UINT64_MAX, since sd_json_variant_integer() cannot represent them.

The sibling functions sd_json_variant_integer() and
sd_json_variant_real() correctly recurse to themselves.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 22:02:54 +02:00
Christian Brauner 26a9ed9559 ssh-proxy: fix use-after-free of borrowed varlink reply reference
sd_varlink_call_full() returns borrowed references into the varlink
connection's receive buffer (v->current). fetch_machine() stored this
borrowed reference with _cleanup_(sd_json_variant_unrefp), which would
unref it on error paths -- potentially freeing the parent object while
the varlink connection still owns it. On success, TAKE_PTR passed the
raw borrowed pointer to the caller, but the varlink connection (and its
receive buffer) is freed when fetch_machine returns, leaving the caller
with a dangling pointer.

Fix by removing the cleanup attribute (the reference is borrowed, not
owned) and taking a real ref via sd_json_variant_ref() before returning
to the caller, so the data survives the varlink connection's cleanup.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 22:02:51 +02:00
Christian Brauner 454d9c1be1 shared: introduce MachineRegistrationContext to track bus and registration state
Bundle scope, buses, and registration success booleans into a
MachineRegistrationContext struct. This eliminates the reterr_registered_system and
reterr_registered_user output parameters from
register_machine_with_fallback_and_log() and the corresponding input
parameters from unregister_machine_with_fallback_and_log().

The struct carries state from registration to unregistration so the
caller no longer needs to manually thread individual booleans between
the two calls.

register_machine_with_fallback_and_log() goes from 7 to 3 parameters,
unregister_machine_with_fallback_and_log() goes from 5 to 2.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 21:42:15 +02:00
Christian Brauner 2af171653f shared: introduce MachineRegistration struct for machine registration
Replace the long positional parameter lists in register_machine() and
register_machine_with_fallback_and_log() with a MachineRegistration
struct that bundles all machine-describing fields.

This reduces register_machine() from 13 parameters to 3 and
register_machine_with_fallback_and_log() from 17 parameters to 7.
Callers now use designated initializers, which makes omitted fields
(zero/NULL/false) implicit and the code much more readable.

Field names are aligned with the existing Machine struct in machine.h
(id, root_directory, vsock_cid, ssh_address, ssh_private_key_path).

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 21:42:15 +02:00
Christian Brauner 6b3b9b1abd shared: document allocateUnit limitation on D-Bus fallback path
The D-Bus registration methods (RegisterMachineEx, RegisterMachineWithNetwork)
do not support the allocateUnit feature that the varlink path provides.
When varlink is unavailable and registration falls back to D-Bus, machined
discovers the caller's existing cgroup unit instead of creating a dedicated
scope. Callers that skip client-side scope allocation (relying on the
server to do it via allocateUnit) will end up without a dedicated scope
on the D-Bus fallback path.

Document this limitation at the fallback site so callers are aware.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 21:42:15 +02:00
Christian Brauner 2b77bbeb20 vmspawn: only open runtime bus when needed for registration or scope allocation
The runtime bus (user bus in user scope, system bus in system scope) is
only needed for scope allocation (!arg_keep_unit) or machine registration
(arg_register != 0). When both are disabled the bus was still opened
unconditionally which causes unnecessary failures if the user bus is
unavailable.

Gate the runtime bus opening on the same condition nspawn already uses.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 21:42:15 +02:00
Christian Brauner d872be82a0 vmspawn: fix error message when opening user bus
The error message incorrectly says "system bus" when the code is
actually opening the user bus via sd_bus_default_user().

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-04-06 21:42:15 +02:00
Daan De Meyer e7fb7296f5 nspawn: rename --user= to --uid= and repurpose --user/--system for runtime scope
Rename nspawn's --user=NAME option to --uid=NAME for selecting the
container user. The -u short option is preserved. --user=NAME and
--user NAME are still accepted but emit a deprecation warning. A
pre-parsing step stitches the space-separated --user NAME form into
--user=NAME before getopt sees it, preserving backwards compatibility
despite --user now being an optional_argument.

Repurpose --user (without argument) and --system as standalone
switches for selecting the runtime scope (user vs system service
manager).

Replace all uses of the arg_privileged boolean with
arg_runtime_scope comparisons throughout nspawn. The default scope
is auto-detected from the effective UID.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 18:49:40 +02:00
Daan De Meyer 1e084aad7d shared: move machine registration to shared machine-register.{c,h}
Move register_machine() and unregister_machine() from
vmspawn-register.{c,h} into shared machine-register.{c,h} so both
nspawn and vmspawn can use the same implementation.

The unified register_machine() uses varlink first (for richer
features like SSH support and unit allocation) with a D-Bus
RegisterMachineWithNetwork fallback for older machined. The
interface adds a class parameter ("vm" or "container") and
local_ifindex for nspawn's network interface support.

The unified unregister_machine() similarly tries varlink first
(io.systemd.Machine.Unregister) before falling back to D-Bus.

Both register_machine() and unregister_machine() only log at debug
level internally, leaving error/notice logging to callers.

Add register_machine_with_fallback() which tries system and/or user
scope registration based on a RuntimeScope parameter
(_RUNTIME_SCOPE_INVALID for both), and
unregister_machine_with_fallback() as its counterpart. Both use
RET_GATHER() to collect errors from each scope.

Make --register= a tristate (yes/no/auto) defaulting to auto. When
set to auto, registration failures are logged at notice level and
ignored. When set to yes, failures are fatal.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 17:13:40 +02:00
Daan De Meyer 0e231729fd machined: skip leader ownership check for user scope
When registering a machine, machined verifies that the leader process
is owned by the calling user via process_is_owned_by_uid(). This
check fails for user scope machined when the leader is inside a user
namespace: after the leader calls setns(CLONE_NEWUSER), it becomes
non-dumpable, and the subsequent ptrace_may_access() check in the
kernel denies access to the process's user namespace, since the
calling user lacks CAP_SYS_PTRACE in the mm's user namespace (the
host namespace), even though the user owns the child user namespace.

Skip this check when running in user scope. For system scope, the
check is important because multiple users share the same machined
instance, so one user must not be able to claim another user's process
as a machine leader. For user scope this is unnecessary: the varlink
socket lives under $XDG_RUNTIME_DIR (mode 0700), so only the owning
user can connect, and the user machined instance can only perform
operations bounded by that user's own privileges. Registering a
foreign PID does not escalate capabilities.
2026-04-06 17:13:40 +02:00
Daan De Meyer 3c96d1429f namespace-util: Add logging to process_is_owned_by_uid() 2026-04-06 17:13:40 +02:00
Daan De Meyer bde83a9e1e vmspawn: Redirect QEMU's stdin/stdout/stderr to the PTY
When a PTY is allocated for the console, QEMU's own stdio file
descriptors were still inherited directly from vmspawn, meaning any
output QEMU writes to stdout/stderr (e.g. warnings) would bypass the
PTY forwarder and go straight to the terminal. Similarly, QEMU could
read directly from the terminal's stdin.

Fix this by opening the PTY slave side and passing it as stdio_fds to
the fork call with FORK_REARRANGE_STDIO, so that all of QEMU's I/O
goes through the PTY and is properly forwarded.
2026-04-06 13:58:31 +02:00
Daan De Meyer fb4bfe651b vmspawn: Use ~ instead of ! as negation prefix for --firmware-features=
Switch the negation character for firmware feature exclusion from
"!" to "~" to be consistent with other systemd options that support
negation such as SystemCallFilter=.
2026-04-05 21:09:23 +02:00
Daan De Meyer a85845f043 vmspawn: Add comment explaining substring match in firmware_data_matches_machine()
The machine types in QEMU firmware descriptions are glob patterns
like "pc-q35-*", so we use strstr() substring matching to check if
our machine type is covered by a given firmware entry.
2026-04-05 21:09:23 +02:00
Daan De Meyer f8e88be1d1 swtpm-util: Silence noise from swtpm_setup
There's no way to configure the log level for swtpm_setup, so pipe
it's logfile (which defaults to stderr) to /dev/null unless debug
logging is enabled.
2026-04-05 20:34:11 +02:00
Daan De Meyer 4753c60053 swtpm: gracefully fall back when --print-profiles output is not JSON
Older swtpm versions print --help output instead of JSON when
swtpm_setup --print-profiles is invoked. Previously, the JSON parse
failure was treated as fatal, preventing swtpm manufacture entirely on
these older versions.

Extract profile detection into a separate swtpm_find_best_profile()
helper and treat JSON parse failure as a graceful fallback: log a
notice and continue without a profile, same as when no builtin profiles
are found.
2026-04-05 19:47:26 +02:00
Daan De Meyer ba937b45be vmspawn: Fix qemu-kvm path on centos stream
Follow up for 41da1ae6a0
2026-04-05 18:51:17 +02:00
Luan Vitor Simião oliveira 39eb7fd259 hwdb: cooler master rgb controller is not a mouse 2026-04-05 17:10:13 +01:00
Christian Brauner 7ae14028d3 udev: also trigger loop device for boot disk when partition scanning is unsupported (#41509)
Previously, probe_gpt_sector_size_mismatch() would bail out early when
the GPT sector size matched the device sector size. However, some
devices (e.g. certain CD-ROM drives) do not support kernel partition
scanning even when sector sizes match. In that case, the kernel still
cannot parse the partition table, and we need to set up a loop device to
expose the partitions — just as we do for the sector size mismatch case.

Check blockdev_partscan_enabled() when sector sizes match, and only skip
the boot partition check if partition scanning is actually supported.

Also rename the function, udev property, and log messages to reflect the
broader scope:

- probe_gpt_sector_size_mismatch() -> probe_gpt_boot_disk_needs_loop()
- ID_PART_GPT_AUTO_ROOT_DISK_SECTOR_SIZE_MISMATCH ->
ID_PART_GPT_AUTO_ROOT_DISK_NEEDS_LOOP
2026-04-05 16:33:46 +02:00
Daan De Meyer c82cf5662e boot: generalize CDROM terminology to El Torito
Per UEFI specification §13.3.2, El Torito partition discovery applies to
any block device, not just optical media. Rename
disk_get_part_uuid_cdrom() to disk_get_part_uuid_eltorito() and update
all log messages and comments to say "El Torito" instead of "CDROM" to
reflect this.
2026-04-05 08:19:49 +00:00
Daan De Meyer 41da1ae6a0 vmspawn: also search for qemu binary at /usr/lib/qemu-kvm
This is the qemu binary path on CentOS Stream.
2026-04-05 09:55:09 +02:00
Daan De Meyer 4e0eabd401 udev: also trigger loop device for boot disk when partition scanning is unsupported
Previously, probe_gpt_sector_size_mismatch() would bail out early when
the GPT sector size matched the device sector size. However, some
devices (e.g. certain CD-ROM drives) do not support kernel partition
scanning even when sector sizes match. In that case, the kernel still
cannot parse the partition table, and we need to set up a loop device to
expose the partitions — just as we do for the sector size mismatch case.

Check blockdev_partscan_enabled() when sector sizes match, and only skip
the boot partition check if partition scanning is actually supported.

Also rename the function, udev property, and log messages to reflect the
broader scope:

- probe_gpt_sector_size_mismatch() -> probe_gpt_boot_disk_needs_loop()
- ID_PART_GPT_AUTO_ROOT_DISK_SECTOR_SIZE_MISMATCH -> ID_PART_GPT_AUTO_ROOT_DISK_NEEDS_LOOP
2026-04-04 22:24:47 +00:00
Lennart Poettering 51e04b7e90 shutdown: enforce a minimum uptime to make boot loops less annoying (#41215)
Fixes: #9453

Split out of #41016
2026-04-04 23:30:30 +02:00