Commit Graph

84995 Commits

Author SHA1 Message Date
Chris Down
e21a431ec4 tests: ASSERT_SIGNAL: Do not allow parent to hallucinate it is the child
assert_signal_internal() returns 0 in two distinct cases:

1. In the child process (immediately after fork returns 0).
2. In the parent process, if the child exited normally (no signal).

ASSERT_SIGNAL fails to distinguish these cases. When a child exited
normally (case 2), the parent process receives 0, incorrectly interprets
it as meaning it is the child, and re-executes the test expression
inside the parent process. Goodness gracious!

This causes two severe test integrity issues:

1. False positives. The parent can run the expression, succeed, and call
   _exit(EXIT_SUCCESS), causing the test to pass even though no signal
   was raised.
2. Silent truncation. The _exit() call in the parent terminates the test
   runner prematurely, preventing subsequent tests in the same file from
   running.

Example of the bug in action, from #39674:

    ASSERT_SIGNAL(fd_is_writable(closed_fd), SIGABRT)

This test should fail (fd_is_writable does not SIGABRT here), but with
the bug, the parent hallucinated being the child, re-ran the expression
successfully, and exited with success.

Fix this by refactoring assert_signal_internal() to be much more strict
about separating control flow from data.

The signal status is now returned via a strictly typed output parameter,
guaranteeing that determining whether we are the child is never
conflated with whether the child exited cleanly.
2025-11-20 02:40:07 +08:00
Chris Down
d759ed527c tests: ASSERT_SIGNAL: Ensure sanitisers do not mask expected signals
ASAN installs signal handlers to catch crashes like SIGSEGV or SIGILL.
When these signals are raised, ASAN traps them, prints an error report,
and then typically terminates the process with a different signal (often
SIGABRT) or a non-zero exit code.

This interferes with ASSERT_SIGNAL when checking for specific crash
signals (for example, checking that a function raises SIGSEGV). In such
a case, the test harness sees the ASAN termination signal rather than
the expected signal, causing the test to fail.

Fix this by resetting the signal handler to SIG_DFL in the child process
immediately before executing the test expression. This ensures the
kernel kills the process directly with the expected signal, bypassing
ASAN's interceptors.
2025-11-20 02:40:07 +08:00
Chris Down
39adecfcd8 tests: ASSERT_SIGNAL: Stop exit codes from masquerading as signals
When a child process exits normally (si_code == CLD_EXITED),
siginfo.si_status contains the exit code. When it is killed by a signal
(si_code == CLD_KILLED or CLD_DUMPED), si_status contains the signal
number.  However, assert_signal_internal() returns si_status blindly.
This causes exit codes to be misinterpreted as signal numbers.

This allows failing tests to silently pass if their exit code
numerically coincides with the expected signal. For example, a test
expecting SIGABRT (6) would incorrectly pass if the child simply exited
with status 6 instead of being killed by a signal.

Fix this by checking si_code. Only return si_status as a signal number
if the child was actually killed by a signal (CLD_KILLED or CLD_DUMPED).
If the child exited normally (CLD_EXITED), return 0 to indicate that no
signal occurred.
2025-11-20 02:40:07 +08:00
Chris Down
408e8d361f tests: Avoid variable shadowing in ASSERT_SIGNAL
The ASSERT_SIGNAL macro uses a fixed variable name, `_r`. This prevents
nesting the macro (like ASSERT_SIGNAL(ASSERT_SIGNAL(...))), as the inner
instance would shadow the outer instance's variable.

Switch to using the UNIQ_T helper to generate unique variable names at
each expansion level. This allows the macro to be used recursively,
which is required for upcoming regression tests regarding signal
handling logic.
2025-11-19 20:31:57 +08:00
Daan De Meyer
3f0fc93219 tools: Add script to detect unused symbols in libshared
Symbols exported by libshared can't get pruned by the linker, so
every unused exported symbol is effectively dead code we ship to users
for no good reason. Let's add a script to analyze how many such symbols
we have.

We also add a meson test to run the script on all of our binaries.
Since it detects unused symbols and still has a few false positives,
don't enable the test by default similar to the clang-tidy tests.

The script was 100% vibe coded by Github Copilot with Claude Sonnet 4.5
as the model.

Current results are (without the unused symbols list):

Analysis of libsystemd-shared-259.so
======================================================================
Total exported symbols: 4830
  (excluding public API symbols starting with 'sd_')
Used symbols: 4672
Unused symbols: 158
Usage rate: 96.7%
2025-11-19 13:14:15 +01:00
Daan De Meyer
4186aad374 libudev: Don't pull in libshared_static
- Move devices-nodes.c to src/basic as it's super trivial anyway
- Duplicate udev_queue_is_empty() in libudev-util.c as it's trivial
  anyway.
2025-11-19 13:14:15 +01:00
Christoph Anton Mitterer
6077791b3a man: use prefix number that matches the general suggestion
`systemd.network(5)` recommends “that each filename is prefixed with a number
smaller than "70" (e.g.  10-eth0.network)”.

Reduce that used by the example accordingly, but stay above the number (`50`)
used in the earlier example for static configuration, so that would take
precedence over the dynamic one if both match for the same network.
2025-11-19 14:13:19 +09:00
Luca Boccassi
6cb76f9e95 Improve systemd-analyze man page and bash completion (#39778)
This updates example output in systemd-analyze's man page after the
tool's output was changed in a previous commit.

Additionally bash completion is added for `systemd-analyze filesystems`
and improved for `systemd-analyze calendar`.
2025-11-18 22:54:01 +00:00
Simon Barth
a049825708 shell-completion: bash: Add systemd-analyze calendar options
Add completion for the systemd-analyze calendar options --iterations and
--base-time.
2025-11-18 23:05:02 +01:00
Zbigniew Jędrzejewski-Szmek
c7c457b2fb User and group error messages (#39783)
I'm using separate commit here because this changes are a bit finicky.
2025-11-18 19:39:57 +01:00
Zbigniew Jędrzejewski-Szmek
970c29b6b6 networkd: use STRERROR_{USER,GROUP} 2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
29d26ebe9a nspawn,vmspawn: improve errors for unknown users and groups 2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
f3f933ee92 login: use STREROR_USER helper 2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
718578b96d creds: improve message about unknown user
Before:
$ build/systemd-creds --uid=asdf
Failed to resolve user 'asdf': No such process
Now:
$ build/systemd-creds --uid=asdf
Failed to resolve user 'asdf': Unknown user
2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
a50fdf611c core: improve messages about unknown users and groups
$ sudo build/systemd-run --uid=asdf whoami
$ journalctl -e
(whoami)[1007784]: run-p1007782-i5200512.service: Failed to determine user credentials: No such process
(whoami)[1007784]: run-p1007782-i5200512.service: Failed at step USER spawning /usr/sbin/whoami: No such process
systemd[1]: run-p1007782-i5200512.service: Main process exited, code=exited, status=217/USER
systemd[1]: run-p1007782-i5200512.service: Failed with result 'exit-code'.

Now:
(whoami)[1013204]: run-p1013202-i5205932.service: Failed to determine credentials for user 'asdf': Unknown user
(whoami)[1013204]: run-p1013202-i5205932.service: Failed at step USER spawning /usr/sbin/whoami: Invalid argument
systemd[1]: run-p1013202-i5205932.service: Main process exited, code=exited, status=217/USER
systemd[1]: run-p1013202-i5205932.service: Failed with result 'exit-code'.
2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
d92e47a093 run: improve log message for unknown user/group
Before:
$ sudo build/systemd-run --scope --uid=asdf whoami
Failed to resolve user asdf: No such process
Now:
$ sudo build/systemd-run --scope --uid=asdf whoami
Failed to resolve user 'asdf': Unknown user
2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
f436664881 tmpfiles: improve error message for missing user/group
From a boot with a dracut initrd:
systemd-tmpfiles[242]: /usr/lib/tmpfiles.d/tpm2-tss-fapi.conf:2: Failed to resolve user 'tss': No such process
systemd-tmpfiles[242]: Failed to parse ACL "default:group:tss:rwx", ignoring: Invalid argument
systemd-tmpfiles[242]: /usr/lib/tmpfiles.d/tpm2-tss-fapi.conf:4: Failed to resolve user 'tss': No such process
systemd-tmpfiles[242]: Failed to parse ACL "default:group:tss:rwx", ignoring: Invalid argument
systemd-tmpfiles[242]: /usr/lib/tmpfiles.d/tpm2-tss-fapi.conf:6: Failed to resolve group 'tss': No such process
systemd-tmpfiles[242]: /usr/lib/tmpfiles.d/tpm2-tss-fapi.conf:7: Failed to resolve group 'tss': No such process
2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
6e6e96f628 udev: define a generic helper to print messages about unknown users and groups
We cannot just use %m, because strerror returns a confusing error message
for ESRCH or ENOEXEC. udev code was doing a good job, but the error handling
was very verbose. Let's encapsulate the customized error messages in a
helper.

No functional change, except that the error messages have a slightly different
form now. The old messages were a bit better, but we don't have as much
flexibility in the new scheme. "Failed to resolve user 'foo': Unknown user"
should be good enough.
2025-11-18 16:23:29 +01:00
Frantisek Sumsal
c3d432a3d2 test: wait for a process ID instead of job ID
Since depending on job control turned out to be flaky [0], let's just
explicitly wait for a process ID instead.

Follow-up for 3849b0701a.
Resolves: #39543

[0] https://github.com/systemd/systemd/issues/39543#issuecomment-3529418583
2025-11-18 15:18:00 +00:00
Daan De Meyer
09ee7040c8 mkosi: Add sanitizer libraries to the CentOS/Fedora tools tree 2025-11-18 15:07:49 +01:00
Armin Brauns
d31af45552 NEWS: fix typo 2025-11-18 13:00:24 +00:00
Zbigniew Jędrzejewski-Szmek
e8a7722eec tree-wide: fix log messages using %m without an errno 2025-11-18 12:27:59 +01:00
Zbigniew Jędrzejewski-Szmek
4a3d57a47a network: gracefully disable resolve hook when socket is disabled
systemd-networkd cannot create the directory /run/systemd/resolve.hook/. Even
if the directory exists, it is not owned by systemd-network user/group, so
systemd-networkd cannot create socket file in the directory. Hence, if the
systemd-networkd-resolve-hook.socket unit is disabled, networkd fails to open
the varlink socket, and fail to start:

  systemd-networkd[1304645]: Failed to bind to systemd-resolved hook Varlink socket: Permission denied
  systemd-networkd[1304645]: Could not set up manager: Permission denied
  systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
  systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
  systemd[1]: Failed to start systemd-networkd.service - Network Management.

If the socket unit is disabled, that should mean the system administrator wants
to disable the feature. Let's not try to setup the varlink socket in that case.

Now the resolve hook feature can be toggled by enabling/disabling the socket
unit, let's drop the $SYSTEMD_NETWORK_RESOLVE_HOOK environment variable.

Follow-up for a7fa29b1b5.
Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-11-18 12:26:07 +01:00
Daan De Meyer
7e5a07c24a Various documentation updates 2025-11-18 10:09:19 +00:00
Mike Yuan
d22139ad71 user-record: use clzll() instead of clzl() for uint64_t 2025-11-18 09:49:01 +09:00
Yu Watanabe
031963fb16 core/unit: unit_process_job() tweaks (#39753) 2025-11-18 08:32:59 +09:00
Mike Yuan
bcf95c4116 labeler: match the whole tree of shell-completion/ 2025-11-18 08:26:16 +09:00
Simon Barth
62aba7c5cd shell-completion: bash: Add systemd-analyze filesystems 2025-11-17 23:40:58 +01:00
Simon Barth
ceb67d42f5 man: Fix systemd-analyze exit-status example output
The output of `systemd-analyze exit-status` changed in commit
e04ed6db6b, so that the exit-status class
for EXIT_SUCCESS and EXIT_FAILURE is "libc" instead of "glibc".

This commit makes the example output in the man-page match the actual
output again.
2025-11-17 23:37:46 +01:00
Luca Boccassi
d810cfcc5a meson: bump version to v259~rc1 2025-11-17 18:36:12 +00:00
Luca Boccassi
9ede3c125a meson: bump library sonames for v259~rc1 2025-11-17 18:36:12 +00:00
Luca Boccassi
c076689342 NEWS: finalize time and place 2025-11-17 18:36:12 +00:00
Luca Boccassi
2389784079 NEWS: update contributors list 2025-11-17 18:36:12 +00:00
Luca Boccassi
8ca3935118 NEWS: copy yet again sysvinit scripts removal announcement
Soon (TM)
2025-11-17 18:36:12 +00:00
Mike Yuan
aea6c4b53f core/unit: modernize unit_process_job() a bit
* Inline one condition
* Annotate boolean args with names
2025-11-17 19:30:00 +01:00
Yu Watanabe
92a224c9b4 musl: gracefully disable utmp support (#39775) 2025-11-18 03:29:34 +09:00
Mike Yuan
2334953a49 core/unit: always propagate reload_result as job result, even if state is unexpected
The end state of unit shouldn't have any impact on reload job, as
either way the reload operation has been aborted.
2025-11-17 19:26:11 +01:00
Mike Yuan
a5b1a79461 core/unit: mark running reload job as canceled if the unit deactivated
The semantics of reload is that the service updates its extrinsic state
and continues execution. If it actually deactivated we shouldn't
spuriously notify the caller that reload succeeded.
2025-11-17 19:26:11 +01:00
Mike Yuan
7cb0030f6c core/unit: no need to handle intermediate job types in unit_process_job()
Installed jobs are always collapsed, i.e. can only be of types
accepted by job_run_and_invalidate() modulo JOB_NOP which is
stored in Unit.nop_job (if any). Let's trim the unreachable
branches.
2025-11-17 19:25:41 +01:00
Yu Watanabe
bd3fc5c539 Revert "musl: utmpx: add several missing definitions"
This reverts commit 3ae7d8fd87.

Now utmp support is always disabled when building with musl,
and all definitions are unused in that case. Let's remove it.
2025-11-18 03:06:02 +09:00
Yu Watanabe
1a2ba82421 musl: meson: gracefully disable utmp support
musl only provides fake utmp functions, and these are not usable.
Let's disable the feature when building with musl.
2025-11-18 02:54:20 +09:00
Yu Watanabe
0ecff59065 Revert "musl: meson: add libutmps support"
This reverts commit bf9bc5beb0.

libutmps does not support utmpxname(), the function always fails
with ENOSYS, and always uses their own file.
However, our code relies on the funtion needs to succeed.

Let's revert the change now, and revisit later when musl users
request to support libutmps.
2025-11-18 02:54:20 +09:00
Luca Boccassi
00ed239a7b repart: prefix LUKS superblock label with "luks-" by default, and add explicit VolumeLabel= setting to control it (#39713)
Alternative-to: #39536
2025-11-17 17:46:39 +00:00
Yu Watanabe
1b9f3473c1 NEWS: menton future removal of SysV support and requirement bump 2025-11-18 02:40:22 +09:00
Yu Watanabe
43a1690e45 Split out script for musl builds (#39758) 2025-11-18 02:17:05 +09:00
Philip Withnall
69f1a1d5ed docs: Update MEMORY_PRESSURE to mention recent improvements in GLib
See https://gitlab.gnome.org/GNOME/glib/-/issues/2931 for the changes in
GLib upstream. Using `GMemoryMonitor` is now more compliant with the
systemd recommended approach, but it needs further work to read the
recommended environment variables rather than unconditionally accessing
the per-cgroup PSI kernel file directly.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-11-17 18:05:41 +01:00
Lennart Poettering
0712316e8e fs-util: enable automatic access mode logic in xopenat() 2025-11-18 01:31:49 +09:00
Yu Watanabe
07910c73b0 test: modernize test-log and add test cases for log_format_iovec() (#39750) 2025-11-18 01:31:02 +09:00
Zbigniew Jędrzejewski-Szmek
18dcc08c65 ci: whitespace fix 2025-11-17 17:02:23 +01:00
Zbigniew Jędrzejewski-Szmek
31d3b96293 musl: split out script to setup build
This makes it easier to set up a local build with musl:
$ tools/setup-musl-build.sh build-meson
$ ninja -C build-meson
2025-11-17 17:02:23 +01:00