6288 Commits

Author SHA1 Message Date
Lennart Poettering
1ceba02ad9 ci: split out nvpcr test, so that it runs before rest of pcrextend (#39915)
in pcrextend we destroy pcr 11, and if we are booted in a kernel that
has pcr11 sigs, we cannot use that signature anymore. hence, let's do
the nvpcr test first, before doing the pcrextend stuff.

Fixes: #39582
2025-11-26 12:24:57 +00:00
Yu Watanabe
1defd69d69 TEST-02-UNITTESTS: drop outdated comment
Follow-up for 741d59b326.
2025-11-25 22:52:10 +09:00
Daan De Meyer
32b10d0d28 TEST-88-UPGRADE: Stop resolved hook socket before downgrading
Otherwise it'll remain active and cause networkd to get started again
during the downgrade.
2025-11-25 11:49:31 +01:00
Lennart Poettering
77a1e2dec6 Revert "nspawn: Fix broken host links for container journals" 2025-11-24 16:34:00 +01:00
Daan De Meyer
d60206c49a meson: Still build libshared even if libmount is disabled (#39871)
Currently, if the libmount feature is disabled, we don't build libshared
and as a result skip building every other executable as well. Among
other things, this makes our nodeps CI builds kind of pointless since
hardly any code will be compiled.

Let's improve on the situation by making libmount properly optional in
libshared. Then, we only skip building the executables that actually
need libmount.
2025-11-24 14:05:29 +01:00
Daan De Meyer
7336f2c748 meson: Still build libshared even if libmount is disabled
Currently, if the libmount feature is disabled, we don't build
libshared and as a result skip building every other executable as
well. Among other things, this makes our nodeps CI builds kind of
pointless since hardly any code will be compiled.

Let's improve on the situation by making libmount properly optional
in libshared. Then, we only skip building the executables that
actually need libmount.
2025-11-24 13:09:41 +01:00
Yu Watanabe
f866ff3df8 tree-wide: replace tab with space, adjust missing or duplicated space 2025-11-24 12:45:06 +01:00
Chris Down
887f54adce nspawn: Add integration test for --link-journal 2025-11-21 21:04:34 +08:00
Frantisek Sumsal
3605b3ba87 timer: rebase last_trigger timestamp if needed
After bdb8e584f4 we stopped rebasing the
next elapse timestamp unconditionally and the only case where we'd do
that was when both last trigger and last inactive timestamps were empty.
This covered timer units during boot just fine, since they would have
neither of those timestamps set. However, persistent timers
(Persistent=yes) store their last trigger timestamp on a persistent
storage and load it back after reboot, so the rebasing was skipped in
this case.

To mitigate this, check the last_trigger timestamp is older than the
current machine boot - if so, that means that it came from a stamp file
of a persistent timer unit and we need to rebase it to make
RandomizedDelaySec= work properly.

Follow-up for bdb8e584f4.

Resolves: #39739
2025-11-20 09:47:11 +01:00
Quentin Deslandes
5b0e262f45 network: clear existing routes if Gateway= is empty in [Network]
Add support for an empty Gateway= in [Network] to clear the existing
routes. This change will allow users to remove the default route from a
drop-in file.
2025-11-20 07:16:26 +09:00
Zbigniew Jędrzejewski-Szmek
8d50438ba5 test/TEST-74-AUX-UTILS: fix racy check
We were getting a list of invocation IDs, picking one at random,
and then querying the unit. This is obviously racy.

TEST-74-AUX-UTILS.sh[2873]: + varlinkctl call /run/systemd/io.systemd.Manager io.systemd.Unit.List
                              '{"invocationID": "2052c9a5-7983-4f72-9910-c49e38c91dab"}'
TEST-74-AUX-UTILS.sh[3707]: Method call io.systemd.Unit.List() failed: io.systemd.Unit.NoSuchUnit

The complicated varlink + jq callout is replaced by a simple systemctl call.
I think that's better to avoid a complicated jq expression.

Fixes https://github.com/systemd/systemd/issues/38647.
2025-11-19 17:09:02 +00: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
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
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
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
Zbigniew Jędrzejewski-Szmek
93470f0451 Various comment and whitespace cleanups (#39740) 2025-11-17 16:52:38 +01:00
Zbigniew Jędrzejewski-Szmek
01100f15ad tree-wide: drop space after shell redirection ops
Those are all unary operators.
2025-11-17 16:50:50 +01:00
Lennart Poettering
0d24626631 test: add testcase for VolumeLabel= 2025-11-17 16:43:21 +01:00
Luca Boccassi
bc154d4c3e test: skip TEST-64-UDEV-STORAGE-simultaneous_events on Debian
It consistently fails with the new 6.17 kernel and nobody can
figure out why, so just disable it for now as it's just noise

Fixes https://github.com/systemd/systemd/issues/39552
2025-11-17 12:17:24 +00:00
Yu Watanabe
d7cf08b735 test-network: drop two overly verbose outputs
Follow-up for 7f9c0c31d2.
2025-11-16 22:15:44 +09:00
Yu Watanabe
3632d7322f test-network: set TimeoutStopFailureMode=abort when running with sanitizers
Hopefully this provides useful data for issue #39631.
2025-11-16 22:15:43 +09:00
Yu Watanabe
c43585bc30 Revert "test-network: disable several more sandbox features when running with sanitizers"
This reverts commit 454ce42305.

Unfortunately, it does not work.
2025-11-16 22:15:43 +09:00
Yu Watanabe
c9fc7eb87e nspawn: Prevent invalid UIDs propagating in bind mounts (#39729)
Commit 88fce09026 modified the
mount_bind() function, causing it to perform arithmetic on the uid_shift
parameter. However, it performs this arithmetic even when uid_shift was
UID_INVALID, which was not intended. This typically occurred when
mount_custom() was called for a simple bind mount without user
namespaces (and thus no rootidmap mount option).

This arithmetic (e.g., uid_shift + m->destination_uid) then wraps
around, resulting in the invalid ID 4294967295 ((uid_t)-1).

This bug manifests for users running systemd-nspawn with
--link-journal=host and --volatile=yes (but without --private-users),
causing systemd-tmpfiles to fail.

Make mount_bind() robust by checking if uid_shift is valid before using
it in arithmetic. If it is UID_INVALID, it defaults to a shift of 0 for
the ownership calculation, restoring correct behavior for plain bind
mounts while preserving the intended logic for ID-mapped mounts.

Fixes: #39714
2025-11-16 04:46:18 +09:00
Chris Down
bb49e719d9 test: Add nspawn regression test for --link-journal --volatile 2025-11-15 22:01:46 +08:00
Lennart Poettering
a719802ca3 test: add workaround for networkd downgrade issue 2025-11-15 07:52:42 +01:00
Lennart Poettering
a7fa29b1b5 networkd: add support for resolved hook for DHCP server
Let's synthesize DNS RRs for leases handed out by our DHCP server. This
way local VMs can have resolvable hostnames locally.

This does not implement reverse look ups for now. We can add this
later in similar fashion.
2025-11-15 07:52:42 +01:00
Luca Boccassi
f041d40dee test: always create networkd mock tmpfs for networkd-test.py
Match the behaviour of the other test classes that use sd-run and
always create the mock tmpfs runtime dirs.
This will be needed as the new resolve.hook directory won't exist
on boot but will be needed by the test case.
2025-11-15 07:48:29 +01:00
Lennart Poettering
3cd929f837 machined: implement resolve hook in machined
This basically implements nss-myhostname, but natively in
systemd-resolved, so that the logic becomes available also for clients
using the local DNS stub for resolution or the D-Bus or Varlink APIs.
2025-11-15 07:44:24 +01:00
Yu Watanabe
fe9bccb2b7 Make new sd-path configuration search functionality generic (#39684)
Reverts systemd/systemd#38680

After taking a closer look I'm not convinced by the approach, see below.

First of all, all other SD_PATH_SEARCH_* are either somewhat generic,
i.e. encode the common prefix for configurations, binaries, etc., or are
subdirectories under systemd/ hence in our own "domain". The
tmpfiles/sysctl/binfmt we don't prefix with "systemd" precisely because
the concept is generic and there're actually other impls of them. A
specific SD_PATH_SEARCH_SYSCTL doesn't fit into our existing scheme.
Instead something along the lines of "SEARCH_SYSTEM_CONFIGURATION" shall
be introduced, and consumers will just suffix
sysctl.d/tmpfiles.d/binfmt.d for the final result.

And secondly, I don't grok why systemd-sysctl now unnecessarily calls
into sd-path to obtain the fixed search path. None of our other tools do
that.

-----------

An alternate approach, SD_PATH_SYSTEM_SEARCH_CONFIGURATION, which does
exactly above, will be introduced instead. It provides a universal
interface for querying any system config with our idiomatic
/etc/:/run/:/usr/local/lib/:/usr/lib/ hierarchy.
2025-11-15 10:09:19 +09:00
Nick Rosbrook
40a6069f9a test: adjust timeouts for testcase_15_wait_online_dns
Do not set a timeout on the wait-online call, since there are timeout
calls later that will prevent the test from blocking forever. Increase
those timeout calls for slower CI runs.
2025-11-14 14:46:16 -05:00
Nick Rosbrook
be394fcaff test: increase timeout waiting for zone DS records setup
This test is flaky on the infrastructure due to this setup step timing
out. As a naive step, just increase the timeout to 60s.

Part 1 of #39602
2025-11-14 14:46:16 -05:00
Yu Watanabe
fd7d749494 core: add varlink Reload/Reexecute methods (#39561)
Same as the D-Bus ones
2025-11-15 04:17:01 +09:00
Nick Rosbrook
3d6eb1ed42 test: wait for interface to come online before checking DNS scopes
The current test is flaky because it creates a new interface definition,
calls networkctl reload, and then calls resolvectl show-cache. If
resolved has not received the changes and setup the DNS scopes for the
interface, show-cache will be empty for that interface.

Part 2 of #39602
2025-11-15 04:04:51 +09:00
Chris Down
7f9c0c31d2 sd-dhcp-server: Add Hostname= option to static leases
This adds a new `Hostname=` option to the [DHCPServerStaticLease]
section in .network files, allowing an administrator to assign a
specific hostname to a client receiving a static lease.

We automatically select the correct DHCP option to use based on the
format of the provided string:

- Single DNS labels are sent as Option 12.
- Names with multiple DNS labels are sent as Option 81 in wire format.

Fixes: #39634
2025-11-14 07:50:13 +09:00
Yu Watanabe
aec0e63a4f musl: test: several random fixlets for unit tests 2025-11-14 03:29:21 +09:00
Zbigniew Jędrzejewski-Szmek
dc04a884e0 systemd-path: add 'system-search-configuration'
This provides functionality to replace what was provided by the preceding
revert:

  $ build/systemd-path system-search-configuration --suffix=sysctl.d
  /etc/sysctl.d:/run/sysctl.d:/usr/local/lib/sysctl.d:/usr/lib/sysctl.d

The result is identical, but more generic, since by changing suffix we can also
get the answer for sysusers.d, tmpfiles.d, and any other of the directories
which follow the same general rule.
2025-11-13 14:11:11 +01:00
Luca Boccassi
55a1b36e91 core: add varlink Reload/Reexecute methods
Same as the D-Bus ones
2025-11-13 00:07:23 +00:00
Mike Yuan
397681405a TEST-03-JOBS: add test for TransactionsWithOrderingCycle 2025-11-12 23:47:39 +01:00
Yu Watanabe
19db9a99e6 systemctl: fix edit and cat verbs with --global flag (#39606)
The --global flag has been broken since commit 
d77d42ed3a, which added a
blanket restriction on acquiring D-Bus connections when
arg_runtime_scope is RUNTIME_SCOPE_GLOBAL. This was done to prevent
crashes, but inadvertently broke legitimate use cases like 'systemctl
edit --global' and 'systemctl cat --global'.

The issue is that verb_edit() and verb_cat() were unconditionally
calling acquire_bus(), which triggers the restriction and fails with
"--global is not supported for this operation."

This commit fixes the issue by making bus acquisition conditional,
following the same pattern used in verb_enable():

- Only acquire the bus when install_client_side() returns NO (i.e., for
system and user scopes)
- For client-side operations (--global, --root, etc.), skip bus
acquisition and use mangle_names() instead of expand_unit_names()
- Update find_paths_to_edit() and verb_cat() to handle NULL bus by
forcing client-side path lookups
- Skip bus-dependent checks (unit_is_masked, need_daemon_reload) when
bus is NULL

This allows both 'systemctl edit --global' and 'systemctl cat --global'
to work correctly by performing all operations client-side without
requiring a connection to the system or user manager.

Fixes #31272
2025-11-12 08:59:06 +09:00
gvenugo3
ebd222b1c8 systemctl: support --global and --root in edit and cat
Make bus acquisition conditional in verb_edit() and verb_cat(), following
the same pattern used in verb_enable(). When install_client_side() returns
non-zero (indicating --global, --root, offline, or similar scenarios), skip
acquiring a D-Bus connection and perform all operations client-side.

Changes:
- Only acquire bus when install_client_side() returns NO
- Use mangle_names() instead of expand_unit_names() in client-side mode
- Pass force_client_side flag based on bus availability
- Skip bus-dependent operations (need_daemon_reload, etc.) when bus is NULL

This allows 'systemctl edit --global' and 'systemctl cat --global' to work
correctly, fixing the regression introduced by commit d77d42ed3a.

Test cases added to verify:
- Creating and editing global user units with --runtime
- Reading global units with cat --global
- Proper detection and rejection of masked units in client-side mode
- Tests use /run/ instead of /etc/ for safer temporary testing

Fixes https://github.com/systemd/systemd/issues/31272
2025-11-11 10:00:29 -07:00
Frantisek Sumsal
b131e8d3a4 test: ignore EC from the second systemctl status -a as well
There is a TOCTOU in the `systemctl status` where a unit might change
its state during the initial ListUnitsByPatterns call and the subsequent
individual GetAll calls, which then makes the systemctl call fail even
if the unit that was originally pulled in was active/running:

[ 1922.040463] TEST-26-SYSTEMCTL.sh[117]: + systemctl status -a --state active,running,plugged
[ 1922.051423] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=ListUnitsByPatterns  cookie=1 reply_cookie=0 signature=asas error-name=n/a error-message=n/a
[ 1922.052501] systemd[1]: Sent message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 signature=a(ssssssouso) error-name=n/a error-message=n/a
[ 1922.052650] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1/unit/_2d_2emount interface=org.freedesktop.DBus.Properties member=GetAll  cookie=2 reply_cookie=0 signature=s error-name=n/a error-message=n/a
...
[ 1922.222061] systemd-hostnamed[424]: Idle for 30s, exiting.
...
[ 1922.224961] systemd[1]: systemd-hostnamed.service: Got notification message from PID 424: STOPPING=1, STATUS=Shutting down...
[ 1922.224983] systemd[1]: systemd-hostnamed.service: Changed running ->stop-sigterm
...
[ 1922.228984] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1/unit/systemd_2dhostnamed_2eservice interface=org.freedesktop.DBus.Properties member=GetAll  cookie=41 reply_cookie=0 signature=s error-name=n/a error-message=n/a
[ 1922.234402] systemd[1]: Sent message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=43 reply_cookie=41 signature=a{sv} error-name=n/a error-message=n/a

Since in this case we care mostly about the code paths the command
triggers, ignore its exit code as we do for the previous one.

Resolves: #39612
2025-11-10 21:31:09 +00:00
Frantisek Sumsal
6a05abb9b4 test: don't register short-living containers with machined
As registering the container creates a scope which might not be cleaned
up completely before we run a next command in the same container,
causing intermittent test fails:

[   63.424739] TEST-13-NSPAWN.sh[4231]: + systemd-nspawn --directory=/var/lib/machines/TEST-13-NSPAWN.sanity.zH2 bash -xec '[[ $USER == root ]]'
[   63.427504] systemd-nspawn[4381]: ░ Spawning container TEST-13-NSPAWN.sanity.zH2 on /var/lib/machines/TEST-13-NSPAWN.sanity.zH2.
[   63.437154] systemd[1]: Started TEST-13-NSPAWN.sanity.zH2.scope - Container TEST-13-NSPAWN.sanity.zH2.
[   63.437765] systemd-machined[1164]: New machine TEST-13-NSPAWN.sanity.zH2.
[   63.440311] TEST-13-NSPAWN.sh[4381]: + [[ root == root ]]
[   63.442046] systemd[1]: TEST-13-NSPAWN.sanity.zH2.scope: Killed unit cgroup '/machine.slice/TEST-13-NSPAWN.sanity.zH2.scope' with SIGKILL on client request.
[   63.442583] systemd-nspawn[4381]: Container TEST-13-NSPAWN.sanity.zH2 exited successfully.
[   63.443073] systemd-machined[1164]: Machine TEST-13-NSPAWN.sanity.zH2 terminated.
[   63.448728] TEST-13-NSPAWN.sh[4231]: + systemd-nspawn --directory=/var/lib/machines/TEST-13-NSPAWN.sanity.zH2 --user=testuser bash -xec '[[ $USER == testuser ]]'
[   63.451209] systemd-nspawn[4385]: ░ Spawning container TEST-13-NSPAWN.sanity.zH2 on /var/lib/machines/TEST-13-NSPAWN.sanity.zH2.
[   63.455295] systemd-nspawn[4385]: Failed to allocate scope: Unit TEST-13-NSPAWN.sanity.zH2.scope was already loaded or has a fragment file.
[   63.456139] systemd[1]: TEST-13-NSPAWN.sanity.zH2.scope: Deactivated successfully.
[   63.461292] TEST-13-NSPAWN.sh[2839]: + at_exit

Since even systemd-nspawn's man page suggests not to register containers
with systemd-machined if they don't run a service manager, let's do just
that to mitigate the race.

Resolves: #39629
2025-11-10 18:30:55 +00:00
Yu Watanabe
1d17b23dd6 test: avoid service name collision
The same service name was accidentally used for two invocations:
```
[ 1801.197993] H TEST-04-JOURNAL.sh[20563]: + assert_rc 0 journalctl -q -D /run/log/journal/e30adae55e664d328af442bf5df694c8/ -u test-23833.service --grep service=test-23833.service
[ 1801.198527] H TEST-04-JOURNAL.sh[20685]: + set +ex
[ 1801.222676] H TEST-04-JOURNAL.sh[20686]: Nov 10 03:18:51 H systemd[1]: test-23833.service: About to execute: /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync"
[ 1801.222676] H TEST-04-JOURNAL.sh[20686]: Nov 10 03:18:51 H systemd[1]: Started test-23833.service - [systemd-run] /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync".
[ 1801.222676] H TEST-04-JOURNAL.sh[20686]: Nov 10 03:18:51 H (bash)[20681]: test-23833.service: Executing: /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync"
[ 1801.222676] H TEST-04-JOURNAL.sh[20686]: Nov 10 03:18:51 H bash[20681]: service=test-23833.service invocation=1866f15e95924a688dcecde72bf345f6
[ 1801.227878] H TEST-04-JOURNAL.sh[20563]: + assert_rc 1 journalctl -q -D /var/log/journal/e30adae55e664d328af442bf5df694c8/ -u test-23833.service --grep service=test-23833.service
[ 1801.228265] H TEST-04-JOURNAL.sh[20689]: + set +ex
[ 1801.253412] H TEST-04-JOURNAL.sh[20690]: Nov 10 03:18:49 H systemd[1]: test-23833.service: About to execute: /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync"
[ 1801.253412] H TEST-04-JOURNAL.sh[20690]: Nov 10 03:18:49 H systemd[1]: Started test-23833.service - [systemd-run] /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync".
[ 1801.253412] H TEST-04-JOURNAL.sh[20690]: Nov 10 03:18:49 H (bash)[20581]: test-23833.service: Executing: /usr/bin/bash -c "echo service=test-23833.service invocation=\$INVOCATION_ID; journalctl --sync"
[ 1801.253412] H TEST-04-JOURNAL.sh[20690]: Nov 10 03:18:49 H bash[20581]: service=test-23833.service invocation=a3089a62b5624d21bac0a75a3995d8b5
[ 1801.258158] H TEST-04-JOURNAL.sh[20692]: FAIL: expected: '1' actual: '0'
```
2025-11-10 20:49:00 +09:00
Mike Yuan
6a5e38c3b9 TEST-54-CREDS: add test case for credential dir masking 2025-11-09 23:38:59 +01:00
Maximilian Bosch
4dabc30050 service: setup credentials for ExecCondition
Closes #35788

This gives access to credentials within ExecCondition=. As described in
ticket #35788, I do have a use-case for this and as noted in the
commit that dropped this[1], this is OK to be revisited if there are
use-cases.

[1] a145623bc4
2025-11-10 05:27:00 +09:00
Yu Watanabe
445b7073c7 repart: Correctly handle btrfs compression (#39597)
systemd-repart is incorrectly choosing the loop-mount
code path to copy files after formatting, instead of using the --rootdir
path, which is required by mkfs.btrfs to apply compression (since it's
on files, not the fs).

So two fixes (and an integ test):

1. If Btrfs compression is requested without a root directory (e.g.,
Compression= without CopyFiles=), we now log a warning and skip the
--compress flag. This prevents the mkfs.btrfs failure, and it's
meaningless anyway without any files.
2. The logic in repart now uses the --rootdir code path whenever the
partition is btrfs and compression is requested. Otherwise it still
won't work even in the legitimate case because use the loop mounting
code, which is too late to use --compress.

Fixes: https://github.com/systemd/systemd/issues/39584
2025-11-10 01:52:19 +09:00
Chris Down
2091caddb8 test: Add integration test for btrfs compression in repart
Add testcase_btrfs_compression() to verify that btrfs partitions with
Compression= and CopyFiles= directives work correctly.

The test verifies the fix for issue #39584, where mkfs.btrfs would fail
with "ERROR: --compression must be used with --rootdir" when repart
tried to create compressed btrfs filesystems.

The test creates a partition definition with Format=btrfs,
Compression=zstd, and CopyFiles=, then validates:

1. systemd-repart output shows "Rootdir from:" and "Compress:",
   confirming that the --rootdir code path is used
2. mkfs.btrfs is invoked with both --compress and --rootdir options
3. The file is successfully copied to the filesystem
4. Compression is actually applied (verified via compsize output
   containing "zstd")
2025-11-09 21:14:22 +08:00
Luca Boccassi
2db3e403ae test: rotate journal before invocation test
Occasionally there are truncated journals failing this test:

[  884.181701] H TEST-04-JOURNAL.sh[12104]: ++ journalctl --no-hostname -n 1 -t bash --invocation=fe8122a7d8eb42c7bf357ac5fafa95e1
[  884.181749] H TEST-04-JOURNAL.sh[12091]: + assert_in 'invocation 1 fe8122a7d8eb42c7bf357ac5fafa95e1' 'Nov 06 17:27:10 bash[11985]: invocation 1 fe8122a7d8eb42c7bf357ac5fafa95e1'
[  884.181773] H TEST-04-JOURNAL.sh[12105]: + set +ex
[  884.181819] H TEST-04-JOURNAL.sh[12091]: + read -r idx invocation _
[  884.181819] H TEST-04-JOURNAL.sh[12091]: + i=2
[  884.181865] H TEST-04-JOURNAL.sh[12106]: ++ journalctl --no-hostname -n 1 -t bash --invocation=2 -u invocation-id-test-20992
[  884.181865] H TEST-04-JOURNAL.sh[12106]: Journal file /var/log/journal/936183a66e7c47939693ae37a967e4fd/system.journal is truncated, ignoring file.
[  884.181865] H TEST-04-JOURNAL.sh[12106]: No journal entry found for the invocation (+2).
[  884.181952] H TEST-04-JOURNAL.sh[12091]: + assert_in 'invocation 2 07d0bd6b5c654b148541d798abccaa96' ''
[  884.181972] H TEST-04-JOURNAL.sh[12107]: + set +ex
[  884.181972] H TEST-04-JOURNAL.sh[12107]: FAIL: 'invocation 2 07d0bd6b5c654b148541d798abccaa96' not found in:

Rotate it at the beginning of the test case to try and avoid this.

Fixes https://github.com/systemd/systemd/issues/39601
2025-11-07 21:35:45 +00:00
Frantisek Sumsal
6d510012b7 test: move the system time to exactly the timer's elapse time
When we moved the time to 1 minute after the timer would've elapsed,
systemd could pick RandomizedDelaySec= <= 1 minute which would then
cause the timer to elapse immediately and the InactiveExitTimestamp=
to get recalculated including a new next elapse time that would be for
the next "window":

systemd[1]: timer-RandomizedDelaySec-30785.timer: Adding 3.634672s random time.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Realtime timer elapses at Fri 2025-11-07 00:10:03 UTC.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Timer elapsed.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Changed waiting -> running
systemd[1]: Found unit timer-RandomizedDelaySec-30785.timer at /run/systemd/system/timer-RandomizedDelaySec-30785.timer (regular file)
systemd[1]: Preset files say disable timer-RandomizedDelaySec-30785.timer.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Got notified about unit deactivation.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Adding 8h 39min 26.166418s random time.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Realtime timer elapses at Sat 2025-11-08 08:49:26 UTC.
systemd[1]: timer-RandomizedDelaySec-30785.timer: Changed running -> waiting
...
TEST-53-TIMER.sh[1008]: InactiveExitTimestamp=Thu 2025-11-06 23:00:00 UTC
TEST-53-TIMER.sh[1010]: ++ systemctl show -P NextElapseUSecRealtime timer-RandomizedDelaySec-30785.timer
TEST-53-TIMER.sh[905]: + NEXT_ELAPSE_REALTIME='Sat 2025-11-08 08:49:26 UTC'
TEST-53-TIMER.sh[1011]: ++ date '--date=Sat 2025-11-08 08:49:26 UTC' +%s
TEST-53-TIMER.sh[905]: + NEXT_ELAPSE_REALTIME_S=1762591766
TEST-53-TIMER.sh[905]: + : 'Next elapse timestamp should be Fri 2025-11-07 00:10:00 UTC <= Sat 2025-11-08 08:49:26 UTC <= Fri 2025-11-07 22:10:00 UTC'
TEST-53-TIMER.sh[905]: + assert_ge 1762591766 1762474200
TEST-53-TIMER.sh[1012]: + set +ex
TEST-53-TIMER.sh[905]: + assert_le 1762591766 1762553400
TEST-53-TIMER.sh[1013]: + set +ex
TEST-53-TIMER.sh[1013]: FAIL: '1762591766' > '1762553400'

Technically, the race is still there, but the window for it should be
_much_ smaller now (< 1s on a reasonably fast system). Let's hope that's
enough.

Resolves: #39594
2025-11-07 20:04:59 +00:00