Commit Graph
454 Commits
Author SHA1 Message Date
Yu Watanabe 90481c0b1b tree-wide: add missing assertions
Found by coccinelle.
2026-08-18 06:30:10 +09:00
dongshengyuan 78238fd7c9 socket: parse message queue size as IEC size
Allow MessageQueueMessageSize= to accept IEC size suffixes in socket unit files.
Support the same syntax for transient property assignments.
Keep MessageQueueMaxMessages= as a plain message count.
2026-08-02 19:17:51 +09:00
Lennart Poettering cc174775f5 core: add socket xattr settings for socket unit 2026-06-23 22:55:23 +02:00
Michael Vogt 046de3caea core: add RestartRandomizedDelaySec= service option
We already support exponential backoff for automatic restarts via
RestartSec=/RestartSteps=/RestartMaxDelaySec=, but there is no way to
randomize the restart delay. When many instances of a service fail at
the same time (e.g. because a shared resource briefly went away) they
are all restarted in lockstep, creating a thundering herd problem.

So this commit adds a simple `RestartRandomizedDelaySec=` service
option which is similar to the timer `RandomizedDelaySec=` and
adds a randomized restart delay.
2026-06-20 12:31:28 +02:00
Luca Boccassi 82b8615463 core: add LUOSession= unit setting
Acquiring a LUO session from /dev/liveupdate requires privileges,
and also the device is a single-owner driver so only a single
process can open it at any given time.

Add a LUOSession= service settings that allows units running
without privileges to get a session assigned to them.

The kernel imposes a 64 chars limit on session names, which is
too short to avoid clashes, so derive a hash from joining the
unit name with the parameter name, that way two units using
the same setting don't clash.
2026-06-17 13:11:15 +01:00
Matteo Croce 15783e4657 oomd: ruleset parsing
Add to oomd the capability to define rulesets in /etc/systemd/oomd/rules.d/
and then reference them with a new config option OOMRule=
2026-05-18 21:42:56 +02:00
glemco 43b53679da cgroup: Add CPUSetPartition= setting
Add support for configuring cpuset partition type via the
CPUSetPartition= unit file setting. This controls the kernel's
cpuset.cpus.partition cgroup attribute.

The setting takes one of "member", "root", or "isolated". This is
useful for real-time workloads that require dedicated CPU resources
without interference from other processes.

When set, systemd will write the partition type to the
cpuset.cpus.partition cgroup file. If the kernel rejects the value
(e.g., due to partition hierarchy rules), a warning is logged and the
unit continues with the kernel's default partition type.

Co-developed-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
2026-05-14 08:55:44 +02:00
Diego Viola 5d17215c7e treewide: fix typos in the entire codebase
Signed-off-by: Diego Viola <diego.viola@gmail.com>
2026-05-05 17:22:26 +02:00
Michael Vogt bd141bd818 many: fix remaining check-pointer-deref issues
The updated parsing_hacks.h file uncovered a bunch of extra
things that the check-pointer-deref coccinelle script flags.

This commit fixes them to make the tree check-pointer-deref clean.
2026-04-12 15:27:15 +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
Lennart Poettering fe1f8c1acd run: support RootMStack= on the client side for systemd-run 2026-02-19 15:05:15 +01:00
Mike Yuan a43bc1aed8 core/service: introduce RefreshOnReload= setting
This allows controlling resources to be refreshed before performing
reload, with one extra benefit that in the future we can permit
"seemless reload"s, i.e. no active signaling is done to the main process
after refreshing get updated. This could come in handy for programs
that loads stuff on demand or watches changes via inotify.
2026-02-10 21:54:12 +01:00
Yu Watanabe c3540c80a5 bus-unit-util: convert StandardInputText to StandardInputData
Fixes #40527.
2026-01-31 06:41:57 +09:00
Yu Watanabe da912e7f2f bus-unit-util: make ExecSearchPath= accepts colon separated list
Unlike other settings that takes multiple values, the setting takes
colon separated list of paths, but when specified as a DBus property,
it previously accepted space separated list of paths.
Let's also make the DBus property accepts colon separated lists.

Fixes #40513.
2026-01-31 01:24:07 +09:00
Mike Yuan 1a0df07843 core/cgroup: obsolete DefaultMemoryMin/Low=
Now that our kernel baseline is v5.7 and memory_recursiveprot
is universally enabled, remove userspace workarounds.
2026-01-19 13:33:28 +01:00
Mike Yuan 64a2712db5 core: rearrange MemoryTHP=
* Place related logic closer to MemoryKSM=, do not interleave
  it with various BPF delegation knobs
* MemoryTHP= is a execute directive, not namespace
2026-01-18 16:42:21 +01:00
Usama Arif 32614b9aab core: introduce MemoryTHP= unit file setting
Transparent Hugepages (THP) is a Linux kernel feature that manages
memory using larger pages (2MB on x86, compared to the default 4KB).
The main goal is to improve memory management efficiency and system
performance, especially for memory-intensive applications.
However, it can cause drawbacks in some scenarios, such as memory
regression and latency spikes. THP policy is governed for the entire
system via /sys/kernel/mm/transparent_hugepage/enabled.
However, it can be overridden for individual workloads via prctl(2)
call.
MemoryTHP= is used to disable THPs at exec-invoke to stop
providing THPs for workloads where the drawbacks outweigh the advantages.
When set to "disable", MemoryTHP= disables THPs completely for the
process, irrespecitive of global THP controls.
When set to "madvise", MemoryTHP= disables THPs for the process except
when specifically madvised by the process with MADV_HUGEPAGE or MADV_COLLAPSE.
2026-01-06 03:26:14 -08:00
Mike Yuan e69ac871a0 bus-unit-util: BindNetworkInterface= is a cgroup property 2025-12-27 23:47:55 +01:00
Luiz Amaral c1c787651b Add support for binding a unit to a network iface 2025-12-24 07:37:58 +01:00
Mike Yuan fd99348353 bus-unit-util: ReloadSignal is a Service property
Follow-up for c133545430
2025-12-16 10:37:09 +01:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De Meyer 0bac1ed242 tree-wide: Fix constness issues with newer glibc
Latest glibc uses _Generic to have strstr() and other functions return
const char* or char* based on whether the input is a const char* or a
char*. This causes build failures as we previously always expected a char*.

Let's fix the compilation failures and add our own macros similar to glibc's
to have string functions that return a mutable or const pointer depending on
the input.
2025-11-25 20:49:39 +01:00
Mike Yuan b03e1b09af core/service: rework ExecReload= + Type=notify-reload interaction, add ExecReloadPost=
When Type=notify-reload got introduced, it wasn't intended to be
mutually exclusive with ExecReload=. However, currently ExecReload=
is immediately forked off after the service main process is signaled,
leaving states in between essentially undefined. Given so broken
it is I doubt any sane user is using this setup, hence I took a stab
to rework everything:

1.  Extensions are refreshed (unchanged)
2.  ExecReload= is forked off without signaling the process
3a. If RELOADING=1 is sent during the ExecReload= invocation,
    we'd refrain from signaling the process again, instead
    just transition to SERVICE_RELOAD_NOTIFY directly and
    wait for READY=1
3b. If not, signal the process after ExecReload= finishes
    (from now on the same as Type=notify-reload w/o ExecReload=)
4.  To accomodate the use case of performing post-reload tasks,
    ExecReloadPost= is introduced which executes after READY=1

The new model greatly simplifies things, as no control processes
will be around in SERVICE_RELOAD_SIGNAL and SERVICE_RELOAD_NOTIFY
states.

See also: https://github.com/systemd/systemd/issues/37515#issuecomment-2891229652
2025-11-04 12:18:33 +01:00
Quentin Deslandes 79dd24cf14 core: Add UserNamespacePath=
This allows a service to reuse the user namespace created for an
existing service, similarly to NetworkNamespacePath=. The configuration
is the initial user namespace (e.g. ID mapping) is preserved.
2025-11-04 10:55:04 +01:00
Yu Watanabe 2bdabb167b basic: rename cap-list.c -> capability-list.c
This also renames relevant files in the same way.

Addresses https://github.com/systemd/systemd/pull/37904#discussion_r2191950396
2025-07-11 18:33:43 +09:00
Matteo Croce ea9826eb94 core: add options to delegate BPFFS token creation
Add four new options BPFDelegate{Commands,Maps,Programs,Attachments}=
in order to delegate to a BPFFS instance the permission to create tokens.

The value is a list of options taken from:
https://github.com/torvalds/linux/blob/v6.14/include/uapi/linux/bpf.h#L922-L1121
The special value "any" means to allow every possible values.

More informations about BPF tokens here:
https://lwn.net/Articles/947173/
2025-07-08 22:35:29 +02:00
Matteo Croce 3a47437fc9 core: Introduce PrivateBPF= to mount a private BPFFS
Add a new option PrivateBPF= to mount a new instance of bpffs within a
namespace.
PrivateBPF= can be set to "no" to use the host bpffs in readonly mode
and "yes" to do a new mount.
The mount is done with the new fsopen()/fsmount() API because in future
we'll hook some commands between the two calls.
2025-07-08 22:33:28 +02:00
Andres Beltran a89afe1948 Add quota support for DBus 2025-07-07 17:31:03 +00:00
Zbigniew Jędrzejewski-Szmek 228d84e37a systemd-analyze: stop printing Ex transient settings
The test will fail if we ever add one again in the future by mistake.
2025-07-06 18:17:47 +02:00
Zbigniew Jędrzejewski-Szmek 41288f2daf shared/bus-unit-util: fix PrivateTmp=/PrivateUsers=/ProtectControlGroups= and Ex variants
For some fields, we perform careful parsing and verification on the sender
side. For other fields, we accept any string or strv. I think that actually
this is fine: we should optimize for the correct case, i.e. the user runs a
command that is valid. The server must perform parsing in all cases, so doing
the verification on the sender side doesn't add value. When doing parsing
locally, in case of invalid or unsupported input, we would generate the error
message locally, so we would avoid the D-Bus call, but the message itself is
not better and from the user's point of view, the result is the same. And by
doing the parsing only on the server side, we deal better with the case where
the sender has an older version of the software. By not doing verification, we
implicitly "support" new values. And when the sender has a newer version that
supports additional fields, that does not help as long as the server uses an
older version. So in case of version mismatches, parsing on the server side is
as good or better.

Resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:45 +02:00
Zbigniew Jędrzejewski-Szmek fb98c75e0e shared/bus-unit-util: tweak bus_append_exec_command to use Ex prop only if necessary
This changes little in behaviour, the conceptual part is more important. The
non-Ex variant is the actual name on the command line, and we should use the
non-Ex D-Bus property too, if it works. This increases compatibility with old
versions. But the code was mostly doing the right thing. Even the tests tested
the right thing.

Follow-up for b3d593673c and
898fc00e79.

The test is simplified by taking advantage of the fact that both names
on the commandline are supposed to behave identically.

Partially resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:43 +02:00
Zbigniew Jędrzejewski-Szmek 6f06afde59 shared/bus-unit-util: rework error messages for NFTSet=
Let's be nice to the user and print the exact reason why we won't accept
a setting.
2025-07-06 18:06:51 +02:00
Zbigniew Jędrzejewski-Szmek 95a3cfcbf6 shared/bus-unit-util: rework error messages
We generally want to have error messages with a fixed structure that convey the
important information, i.e. field name, error value, and the offending text for
options that take short values. (The text is not printed for strings encoded with
base64 and hexmem or for credentials.)

Let's use a helper that prints the message in a fixed format in the majority of
cases. In the few places where a custom message is useful, the helper is not
used. The helper:
- prints the field name, value, and error info,
- quotes the value,
- handles -ENOMEM, so we don't need to handle it separately everywhere.

When this code was originally written, parse functions would return -1
as error. Nowadays day all return a good errno, so it is fine if we print
the corresponding strerror.
2025-07-06 18:06:49 +02:00
Zbigniew Jędrzejewski-Szmek ce120ac823 shared/bus-unit-util: tweak error handling in bus_append_exec_command
exec_command_flags_to_strv() should not fail, unless we screwed up, so assert
instead of returning an error. Also, no need to strdup constant _PATH_BSHELL;
drop that so that we can get rid of the oom error handling. Finally, rename
l → cmdline for clarity.
2025-07-06 17:47:11 +02:00
Zbigniew Jędrzejewski-Szmek 8d853534ed shared/bus-unit-util: also send empty array for LogFilterPatterns=
Before, for empty input, we'd send an array with one item with an empty
pattern. Use the helper which sends an empty array instead.
bus_exec_context_set_transient_property() ignores items with an empty
pattern, so the result should be the same.

Request in review:
https://github.com/systemd/systemd/pull/37665#discussion_r2182375988.
2025-07-04 12:14:27 +02:00
Zbigniew Jędrzejewski-Szmek 892a24d42c shared/bus-unit-util: check errors before other conditions
As requested in post-merge review in
https://github.com/systemd/systemd/pull/37665#discussion_r2183755909.
2025-07-04 12:14:27 +02:00
Zbigniew Jędrzejewski-Szmek 01383af1c1 shared/bus-unit-util: stop unsing strndupa
Those are user-controlled strings, so let's use heap allocations in the usual
fashion. (Though, with strndupa_safe, the allocations were bounded anyway, so
ultimately this doesn't matter.)
2025-07-03 21:03:26 +02:00
Zbigniew Jędrzejewski-Szmek 1c1626e063 shared/bus-unit-util: add bus_dump_transient_settings() helper
bus_append_unit_property() and associated functions accept a long list of
properties. But the specific names are only available through code. But it is
useful to be able to know the specific list of properties that is supported, in
particular for shell completions. Thus, add a way to list the properties that
are supported by the code.

In the future we could also turn this into a test for the documentation. For
various reasons, the list of properties listed in the docs is a partially
overlapping set. E.g. for service type, the pull request
https://github.com/systemd/systemd/pull/37661 creates a list with 212 entries,
and this code generates 7 entries less and 184 more. I didn't check all the
differences, but in the few cases I did, the list generated here was actually
correctly supported by 'systemd-run -p'.

A smoke test is added.
2025-07-03 21:03:26 +02:00
Zbigniew Jędrzejewski-Szmek c133545430 shared/bus-unit-util: convert to a table 2025-07-03 19:58:15 +02:00
Zbigniew Jędrzejewski-Szmek b77e4fc6ce shared/bus-unit-util: add helper for TimeoutSec= 2025-07-03 19:58:15 +02:00
Zbigniew Jędrzejewski-Szmek 73ac906bec shared/bus-unit-util: add define to shorten common append pattern 2025-07-03 19:58:12 +02:00
Zbigniew Jędrzejewski-Szmek 472a1faae8 shared/bus-unit-util: add helper for AppArmorProfile=/SmackProcessLabel= 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek dbd4d4cc43 shared/bus-unit-util: add helper for CPUQuotaPeriodSec=ManagedOOMMemoryPressureDurationSec= 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek 5e18038da2 shared/bus-unit-util: add helper for unit deps 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek a90d205af5 shared/bus-unit-util: define helper for conditions and asserts
The function has "try" in the name because it dynamically checks
if the field name matches.
2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek 9806468ea4 shared/bus-unit-util: define helper for SuccessActionExitStatus= and friend 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek bfa7d82661 shared/bus-unit-util: add helper for TimersCalendar property 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek c3c21b2bc4 shared/bus-unit-util: add helper for TimersMonotonic property 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek d661a540a3 shared/bus-unit-util: add helper for Listen property 2025-07-03 19:53:38 +02:00