Commit Graph
87871 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek ccb5a185e4 executor: convert to the new option parser, define OPTION_COMMON_LOG_*
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:52:38 +02:00
Zbigniew Jędrzejewski-Szmek 98c57879b6 cryptsetup: convert to the new option and verb parsers
The synopisis is moved from the header to the a new section:

  -systemd-cryptsetup attach VOLUME SOURCE-DEVICE [KEY-FILE] [CONFIG]
  -systemd-cryptsetup detach VOLUME
  +systemd-cryptsetup [OPTIONS...] {COMMAND} ...

   Attach or detach an encrypted block device.

  +Commands:
  +  attach VOLUME SOURCE-DEVICE [KEY-FILE] [CONFIG] Attach an encrypted block
  +                                                  device
  +  detach VOLUME                                   Detach an encrypted block
  +                                                  device
  +
  +Options:

I think that's OK… With the autogenerated table that's the natural
thing to do.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 85c1c04a4e cryptenroll: convert to the new option parser
--help is the same, apart from linewrapping.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 227460f4ef cryptenroll: reorder option cases to match --help output
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek ddc97d68d6 cat: convert to the new option parser
--help is identical except for whitespace.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek c5f444e85b bsod: convert to the new option parser
Option indentation in --help is fixed.
Description for --continuous is shortened.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 120edabb4f delta: convert to the new option parser
--help for --diff= is changed from old-style "1|0" to "yes|no".

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek c15550e1df escape: convert to the new option parser
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek e517eadbd2 pull: convert to the new option and verb parsers
Duplicated word in description of --keep-download= is fixed.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 959116d5de importctl: convert to the new option and verb parsers
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek ee96f934c6 importctl: fix -N to actually clear keep-download flag
-N was clearing and re-setting the same bit in arg_import_flags_mask,
which is a no-op. It should clear the bit in arg_import_flags instead,
matching what --keep-download=no does via SET_FLAG().
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 4319ca43f9 import: convert to the new option and verb parsers
--help output is the same.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 11505ac135 bootctl: convert options and verbs to the new macros
-RR is formatted using the new OPTION_HELP_ENTRY_VERBATIM so that
we get the same --help as before.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 4f6fdbcf7a shared/verbs: add _SCOPE variants of the verb macros
In some of the large programs, verbs are defined as non-static
functions. To support this cases, add variants of the VERB macros that
take an explicit scope parameter. The existing macros then call those
new macros with scope=static. The variant without static is the
exception, so the macros are "optimized" toward the static helpers.

I also considered allowing VERB macros to be used in different files,
i.e. in different compilation units. This would actually work without
too many changes, except for one caveat: the order in the array would be
unspecified, so we'd need to somehow order the verbs appropriately. This
most likely means that the verbs would need to be annotated with a
number. But that doesn't seem attractive at all: we'd need to coordinate
changes in different files. So just listing the verbs in one file seems
like least bad option.
2026-04-11 09:54:57 +02:00
Zbigniew Jędrzejewski-Szmek 10e78e0b0e shared/options: add option to generate a help line for custom option format
Sometimes we want to document what -RR or -vv does or some other
special thing. Let's allow this by (ab-)using long_code pointer
to store a preformatted string.
2026-04-11 09:54:56 +02:00
Luca Boccassi 53c87c096c json-stream: fix NULL pointer passed to memcpy on first read with INPUT_SENSITIVE
When JSON_STREAM_INPUT_SENSITIVE is set before the first read,
input_buffer is NULL, input_buffer_size is 0, and input_buffer_index
is 0. The old condition '!INPUT_SENSITIVE && index == 0' would route
this case into the else branch which calls memcpy() with a NULL source
pointer, which is undefined behavior even when the length is zero, and
is caught by UBSan.

Fix by checking input_buffer_index == 0 first, then allowing the
GREEDY_REALLOC fast path also when input_buffer_size == 0, since
there is no sensitive data to protect from realloc() copying in that
case. The else branch is now only entered when there is actual data
to copy (input_buffer_size > 0), guaranteeing input_buffer is
non-NULL.

Follow-up for 6b1a59d594
2026-04-11 06:42:28 +02:00
Nandakumar Raghavan 056bc106e1 core: fix EBUSY on restart and clean of delegated services
When a service is configured with Delegate=yes and DelegateSubgroup=sub,
the delegated container may write domain controllers (e.g. "pids") into the
service cgroup's cgroup.subtree_control via its cgroupns root. On container
exit the stale controllers remain, and on service restart clone3() with
CLONE_INTO_CGROUP fails with EBUSY because placing a process into a cgroup
that has domain controllers in subtree_control violates the no-internal-
processes rule. The same issue affects systemctl clean, where cg_attach()
fails with EBUSY for the same reason.

Add unit_cgroup_disable_all_controllers() helper in cgroup.c that clears
stale controllers via cg_enable(mask=0) and updates cgroup_enabled_mask to
keep internal tracking in sync. Call it from service_start() and
service_clean() right before spawning, so that resource control is preserved
for any lingering processes from the previous invocation as long as possible.
2026-04-11 00:07:05 +01:00
Frantisek Sumsal 1016dd315f sd-json: limit the stack depth during parsing as well 2026-04-10 21:33:11 +01:00
Zbigniew Jędrzejewski-Szmek 5cd61c1330 Define array cleanup funcs through macros (#41559) 2026-04-10 21:45:14 +02:00
Daan De Meyer 6b1a59d594 sd-json: add JsonStream transport-layer module and migrate sd-varlink
Introduces JsonStream, a generic transport layer for JSON-line message
exchange over a pair of file descriptors. It owns the input/output
buffers, SCM_RIGHTS fd passing, the deferred output queue, the
read/write/parse step functions, sd-event integration (input/output/time
event sources), the idle timeout machinery, and peer credential caching,
but knows nothing about the specific JSON protocol on top — the consumer
drives its state machine via phase/dispatch callbacks supplied at
construction.

sd-varlink is reworked to delegate the entire transport layer to a
JsonStream owned by sd_varlink. The varlink struct drops every
transport-related field (input/output buffers and fds, output queue,
fd-passing state, ucred/pidfd cache, prefer_read/write fallback, idle
timeout, description, event sources) — all of that lives in JsonStream
now. What remains in sd_varlink is the varlink-protocol state machine
(state, n_pending, current/previous/sentinel, server linkage, peer
credentials accounting, exec_pidref, the varlink-specific quit and defer
sources) and a thin wrapper layer over the JsonStream API. The
should_disconnect / get_timeout / get_events / wait helpers all live in
JsonStream now and are driven by a JsonStreamPhase the consumer reports
via its phase callback.
2026-04-10 20:04:12 +02:00
Luca Boccassi a1813a40ec docs: beef up SECURITY.md rules for reporting
With yeswehack.com suspended due to funding issues for triagers being
worked out, reports on GH are starting to pile up. Explicitly define
some ground rules to avoid noise and time wasting.
2026-04-10 17:34:03 +02:00
Zbigniew Jędrzejewski-Szmek 79f90f4ae0 various: use DEFINE_ARRAY_FREE_FUNC 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 2a23e43f70 sysupdate: use DEFINE_POINTER_ARRAY_FREE_FUNC, rename func 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 7024c0c38c shared/tar-util: use DEFINE_ARRAY_FREE_FUNC, rename funcs 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 90c6157100 sd-journal: use NormalCasing for struct 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 5ceaab3d4f nsresourced: use DEFINE_ARRAY_FREE_FUNC, make func static and rename 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek b8514cff52 libsystemd-network: use DEFINE_POINTER_ARRAY_FREE_FUNC, rename cleanup function 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 954243f2bc libsystemd-network: use DEFINE_ARRAY_FREE_FUNC, rename cleanup func 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 3b478198e9 stub: use DEFINE_ARRAY_FREE_FUNC 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 81d2d0270b Add DEFINE_ARRAY_FREE_FUNC and mount_image_free_array
This is similar to DEFINE_POINTER_ARRAY_FREE_FUNC, but one
pointer chase less. The name of the outer and inner functions are
specified separately. The inner function does not free, so it'll
be generally something like 'foo_done', but the outer function
does free, so it can be called 'foo_array_free'.
2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek bbc6af9ce3 Add DEFINE_POINTER_ARRAY_FREE_FUNC and conf_file_free_array
As mentioned in the grandfather commit, I want to use the _many
suffix for freeing of the contents of an array, so the functions
to free the array to get the suffix _array.
2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 3ed9e7cd23 firewall-util: use DEFINE_ARRAY_DONE_FUNC for netlink message cleanup
Replace the open-coded netlink_message_unref_many() function and its
DEFINE_TRIVIAL_CLEANUP_FUNC wrapper with DEFINE_ARRAY_DONE_FUNC.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 74573799ca Add DEFINE_ARRAY_DONE_FUNC
This is a helper macro that defines a function to drop elements of an
array but not the array itself. I used the "_many" suffix because it
most closely matches what happens here: we are calling the cleanup
function a bunch of times.
2026-04-10 15:08:02 +02:00
Lennart Poettering ff6b70fe7e Update TODO 2026-04-10 14:54:39 +02:00
Daan De Meyer 8355eb6e11 meson: Check if files returned by git ls-files actually exist
Otherwise you run into errors such as:

"""
../meson.build:2899:28: ERROR: File src/test/test-loop-util.c does not exist.
"""

when deleting a file in git without staging the deletion.
2026-04-10 14:34:00 +02:00
Frantisek Sumsal 92d87ac302 sd-bus: don't overallocate the message buffer
newa(t, n) already allocates sizeof(t) * n bytes, so previously we'd
actually allocate sizeof(t) * sizeof(t) * n bytes, which is ~16x more
(on x86_64) that we actually needed.

This is probably an oversight from a tree-wide change in
6e9417f5b4 that replaced alloca() with
newa().

Follow-up for 6e9417f5b4.
2026-04-10 12:20:16 +01:00
Lennart Poettering 5401a1270a logind: add io.systemd.Shutdown varlink interface (#41229)
The shutdown interface is currently only exposed via dbus. This PR
adds a comparable varlink implementation. It is inspired by the existing
dbus methods and implements PowerOff, Reboot, Halt, Kexec, SoftReboot
as varlink methods on a new io.systemd.Shutdown interface.

It is (intentional) simpler than the dbus for now, i.e. no Can* yet,
mostly
because I want to get feedback first (happy to do that in a followup). 

The only real difficulty here is what to do about
verify_shutdown_creds()
as this is needed by both dbus and varlink and its dbus only. I went for
an ugly but (hopefully) pragmatic choice (see the commit message for
details). But I can totally understand if a refactor instead is
preferred.
2026-04-10 12:29:32 +02:00
Lennart Poettering 58b9e400a6 Help users with incorrect / permission bits (#41431)
This error causes the computer to pass the emergency.target and go to
graphical.target.
Then, your window manager will have problems because it cant access any
directories, your network manager wont startup the network. In my case,
the screen just goes black. Ideally, you'd get an error message
explaining this edge scenario that's occuring to you, and an emergency
shell that makes it easy to run the necessary chmod 0755 / to proceed
with booting. IDK not sure if this is the correct way to implement this,
sorry it's my first contribution.

I ran 
`meson test -C build`
and got 

Ok:                1806
Fail:              26  
Skipped:           25  
on my cloned systemd repo before any changes, and got the same result
after my commit ¯\_(ツ)_/¯
So I hope I did that right. 
Thanks
2026-04-10 12:25:07 +02:00
Lennart Poettering 554ba32d30 report: add cgroup metrics in a separate varlink service (#41489)
Add CpuUsage, MemoryUsage, IOReadBytes, IOReadOperations, and
TasksCurrent in a standalone socket-activated varlink service. These
metrics are gathered from the kernel via cgroup files and PID1's only
role is mapping unit names to cgroup paths — a separate process can
query PID1 once for that mapping and then read the cgroup files
directly, minimizing PID1 involvement.

The new systemd-report-cgroup-metrics service listens at
/run/systemd/report/io.systemd.CGroup and exposes:
  - io.systemd.CGroup.CpuUsage
  - io.systemd.CGroup.IOReadBytes
  - io.systemd.CGroup.IOReadOperations
  - io.systemd.CGroup.MemoryUsage (with type=current/available/peak)
  - io.systemd.CGroup.TasksCurrent

This is spun out of #41078 and based on top of it. Will rebase once
that's merged.
2026-04-10 12:10:06 +02:00
Milan Kyselica dd80e5a348 resolved: replace assert() with error return in DNSSEC verify functions
dnssec_rsa_verify_raw() asserts that RSA_size(key) matches the RRSIG
signature size, and dnssec_ecdsa_verify_raw() asserts that
EC_KEY_check_key() succeeds. Both conditions depend on parsed DNS
record content. Replace with proper error returns.

The actual crypto verify calls (EVP_PKEY_verify / ECDSA_do_verify)
handle mismatches fine on their own, so the asserts were also redundant.

While at it, fix the misleading "EC_POINT_bn2point failed" log message
that actually refers to an EC_KEY_set_public_key() failure.

Fixes: https://github.com/systemd/systemd/issues/41569
2026-04-10 10:29:37 +01:00
Daan De Meyer a65ebc3ff9 claude-review: improve review quality for large PRs
Several issues were identified from analyzing logs of a large (52-commit) PR
review:

- Claude was batching multiple commits into a single review agent instead of
  one per worktree. Strengthen the prompt to explicitly prohibit grouping.
- Claude was reading pr-context.json and commit messages before spawning
  agents despite instructions not to, wasting time. Tighten the pre-spawn
  rules to only allow listing worktrees/ and reading review-schema.json.
- Subagents were spawned with model "sonnet" instead of "opus". Add explicit
  instruction to use opus.
- After agents returned, Claude spent 9 minutes re-verifying findings with
  bash/grep/sed commands, duplicating the agents' work. Add instruction to
  trust subagent findings and only read pr-context.json in phase 2.
- Subagents returned markdown-wrapped JSON instead of raw JSON arrays. Add
  instruction requiring raw JSON output only.
- Each subagent was independently reading review-schema.json. Instead have
  the main agent read it once and paste it into each subagent prompt.
- The "drop low-confidence findings" instruction was being used to justify
  dropping findings that Claude itself acknowledged as valid ("solid cleanup
  suggestions", "reasonable consistency improvement"). Remove the instruction.
- Simplify the deduplication instructions
- Stop adding the severity to the body in the post processing job as claude is
  also adding it so they end up duplicated.
2026-04-10 10:57:35 +02:00
azureuser fb0ae7436d resolved: skip cache flush on server switch/re-probe when StaleRetentionSec is set
manager_set_dns_server() and dns_server_flush_cache() call dns_cache_flush()
unconditionally, wiping the entire cache even when StaleRetentionSec is
configured. This defeats serve-stale by discarding cached records that should
remain available during server switches and feature-level re-probes.

The original serve-stale commit (5ed91481ab) added a stale_retention_usec
guard to link_set_dns_server(), and a later commit (7928c0e0a1) added the
same guard to dns_delegate_set_dns_server(), but these two call sites in
resolved-dns-server.c were missed.

This is particularly visible with DNSOverTLS, where TLS handshake failures
trigger frequent feature-level downgrades and re-probes via
dns_server_flush_cache(), flushing the cache each time.

Add the same stale_retention_usec guard to both call sites so that cache
entries are allowed to expire naturally via dns_cache_prune() when
serve-stale is enabled.

Fixes: #40781

This commit was prepared with assistance from an AI coding agent (GitHub
Copilot). All changes have been reviewed for correctness and adherence to the
systemd coding style.
2026-04-10 10:10:26 +02:00
Yaping Li 8c65fe4fa1 report: add cgroup metrics in a separate varlink service
Add CpuUsage, MemoryUsage, IOReadBytes, IOReadOperations, and
TasksCurrent in a standalone socket-activated varlink service.

The new systemd-report-cgroup service listens at
/run/systemd/report/io.systemd.CGroup and exposes:
  - io.systemd.CGroup.CpuUsage
  - io.systemd.CGroup.IOReadBytes
  - io.systemd.CGroup.IOReadOperations
  - io.systemd.CGroup.MemoryUsage (with type=current/available/peak)
  - io.systemd.CGroup.TasksCurrent
2026-04-09 14:45:05 -07:00
Yaping Li 6fe4a16f36 cgroup-util: add cg_get_keyed_attribute_uint64() helper
Multiple callers of cg_get_keyed_attribute() follow the same pattern of
reading a single keyed attribute and then parsing it as uint64_t with
safe_atou64(). Add a helper that combines both steps.

Convert all existing single-key + uint64 call sites in cgtop, cgroup.c,
and oomd-util.c to use the new helper.
2026-04-09 14:45:05 -07:00
Frantisek Sumsal d3a1710bc2 sd-varlink: fix a potential connection count leak
With the old version there was a potential connection count leak if
either of the two hashmap operations in count_connection() failed. In
that case we'd return from sd_varlink_server_add_connection_pair()
_before_ attached the sd_varlink_server object to an sd_varlink object,
and since varlink_detach_server() is the only place where the connection
counter is decremented (called through sd_varlink_close() in various
error paths later _if_ the "server" object is not null, i.e. attached to
the sd_varlink object) we'd "leak" a connection every time this
happened. However, the potential of abusing this is very theoretical,
as one would need to hit OOM every time either of the hashmap operations
was executed for a while before exhausting the connection limit.

Let's just increment the connection counter after any potential error
path, so we don't have to deal with potential rollbacks.
2026-04-09 22:05:25 +01:00
Milan Kyselica 4b32ab5a36 udev: fix bounds check in dev_if_packed_info()
The check compared bLength against (size - sizeof(descriptor)), which
is an absolute limit unrelated to the current buffer position. Since
bLength is uint8_t (max 255), this can never exceed size - 9 for any
realistic input, making the check dead code.

Use (size - pos) instead so the check actually catches descriptors
that extend past the end of the read data.

Fixes: https://github.com/systemd/systemd/issues/41570
2026-04-09 21:48:09 +01:00
Daan De Meyer 5ade3f6a01 docs: Fix window in PRESSURE.md 2026-04-09 22:47:10 +02:00
Daan De Meyer 158f2d50bf docs: Update MEMORY_PRESSURE.md => PRESSURE.md
Make the doc more generic and mention all pressure types, not just
memory.
2026-04-09 22:47:10 +02:00
Daan De Meyer 594659da06 core: Add I/O pressure support 2026-04-09 22:47:10 +02:00
Daan De Meyer 316d17fcbd core: Add support for CPU pressure notifications
Works the same way as memory pressure notifications. Code is refactored
to work on enum arrays to reduce duplication.
2026-04-09 22:47:10 +02:00