Commit Graph

5914 Commits

Author SHA1 Message Date
Ivan Kruglov
738a47fd98 tests: fix TEST-74-AUX-UTILS.varlinkctl.sh (#37562)
per Daan's explanation:
other subtests running as testuser apparently use systemd-run --user
--machine testuser@.host which turns user tracking in logind into "by
pin" mode. when the last pinning session exits it terminates the user.
2025-05-22 22:40:30 +01:00
Zbigniew Jędrzejewski-Szmek
61d78f1788 Restore compatibility for coredump --backtrace (#37559) 2025-05-22 13:40:29 +02:00
Matteo Croce
6288739eaf networkd: print a meaningful error on failure
test_keep_configuration_on_restart() works, but the error printed is
misleading because self.assertNotEmpty() doesn't exist.

Add a working assert statement so, when the unmanaged interface is
altered, the test fails with a meaningful error, like:

        ### ip monitor dev unmanaged0 BEGIN
        222:33::/64 proto kernel metric 256 pref medium
        FAIL
        [...]
        Traceback (most recent call last):
          File "/work/src/test/test-network/systemd-networkd-tests.py", line 5085, in test_keep_configuration_on_restart
            self.assertEqual(line, '')
        AssertionError: '222:33::/64 proto kernel metric 256 pref medium' != ''
        - 222:33::/64 proto kernel metric 256 pref medium

While at it, strip the trailing newline so we can print easily the
string (and in future build more a robust regexp which uses the $ token)
2025-05-22 09:33:39 +02:00
Zbigniew Jędrzejewski-Szmek
ded0aac389 coredump: restore compatibility with older patterns
This was broken in f45b801551. Unfortunately
the review does not talk about backward compatibility at all. There are
two places where it matters:
- During upgrades, the replacement of kernel.core_pattern is asynchronous.
  For example, during rpm upgrades, it would be updated a post-transaction
  file trigger. In other scenarios, the update might only happen after
  reboot. We have a potentially long window where the old pattern is in
  place. We need to capture coredumps during upgrades too.
- With --backtrace. The interface of --backtrace, in hindsight, is not
  great. But there are users of --backtrace which were written to use
  a specific set of arguments, and we can't just break compatiblity.
  One example is systemd-coredump-python, but there are also reports of
  users using --backtrace to generate coredump logs.

Thus, we require the original set of args, and will use the additional args if
found.

A test is added to verify that --backtrace works with and without the optional
args.
2025-05-21 23:45:14 +02:00
Matteo Croce
bcb9e72b6b networkd: ensure that unmanaged interfaces aren't touched
Extend the test_keep_configuration_on_restart in order to check
that the unmanaged interface isn't altered in any way.
2025-05-22 03:04:40 +09:00
Lennart Poettering
88d2cb3668 test: add simple integration test for delegation feature 2025-05-20 23:00:53 +02:00
Matteo Croce
6479204e56 networkd: add test to ensure that untracked addresses are kept
Users can alter the network configuration manually, but networkd should
not interfere with manually set addresses and routes.
2025-05-20 14:14:53 +02:00
Luca Boccassi
6946eed3fa core: Also refresh confext extensions when reloading notify-reload service (#33995)
`ExtensionImages=` and `ExtensionDirectories=` now let you specify
vpick-named extensions; however, since they just get set up once when
the service is started, you can't see newer versions without restarting
the service entirely. Here, also reload confext extensions when you
reload a service. This allows you to deploy a new version of some
configuration and have it picked up at reload time without interruption
to your workload.

Right now, we would only reload confext extensions and leave the sysext
ones behind, since it didn't seem prudent to swap out what is likely
program code at reload. This is made possible by only going for the
`SYSTEMD_CONFEXT_HIERARCHIES` overlays (which only contains `/etc`).

This PR:
- Adjusts `service.c` to also refresh extensions when needed. 
- Adds integration tests to check that a confext reload actually
occurred.
- Adds to the `systemd.exec` man pages to document this behavior.

This is a follow up to #24864 and #31364. Thank you to @bluca and
@goenkam for help in getting this up.
2025-05-20 11:27:34 +01:00
maia x.
3998b30a04 test: check reloading notify-reload service refreshes vpick extensions
In TEST-50-DISSECT.dissect, this adds the following cases:
- testservice-50g: vpick extension in ExtensionDirectories
- testservice-50h: vpick extension in ExtensionImages
- testservice-50i: ExtensionDirectories + RootImage
- testservice-50j: ExtensionDirectories + RootDirectory
2025-05-19 13:36:21 +01:00
Yu Watanabe
a31edb4e71 TEST-07-PID1: drop journal message flood test
This partially reverts f9b186c21a.

The test case is unstable, and fills debugging logs after journald
is restarted.
2025-05-16 22:24:54 +09:00
Mike Yuan
7762e9bbb2 core: always enable CPU accounting; cgtop: drop cgv1 handling (#37448) 2025-05-15 14:41:07 +02:00
Tommy Unger
ef3a0478bb test: write file from systemd service in transient unit
This integration test demonstrates that a containerized systemd instance can
write to a bind mounted file observable to the host. Specifically, the bash
script uses systemd-run to start a systemd instance as a transient unit
container. This systemd-run command bind mounts a directory the container will
share with the host, and runs an internal service which creates and writes to a
file from the container's view of this directory. When finished writing, the
service runs the exit target, terminating the internal systemd instance, and
ending the lifetime of the container.

The script waits for the container to finish running, then verifies that the
expected file contents were written on the host side of the filesystem mount.

This test employs a workaround, creating an unmasked procfs mount on the host
which enables the privileged guest to create its own mounts internally. This
may indicate a systemd bug, as the privileged container should not rely on
the existence of an unmasked procfs on the host in order to mount its own
filesystems internally.
2025-05-15 11:33:23 +02:00
Mike Yuan
29da53dde3 core: always enable CPU accounting
Our baseline is v5.4 and cgroup v2 is enforced now,
which means CPU accounting is cheap everywhere without
requiring any controller, hence just remove the directive.
2025-05-15 02:19:16 +02:00
Daan De Meyer
17b0d165f6 capability-util: Ignore unknown capabilities instead of aborting
capability_quintet_mangle() can be called with capability sets
containing unknown capabilities. Let's not crash when this is the
case but instead ignore the unknown capabilities.

Fixes d5e12dc75e
2025-05-15 03:33:32 +09:00
Yu Watanabe
eba8cc8981 integration-tests: several cleanups (#37394) 2025-05-15 01:45:10 +09:00
Lennart Poettering
4fefc10c0d validatefs: fix checks on file systems backed by multiple devices (i.e. verity) (#37434)
Fixes #37157
2025-05-14 17:53:06 +02:00
Lennart Poettering
c019ad849f test: attempt to fix resolved wait-online testcase
Fixes: #37430
2025-05-14 16:09:32 +02:00
Lennart Poettering
61b15b78e5 ci: extend validatefs testcase to validate verity partitions 2025-05-14 15:44:54 +02:00
Yu Watanabe
18609909d9 TEST-73-LOCALE: skip lv keymap and friends
The following failure should be in libxkbcommon and/or sanitizer.
There is nothing we can do here. Let's skip it.

```
TEST-73-LOCALE.sh[3733]: + assert_rc 0 localectl set-keymap lv
TEST-73-LOCALE.sh[6699]: + set +ex
TEST-73-LOCALE.sh[6700]: Failed to set keymap: Remote peer disconnected
TEST-73-LOCALE.sh[6703]: FAIL: expected: '0' actual: '1'
TEST-73-LOCALE.sh[157]: + rm -f /etc/dbus-1/system.d/systemd-localed-read-only.conf
[FAILED] Failed to start TEST-73-LOCALE.service - TEST-73-LOCALE.
```
```
==3719==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fa51f161000 at pc 0x7fa521250be4 bp 0x7ffe49130a80 sp 0x7ffe49130240
READ of size 19126 at 0x7fa51f161000 thread T0
    #0 0x7fa521250be3 in strndup (/usr/lib/clang/20/lib/x86_64-redhat-linux-gnu/libclang_rt.asan.so+0x50be3) (BuildId: aa6231e817f72469c44a6c6cee9f0694a87db7fb)
    #1 0x7fa51f128325  (/lib64/libxkbcommon.so.0+0x1c325) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #2 0x7fa51f121952  (/lib64/libxkbcommon.so.0+0x15952) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #3 0x7fa51f123d3a  (/lib64/libxkbcommon.so.0+0x17d3a) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #4 0x7fa51f117c86  (/lib64/libxkbcommon.so.0+0xbc86) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #5 0x7fa51f12548f  (/lib64/libxkbcommon.so.0+0x1948f) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #6 0x7fa51f125c9e  (/lib64/libxkbcommon.so.0+0x19c9e) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #7 0x7fa51f126a59  (/lib64/libxkbcommon.so.0+0x1aa59) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #8 0x7fa51f12cec6  (/lib64/libxkbcommon.so.0+0x20ec6) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #9 0x7fa51f12e3c2  (/lib64/libxkbcommon.so.0+0x223c2) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #10 0x7fa51f12a4e5 in xkb_keymap_new_from_names (/lib64/libxkbcommon.so.0+0x1e4e5) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #11 0x5574dd63f864 in verify_xkb_rmlvo /usr/src/debug/systemd/src/locale/xkbcommon-util.c:69:14
(snip)
```
2025-05-14 02:28:27 +09:00
Yu Watanabe
7ded7cfb7f TEST-73-LOCALE: drop unnecessary workaround
It should be fixed by 157d5b5c30.
2025-05-14 02:28:27 +09:00
Yu Watanabe
71078275e8 integration-tests: adjust priorities
When running with sanitizers:
```
26/95 systemd:integration-tests / TEST-21-DFUZZER                          OK 1517.75s
40/95 systemd:integration-tests / TEST-85-NETWORK-NetworkdDHCPClientTests  OK  779.18s
42/95 systemd:integration-tests / TEST-04-JOURNAL                          OK  716.17s
```
and without sanitizers:
```
44/95 systemd:integration-tests / TEST-85-NETWORK-NetworkdDHCPClientTests  OK  730.33s
29/95 systemd:integration-tests / TEST-64-UDEV-STORAGE-simultaneous_events OK  701.49s
40/95 systemd:integration-tests / TEST-04-JOURNAL                          OK  348.05s
```

So, let's set higher priorities only on these tests.
2025-05-14 02:28:27 +09:00
Yu Watanabe
59dd650501 TEST-21-DFUZZER: skip test when no sanitizer is enabled 2025-05-14 02:28:22 +09:00
Lennart Poettering
f9b186c21a test: add test for "systemd-run -v" 2025-05-13 15:39:57 +02:00
Lennart Poettering
80ab0e04d3 test: add sync request until all logging about the test unit is done 2025-05-13 14:42:34 +02:00
Ivan Kruglov
f08c134661 tests: tests for io.systemd.manager.Describe 2025-05-13 01:55:15 -07: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
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
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
Yu Watanabe
3e320dc608 test-execute: add test case for PrivateTmp=disconnected 2025-05-11 03:33:02 +09:00
Yu Watanabe
0c93e66386 udev: use userdb_by_name()/groupdb_by_name()
Prompted by https://github.com/systemd/systemd/pull/37294#discussion_r2068141968.
2025-05-09 12:10:28 +09:00
Yu Watanabe
1e35d21ab0 udevadm-trigger: parse all arguments before doing anything (#37293) 2025-05-09 12:09:18 +09:00
David Tardon
f849e85221 test: extend udevadm coverage test a bit 2025-05-09 09:53:50 +09:00
Yu Watanabe
75e906a406 TEST-17-UDEV: extend test cases for udevadm control --start-exec-queue/--stop-exec-queue 2025-05-09 08:54:26 +09:00
Yu Watanabe
9999e8b409 TEST-17-UDEV: drop needless numbering
The subtest was renamed from TEST-17-UDEV.10.sh.
Let's also drop the numbering from function name and interface name.

Follow-up for 40959dcc02.
2025-05-09 08:54:26 +09:00
Mike Yuan
66a3b69440 test: add test cases for ExecStart= via-shell prefix 2025-05-07 18:32:20 +02:00
Nick Rosbrook
0e0d3ed93a networkd-test: stop resolved socket units in setUpModule()
Avoid warnings about the socket units when stopping systemd-resolved.
2025-05-01 01:52:28 +01:00
Yu Watanabe
366dd4a662 wait-online: handle varlink connection errors while waiting for DNS (#37283)
Currently, if systemd-networkd-wait-online is started with --dns, and
systemd-resolved is not running, it will exit with an error right away.
Similarly, if systemd-resolved is restarted while waiting for DNS
configuration, systemd-networkd-wait-online will not attempt to
re-connect, and will potentially never see subsequent DNS
configurations.

Improve this by adding socket units for the systemd-resolved varlink
servers, and re-establish the connection in systemd-networkd-wait-online
when we receive `SD_VARLINK_ERROR_DISCONNECTED`.
2025-05-01 01:55:04 +09:00
Luca Boccassi
b16e6fd767 busctl: validate argvs on get-property/set-property too
Otherwise passing invalid data means asserts get hit instead of
handling it gracefully. Other verbs already do the same checks.

busctl get-property org.freedesktop.systemd1 '*' org.freedesktop.systemd1.Manager Version
Assertion 'object_path_is_valid(path)' failed at src/libsystemd/sd-bus/bus-message.c:562, function sd_bus_message_new_method_call(). Aborting.
Aborted (core dumped)
2025-05-01 01:53:08 +09:00
Yu Watanabe
da9d75e0c6 TEST-17: drop unnecessary $PATH setting
My local setting was unintentionally inserted by the commit
7cb4508c5a.
2025-05-01 00:27:51 +09:00
Nick Rosbrook
3ea04a9432 test: add a test for resolved and wait-online interactions
Specifically, add a test case that ensures systemd-networkd-wait-online --dns
is robust against (a) systemd-resolved absence, and (b) systemd-resolved
restarts.
2025-04-30 11:12:15 -04:00
Luca Boccassi
a3dc2bbf96 test: use /run/ for test configuration, not /etc/
In case of failures we don't want to leave an image with intermediate
test configuration, as images are reused across multiple tests

Follow-up for edca63a632
2025-04-25 06:13:43 +09:00
Daan De Meyer
45f63c3db7 test: Add custom signal handlers to integration test wrapper script
meson will send SIGTERM if the test gets stuck and hits the timeout,
in which case we still want to do log saving and analysis, so let's
add some signal handlers which allow us to do that.

This won't be very useful until https://github.com/mesonbuild/meson/pull/14513
lands, since we only get half a second from meson to handle SIGTERM
before it sends SIGKILL, but let's land this already so we immediately
start taking advantage of the meson fix once it lands.
2025-04-25 06:11:43 +09:00
Yu Watanabe
28659e1eac TEST-82-SOFTREBOOT: add test case for uevents generated during soft-reboot 2025-04-23 10:48:51 +09:00
Lennart Poettering
edca63a632 test: add integration test for concurrency limits 2025-04-22 18:56:01 +02:00
Daan De Meyer
505492d61c udev: serialize queued events on exit (#37047)
Previously, all queued events were discarded on exit, hence several
events might not be processed by udevd when it is restarted. Such
situation especially easily happens on switching root.

This makes queued events serialized on exit, and deserialized in the
next invocation. Hence, no events should be lost during restarting
udevd.

This is important with the several aspects. Basically
systemd-udev-trigger.service (re)triggers all devices anyway after
switching root, But the service may be disabled or modified by admin.
Moreover, the service produces only 'add' events, and thus the service
cannot cover events with other actions generated by the kernel during
switching root. Also, the userspace triggered events may not contain
some parameters compared with events triggered by the kernel.
2025-04-22 10:54:25 +02:00
Yu Watanabe
acd65ba1cd Revert "tests: add test for StartAuxiliaryScope()"
This reverts commit fd7fd59b6d.

The DBus method StartAuxiliaryScope() will be removed in the next
commit.
2025-04-22 09:00:19 +09:00
Yu Watanabe
7137e0bf24 ssh-proxy: use % as an alternative separator
Since OpenSSH 10.0p1, specifically
https://anongit.mindrot.org/openssh.git/commit/?id=487cf4c18c123b66c1f3f733398cd37e6b2ab6ab
ssh refuses comma in hostname by default.

Let's use % as an alternative separator.

Follow-up for defd5060d6.
2025-04-20 15:15:54 +02:00
Yu Watanabe
a4f003bac0 TEST-17-UDEV: add test case for queued events serialization/deserialization 2025-04-19 01:51:59 +09:00
Matthieu Baerts (NGI0)
defd5060d6 ssh-proxy: add scp and rsync support
ssh-generator and ssh-proxy are great features, it is very handy to be
able to do:

    ssh vsock/1

But, because of the '/' used as a separator, scp and rsync don't
interpret 'vsock/<CID>' as a hostname, e.g.

    $ scp /etc/machine-id vsock/2222:.
    cp: cannot create regular file 'vsock/2222:.': No such file or directory

    $ rsync /etc/machine-id vsock/2222:.
    rsync: [Receiver] change_dir#3 "(...)/vsock" failed: No such file or directory (2)
    rsync error: errors selecting input/output files, dirs (code 3) at main.c(829) [Receiver=3.4.1]

An alternative is to use ',' as separator, e.g.

    $ scp /etc/machine-id vsock,2222:.

This is what is being suggested here. The names with '/' are kept not to
break anything here.

Others are possible: '%', '=', '#', '@', ':', etc. As mentioned in
commit 0abd510f7f ("ssh-proxy: add ssh ProxyCommand tool that can
connect to AF_UNIX + AF_VSOCK sockets"), it is better to avoid ':' as it
is already taken by SSH itself when doing sftp, and "@" is already taken
for separating the user name. '#' will cause some issues with some
shells like ZSH when quotes are not used.
2025-04-18 12:58:28 +02:00