Commit Graph

81328 Commits

Author SHA1 Message Date
Lennart Poettering
f9d76a8d15 sd-boot: add support for a sysfail entry (#34856)
Add support for a sysfail boot entry. Sysfail boot entries can be used
for optional tweaking the automatic selection order in case a failure
state of the system in some form is detected (boot firmware failure
etc).

The EFI variable `LoaderEntrySysFail` contains the sysfail boot loader
entry to use. It can be set using bootctl:
```
$ bootctl set-sysfail sysfail.conf
```

The `LoaderEntrySysFail` EFI variable would be unset automatically
during next boot by `systemd-boot-clear-sysfail.service` if no system
failure occured, otherwise it would be kept as it is and a system
failure reason will be saved to `LoaderSysFailReason` EFI variable.

`sysfail_check()` expected to be extented to support possibleconditions
when we should boot sysfail("recovery") boot entry.

Also add support for using a sysfail boot entry in case of UEFI firmware
capsule update failure [1]. The status of a firmware update is obtained
from the EFI System Resource Table (ESRT), which provides an optional
mechanism for identifying device and system firmware resources for the
purposes of targeting firmware updates to those resources.
    
Current implementation uses the value of LastAttemptStatus field from
ESRT, which describes the result of the last firmware update attempt for
the firmware resource entry. The field is updated each time an
`UpdateCapsule()` is attempted for an ESRT entry and is preserved across
reboots (non-volatile).
    
This can be be used in setups with support for A/B OTA updates, where
the boot firmware and Linux/RootFS might be updated synchronously.
    
The check is activated by adding "sysfail-firmware-upd" to loader.conf
    
[1]
https://uefi.org/specs/UEFI/2.10/23_Firmware_Update_and_Reporting.html
2025-05-13 11:23:26 +02:00
Eisuke Kawashima
6d07d23b02 shell-completion: fix completion of systemctl --user unset-environment (#37409)
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2025-05-13 09:04:52 +09:00
André Monteiro
02527e95b5 Add dns0.eu in resolved.conf.in (#37404)
Add dns0.eu as a dns option in resolved.conf.in
This also adds Quad9 DNS servers as the default fallback servers.
2025-05-13 08:36:22 +09:00
Mike Yuan
2950fb1b9b run0: drop -a short switch for --area=
Follow-up for f44e7a8c11

This breaks the rule stated at the beginning of help_sudo_mode():

> NB: Let's not go overboard with short options: we try to keep a modicum of compatibility with
> sudo's short switches, hence please do not introduce new short switches unless they have a roughly
> equivalent purpose on sudo. Use long options for everything private to run0.
2025-05-13 08:33:10 +09:00
Yu Watanabe
87ddd97057 core: assorted cleanups (#37410) 2025-05-13 08:32:20 +09:00
Mike Yuan
3ca4a717a6 core/dbus-unit: remove unneeded else if 2025-05-12 18:56:15 +02:00
Mike Yuan
f76b029312 core/dbus-execute: always normalize argv[0] to "sh" on EXEC_COMMAND_VIA_SHELL
Addresses https://github.com/systemd/systemd/pull/37071#discussion_r2084851759
2025-05-12 17:09:08 +02:00
Mike Yuan
5e24ebace2 core/slice: remove redundant assertion 2025-05-12 17:05:37 +02:00
Antonio Alvarez Feijoo
0425fc5eb7 log: fix declaration of log_dispatch_internal() 2025-05-12 23:42:19 +09:00
Mike Yuan
81d5eda6c5 core: accept "|" ExecStart= prefix to spawn target user's shell; teach run0 about the new logic (#37071)
I've always been reluctant to invoke the current user's shell in another
user's context, hence was fully grounded in `sudo -i`. With this bit in
place `run0` will finally be feature-complete on my side ;-)
2025-05-12 16:10:03 +02:00
Yu Watanabe
262dee132b meson: Various improvements (#37395) 2025-05-12 23:06:57 +09:00
Yu Watanabe
6ea555f913 core/namespace: fix issue in PrivateTmp=disconnected vs var.mount (#37271)
Fixes #37258.
Replaces #37259.
2025-05-12 23:05:24 +09:00
Yu Watanabe
fdb4d869f0 udev: sort received events by their seqnum (#37314)
The kernel sometimes sends uevents in a random order, so previously the
received events were not sorted by their seqnum. We determine which
event is ready for processing by using the assumption that queued events
are sorted by their seqnum. Let's sort the received events before queue
them, to make events processed in a correct ordering.
2025-05-12 23:04:49 +09:00
Igor Opaniuk
9c56688e87 sd-boot: use sysfail entry for UEFI firmware update failure
Add support for using a sysfail boot entry in case of UEFI firmware
capsule update failure [1]. The status of a firmware update is obtained from
the EFI System Resource Table (ESRT), which provides an optional mechanism
for identifying device and system firmware resources for the purposes of
targeting firmware updates to those resources.

Current implementation uses the value of LastAttemptStatus field from
ESRT, which describes the result of the last firmware update attempt for
the firmware resource entry. The field is updated each time an
UpdateCapsule() is attempted for an ESRT entry and is preserved across
reboots (non-volatile).

This can be be used in setups with support for A/B OTA updates, where
the boot firmware and Linux/RootFS might be updated synchronously.

[1] https://uefi.org/specs/UEFI/2.10/23_Firmware_Update_and_Reporting.html
Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
2025-05-12 15:37:47 +02:00
Igor Opaniuk
2857a83975 bootctl: configure a sysfail entry
You can configure the sysfail boot entry using the bootctl command:
$ bootctl set-sysfail sysfail.conf

The value will be stored in the `LoaderEntrySysFail` EFI variable.

The `LoaderEntrySysFail` EFI variable would be unset automatically
during next boot by `systemd-boot-clear-sysfail.service` if no
system failure occured, otherwise it would be kept as it is and a system
failure reason will be saved to `LoaderSysFailReason` EFI variable.

Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
2025-05-12 15:37:47 +02:00
Igor Opaniuk
004e3e4082 sd-boot: add support for a sysfail entry
Add support for a sysfail boot entry. Sysfail boot entries can be
used for optional tweaking the automatic selection order in case a
failure state of the system in some form is detected (boot firmware
failure etc).

The EFI variable `LoaderEntrySysFail` holds the boot loader entry to
be used in the event of a system failure. If a failure occurs, the reason
will be stored in the `LoaderSysFailReason` EFI variable.

sysfail_check() expected to be extented to support possible
conditions when we should boot sysfail("recovery") boot entry.

Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
2025-05-12 15:37:46 +02:00
Lennart Poettering
bd543bca11 bless-boot: some fixes (#37375)
This mostly makes sure we do something reasonable when our tool is
called from a boot of an entry that was already marked as definitely
"bad" on a previous boot. Such an entry we can return into a "good"
state, but we cannot return it into an "indeterminate" state, because
the status quo ante is already known.

Fixes: #37350
2025-05-12 15:11:06 +02:00
Daan De Meyer
1fbaabf9ec meson: Don't create static library target unless option is enabled
While we don't build these by default, all the source files still
get added to the compile_commands.json file by meson, which can confuse
tools as they might end up analyzing the source files twice or analyzing
the wrong one.

To avoid this issue, only define the static library target if the
corresponding option is enabled.
2025-05-12 13:35:50 +02:00
Daan De Meyer
30d20907bd meson: Remove unneeded include directories
meson by default adds the current source and build directory as include
directories. Because we structure our meson code by gathering a giant dict
of everything we want to do and then doing all the actual target generation
in the top level meson.build, this behavior does not make sense at all because
we end up adding the top level repository directory as an include directory
which is never what we want.

At the same time, let's also make sure the top level directory of the build
directory is not an include directory, by moving the version.h generation
into the src/version subdirectory and then adding the src/version subdirectory
of the build directory as an include directory instead of the top level
repository directory.

Making this change means that language servers such as clangd can't get
confused when they automatically insert an #include line and insert
"#include "src/basic/fs-util.h" instead of "#include "fs-util.h".
2025-05-12 13:35:50 +02:00
Daan De Meyer
6350d2dbd9 meson: Extract objects instead of creating intermediate static libraries
Currently, when we want to add unit tests for code that is compiled into
an executable, we either compile the code at least twice (once for the
executable, and once for each test that uses it) or we create a static
library which is then used by both the executable and all the tests.

Both of these options are not ideal, compiling source files more than
once slows down the build for no reason and creating the intermediate
static libraries takes a lot of boilerplate.

Instead, let's use the extract_objects() method that meson exposes on
build targets. This allows us to extract the objects corresponding to
specific source files and use them in other executables. Because we
define all executables upfront into a dictionary, we integrate this into
the dictionary approach by adding two new fields:

- 'extract' takes a list of files for which objects should be extracted.
  The extracted objects are stored in a dict keyed by the executable name
  from which they were extracted.
- 'objects' takes the name of an executable from which the extracted
  objects should be added to the current executable.

One side effect of this approach is that we can't build test executables
anymore without building the main executable, so we stop building test
executables unless we're also building the main executable. This allows
us to switch to using subdir_done() in all of these subdirectories to skip
parsing them if the corresponding component is disabled.

These changes get me down from 2439 => 2403 ninja targets on a full rebuild
from scratch.
2025-05-12 13:35:50 +02:00
Daan De Meyer
d8def5dc87 meson: Stop doing nested build when fuzzers are enabled
Currently, when fuzzers are enabled, we run meson from within meson
to build the fuzzer executables with sanitizers. The idea is that
we can build the fuzzers with different kinds of sanitizers
independently from the main build.

The issue with this setup is that we don't actually make use of it.
We only build the fuzzers with one set of sanitizers (address,undefined)
so we're adding a bunch of extra complexity without any benefit as we
can just setup the top level meson build with these sanitizers and get
the same result.

The other issue with this setup is that we don't pass on all the options
passed to the top level meson build to the nested meson build. The only things
we pass on are extra compiler arguments and the value of the auto_features
option, but none of the individual feature options if overridden are passed on,
which can lead to very hard to debug issues as an option enabled in the top
level build is not enabled in the nested build.

Since we're not getting anything useful out of this setup, let's simplify
and get rid of the nested meson build. Instead, sanitizers should be enabled
for the top level meson.build. This currently didn't work as we were overriding
the sanitizers passed to the meson build with the fuzzer sanitizer, so we
fix that as well by making sure we combine the fuzzer sanitizer with the ones
passed in by the user.

We also drop support for looking up libFuzzer as a separate library as
it has been shipped builtin in clang since clang 6.0, so we can assume
that -fsanitize=fuzzer is available.

To make sure we still run the fuzzing tests, we enable the fuzz-tests option
by default now to make sure they still always run (without instrumentation unless
one of llvm-fuzz or oss-fuzz is enabled).
2025-05-12 13:34:28 +02:00
Lennart Poettering
30284e3a59 bless-boot: never try to rename an entry file onto itself
If we are booting a known bad entry, and we are asked to mark it as bad,
we so far would end up renaming the entry onto itself, which resulted in
EEXIST and is really borked operation. Let's catch that case and handle
it explicitly.
2025-05-12 13:04:16 +02:00
Lennart Poettering
9420a0e6cb bless-boot: in "status" output report bad state from prev boot as "dirty"
The bless-boot logic currently assumes that if the name of the boot
entry reported via the EFI var matches the name on disk that the state
is "indeterminate", as we haven't counted down the counter (to mark it
bad) or drop the counter (to mark it good) yet. But there's one corner
case we so far didn't care about: what if the entry already reached 0
left tries in a previous boot, i.e. if the user invoked an entry already
known to be completely bad. In that case we'd still return
"indeterminate", but that's kinda misleading, because we *know* the
currently booted entry is bad, however we inherited that fact from a
previous boot, we didn't determine it on the current.

hence, let's introduce a new status we report in this case, that is both
distinct from "bad" (which indicates whether the *current* boot is bad)
and "indirect" (which indicates the current boot has not been decided on
yet): "dirty".

Why "dirty"? To mirror "clean" which we already have, which indicates a
boot already marked good in a previous boot, which is a relatively
symmetric state.

This is a really weak api break of sorts, because it introduces a new
state we never reported before, but I think it's fine, because the old
reporting was just wrong, and in a way this is bugfix, that we now
report correctly something where previously returned kind of rubbish
(though systematic rubbish).

Replaces:  #37350
2025-05-12 13:04:16 +02:00
Lennart Poettering
7a8372a9f1 bless-boot: switch from last_path_component() to path_find_last_component()
Using path_find_last_component() means special cases such as the root dir
and paths referencing dirs are detected and refused.
2025-05-12 13:04:16 +02:00
Lennart Poettering
aefdbacff8 README: mention explicitly that dmi-sysfs must be built-in, cannot be loaded as kmod
Fixes: #37391
2025-05-12 10:38:15 +02:00
naly zzwd
b5ee8ec4e8 po: Translated using Weblate (Catalan)
Currently translated at 100.0% (257 of 257 strings)

po: Translated using Weblate (Catalan)

Currently translated at 79.7% (205 of 257 strings)

Co-authored-by: naly zzwd <xeanhort007@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/ca/
Translation: systemd/main
2025-05-12 14:54:03 +09:00
Valentin Hăloiu
1dbeb98fea Add netdev files associated with link to networkd JSON output (#37402)
`networkctl status LINK` gained support for showing the netdev
configuration files associated with a link in
c9837c17d5, but these netdev files were
never added to the JSON output too.

This pull-request fixes that by adding two new fields (`NetDevFile` and
`NetDevFileDropins`) to the `networkctl` (and `D-Bus`) JSON output.
2025-05-11 09:33:28 +09:00
Yu Watanabe
8ac5b047fc man/systemd.exec: update documents for PrivateTmp= 2025-05-11 03:33:02 +09:00
Yu Watanabe
3e320dc608 test-execute: add test case for PrivateTmp=disconnected 2025-05-11 03:33:02 +09:00
Yu Watanabe
6156bec7a4 core: disable mounting disconnected private tmpfs on /var/tmp/ when DefaultDependencies=no
If DefaultDependencies=no, /var/ may not be mounted yet when the service
is being started. Previously, In such case, if the service has
PrivateTmp=disconnected, the service manager created /var/tmp/ on the
root filesystem and mounted the disconnected private tmpfs there. That
poluted the root filesystem and disturbed gpt-auto-generator on next
boot, as /var/ would not be empty anymore. See issue #37258.

This changes PrivateTmp=disconnected as the following:
- If DefaultDependencies=no and RootDirectory=/RootImage= are not set,
  then a private tmpfs is mounted _only_ on /tmp/, and set $TMPDIR=/tmp
  environment variable to suggest the service to use /tmp/.
- If DefaultDependencies=yes and RootDirectory=/RootImage= are not set,
  then implies RequiresMountsFor=/var/, though that is typically
  redundant, but anyway. Hence, we can safely mount /var/tmp/.
- Otherwise, i.e. when one of RootDirectory=/RootImage= is set, behaves
  as the same as the previous, as the private root filesystem for the
  service is explicitly prepared by the service manager, and we can
  safely mount a private tmpfs on /var/tmp/ without any extra
  dependencies.

Fixes #37258.

Co-authored-by: Mike Yuan <me@yhndnzj.com>
2025-05-11 03:33:02 +09:00
Yu Watanabe
26186503d7 core/mount: drop unnecessary dependency generations
When the unit is new, then mount_setup_new_unit() adds the unit to the
load queue, and the same dependencies will be anyway added.

When the unit already exists but previously failed to be loaded, then
mount_setup_existing_unit() also adds the unit to the load queue.
Hence it is not necessary to regenerate dependencies here now.

So, we need to regenerate dependencies only when things changed and
the unit has been already loaded.

No functional changes, just optimization.
2025-05-11 03:33:02 +09:00
Yu Watanabe
fee2f5ca3f core/mount,swap: reload unit when manually mounted/started and we previously failed to load
Otherwise, neither unit_patch_contexts() nor unit_add_exec_dependencies()
is called for the unit.
2025-05-11 03:32:48 +09:00
Yu Watanabe
13208591db core/namespace: split out append_private_tmp() 2025-05-11 03:29:20 +09:00
Yu Watanabe
97bf617af1 core/namespace: introduce should_propagate_to_submounts() helper function 2025-05-11 03:29:20 +09:00
Yu Watanabe
a4b1232dbf core/unit: suffix directory paths with slash 2025-05-11 03:29:20 +09:00
Mike Yuan
813c96c059 core/unit: clean up duplicate conditions 2025-05-11 03:29:20 +09:00
Luca Boccassi
f0b7ca9768 test: fix root check for test-bpf-foreign-programs
This test requires root, but the check was mistakenly dropped, causing it
to fail with an assert when running without root:

src/test/test-bpf-foreign-programs.c:308: Assertion failed: expected "test_bpf_cgroup_programs(m, "single_prog.service", single_prog, ELEMENTSOF(single_prog))" to succeed, but got error: Operation not permitted

Restore the uid check

Follow-up for 22e2f06428
2025-05-10 14:04:45 +02:00
Yu Watanabe
d7b217f2a9 mount-tool: honor arg_canonicalize for ACTION_UMOUNT path_is_absolute() check too (#37398)
Split out from #36337
2025-05-10 03:22:20 +09:00
Yu Watanabe
ef12eadfc8 core/bpf: drop old kernels support (#37151) 2025-05-10 03:13:42 +09:00
Yu Watanabe
6a04c1e518 udev: sort queued events by their seqnum
Unfortunately, the kernel may send events in a random order:
```
[   25.769624] systemd-udevd[194]: sdi7: Device is queued (SEQNUM=2843, ACTION=add)
[   25.769893] systemd-udevd[194]: sda5: Device is queued (SEQNUM=2842, ACTION=add)
[   25.770517] systemd-udevd[194]: sdi8: Device is queued (SEQNUM=2844, ACTION=add)
```
As you can see, udevd receives the event with SEQNUM=2843 earlier than
one with SEQNUM=2842.

Let's make queued events sorted, as our logic of determining which event
is ready for being processed assumes that queued events are sorted.
See event_build_dependencies().

Also, refuse to queue an event if another event with the same seqnum is
already queued.
2025-05-10 02:44:54 +09:00
Yu Watanabe
e8f017c421 udev: drop event_is_blocked()
As now it is a trivial wrapper of event_build_dependencies().
2025-05-10 02:41:29 +09:00
Yu Watanabe
f8b1d4fdfb udev: refactoring for managing events for locked block devices
Previously, when an event for block device is queued or an inotify event
for a block device is triggered, all queued events were checked by
event_queue_assume_block_device_unlocked(), and its cost may be huge
on early boot stage.

This makes locked events are managed in separated prioq and hashmap,
to reduce the cost of event_queue_assume_block_device_unlocked(),
which is now renamed to manager_requeue_locked_events_by_device().

This also changes the clockid of timer events for requeueing and
timeout of retry from CLOCK_BOOTTIME to CLOCK_MONOTONIC. Otherwise,
if the system suspend while an event is locked, the event may be
requeued immediately after come back from the suspend and timed out.
2025-05-10 02:41:10 +09:00
Yu Watanabe
b112a676d5 udev: several cleanups for managing events (#37384)
Mostly no functional changes, just refactoring.
2025-05-10 02:30:25 +09:00
Mike Yuan
b3cfee2f5d mount-tool: honor arg_canonicalize for ACTION_UMOUNT path_is_absolute() check too
Follow-up for 4e24796b5a
2025-05-09 18:39:51 +02:00
Mike Yuan
3cea9c403c core/mount: remove unused temporary variable 2025-05-09 18:39:37 +02:00
Luca Boccassi
b6c3fc750a boot: skip shim-specific logic when running with new shim
Since shim 16 the plain BS->LoadImage() will just work (TM), we do not need
anymore to set up manual overrides and manually call in the shim-specific
lock protocol or to set shim-specific EFIVAR to make addons work or to load
shim-signed kernels.

Check if the new protocol added in v16 is present, and if so, skip
all that. Once versions < 16 are no longer supported/revoked, all
the code can be dropped entirely.
2025-05-09 17:07:14 +01:00
Yu Watanabe
dcd2ad2314 udev: move error handling in event_requeue() to caller
Also, remove udev database on failure.
2025-05-10 00:26:32 +09:00
Yu Watanabe
f694a527ac udev: split out device_broadcast_on_error() 2025-05-10 00:26:32 +09:00
Yu Watanabe
e969ec1d51 sd-device: rename arguments
To make it consistent with its declaration and other function
prototypes.
2025-05-10 00:26:32 +09:00
Yu Watanabe
dc231d66ac udev: move timeout event sources from struct Event to struct Worker
The timeout event sources are enabled only when the event is being
processed by a worker, hence they are not necessary to be owned by the
event.

No effective functional change, just refactoring.
2025-05-10 00:26:32 +09:00