Commit Graph

6168 Commits

Author SHA1 Message Date
Jelle van der Waa
c6ebb98e3c logind: emit PropertiesChanged when lingering is enabled/disabled
Cockpit's podman plugin needs to know the lingering status so the UI can
advertise enabling `podman-restart` (which depends on lingering to
work). Currently it relies on watching `/var/lib/systemd/linger/${user}`
but that isn't a public API.

Related: #22244
2025-10-09 09:39:45 +02:00
Lennart Poettering
e921d6d40f creds: add explicit control on whether to allow null key decryption
The ability to encrypt/authenticate encryption with a null key was
originally just a fallback concept for cases where during early boot we
have no host key, but the local system has no TPM2. Nowadays it is used
for other stuff as well, such as pcrlock data propagation (i.e. data
that needs no protection itself and required to properly to TPM key
derivation).

Let's give better, explicit control over null key usage, i.e. let's make
it a tristate both on the systemd-creds command line and in the Varlink
IPC to control three cases:

- the default that we allow it only if SecureBoot is off
- explicitly allowed
- explicitly refused (this is new)

Ideally systemd-creds --allow-null switch would take a boolean argument
to control this as a tristate. Alas, that would be a compat break, hence
I added --refuse-null instead (which also maps to the low-level flag for
this).

This also normalizes that the null key is always called "null key" in
messages, and not sometimes "empty key" or "fallback key".
2025-10-08 09:18:28 +02:00
Lennart Poettering
76d5d38fcc test: add testcase for withKey varlink option 2025-10-08 09:18:28 +02:00
Lennart Poettering
e4201d0a0e sysctl: support reading configuration from stdin and command line arguments (#39219)
This makes systemd-sysctl support following syntax, like
systemd-sysusers and systemd-tmpfiles:
```sh
$ /usr/lib/systemd/systemd-sysctl --inline 'foo.bar=42'
$ /usr/lib/systemd/systemd-sysctl - <<EOF
foo.bar=42
EOF
```
2025-10-06 16:12:11 +02:00
Jelle van der Waa
42e543408b varlinkctl: add detailed error message when --more is needed
Instead of reporting a "Invalid exchange", tell the user the `--more`
flag is missing.

Closes: #39201
2025-10-05 22:14:50 +02:00
Yu Watanabe
2de03c8e8b test: add test cases for sysctl reading configuration from stdin or positional arguments 2025-10-06 04:55:25 +09:00
Yu Watanabe
862b61a3a1 test: merge TEST-76-SYSCTL into TEST-87-AUX-UTILS-VM 2025-10-06 03:26:28 +09:00
val4oss
b8efd65975 TEST-74-AUX-UTILS: use sshd_config.d
* From the TEST-74-AUX-UTILS.ssh.sh writing directly into
  /etc/ssh/sshd_config can hide config from distro using /usr/etc.
* Using directory configuration /etc/ssh/sshd_config.d/* suits for all
  cases.

Signed-off-by: val4oss <val4oss@pm.me>
2025-10-04 23:00:31 +02:00
Zbigniew Jędrzejewski-Szmek
ea44302b29 meson: using f-strings in meson
Those were added before 0.61 which is our minimum version.

Dots were dropped from the end of some messages. Most messages did not have the
trailing dot.

0.63 added support for multi-line f-strings. We can't use those yet.
2025-10-03 21:21:52 +02:00
Frantisek Sumsal
0cb252d50f test: store and compare just the property value
Follow-up for 5730a400fd.
2025-09-29 23:01:24 +02:00
Lennart Poettering
0c3639d0f5 homectl firstboot tweaks (#39137)
This adds what #39101 and #39070 did for the regular firstboot wizard
but for the homectl firstboot part: i.e. port to the generic prompt
loop, show the "chrome" bars, and mute the console.

And then it also makes querying for aux groups and shells optional,
because quite frankly, i am not sure what to answer there.
2025-09-29 10:56:27 +02:00
Yu Watanabe
0f8706915a TEST-64-UDEV-STORAGE: do not use -f/--force option for wipefs
When -f/--force is used, wipefs does not call ioctl(BLKRRPART), hence
the partitions will remain in sysfs. Let's not use the option.

This also makes it use 'udevadm lock' for safety.
2025-09-27 00:18:53 +09:00
Lennart Poettering
aa27bec194 firstboot: optionally, don't query for keymap unless connected to a real VT
The keymap only really matters if there's local access to a system, i.e.
if there's actually a physical kbd directly connected to it, to apply it
to. If during firstboot we are not talked to via a VT (but via SSH,
container, or hypervisor console or so instead), then it's very unlikely
we ever are. Hence, don't ask for a keymap, and let#s shortcut the
questions asked at boot.
2025-09-26 16:40:14 +02:00
Lennart Poettering
bedcce1a1f firstboot: drop waiting for key when starting
We only show this blurb on the first question, but the first question is
interactive anyway, hence no need to wait for input first explicitly, we
won't progress anyway without user input.

(similar for homectl's firstboot)
2025-09-26 16:27:53 +02:00
Lennart Poettering
82a48eb1db test: add simple test case for mute-console service 2025-09-26 09:42:13 +02:00
Yu Watanabe
0f44a6c64a core: assorted fixes and cleanups for cgroup (#39094) 2025-09-26 13:56:25 +09:00
Yu Watanabe
10b2d19219 timer: fix unexpected triggering of service immediately after restart of a timer (#38868)
Fixes: #31231
Fixes: #35805
2025-09-26 09:51:36 +09:00
Yu Watanabe
8b4ee3d68d core/unit: fail earlier before spawning executor when we failed to realize cgroup
Before 23ac08115a, even if we failed to
create the cgroup for a unit, a cgroup runtime object for the cgroup is
created with the cgroup path. Hence, the creation of cgroup is failed,
execution of the unit will fail in posix_spawn_wrapper() and logged
something like the following:
```
systemd[1]: testservice.service: Failed to create cgroup /testslice.slice/testservice.service: Cannot allocate memory
systemd[1]: testservice.service: Failed to spawn executor: No such file or directory
systemd[1]: testservice.service: Failed to spawn 'start' task: No such file or directory
systemd[1]: testservice.service: Failed with result 'resources'.
systemd[1]: Failed to start testservice.service.
```

However, after the commit, when we failed to create the cgroup, a cgroup
runtime object is not created, hence NULL will be assigned to
ExecParameters.cgroup_path in unit_set_exec_params().
Hence, the unit process will be invoked in the init.scope.
```
systemd[1]: testservice.service: Failed to create cgroup /testslice.slice/testservice.service: Cannot allocate memory
systemd[1]: Starting testservice.service...
cat[1094]: 0::/init.scope
systemd[1]: testservice.service: Deactivated successfully.
systemd[1]: Finished testservice.service.
```
where the test service calls 'cat /proc/self/cgroup'.

To fix the issue, let's fail earlier when we failed to create cgroup.

Follow-up for 23ac08115a (v258).
2025-09-26 09:28:12 +09:00
Yu Watanabe
5c60d3011f integration tests: do not adjust log level in the test script
We passes log level through kernel command line. It is not necessary to
set to debug level at the beginning, and set to info at the end.
This is important when a test has several subtests. If a subtest sets
log level to info at the end, then subsequent tests may not generate any
useful logs.
2025-09-26 07:20:04 +09:00
Luca Boccassi
c5e48e3a66 machined: do not allow unprivileged users to shell into the root namespace
We intend to make self-registering machines an unprivileged operation,
but currently that would allow an unprivileged user to register a
process they own in the root namespace, and then login as any
user they like, including root, which is not ideal.

Forbid non-root from shelling into a machine that is running in
the root user namespace.
2025-09-25 22:13:05 +02:00
Frantisek Sumsal
f4c3c107d9 test: check the next elapse timer timestamp after deserialization
When deserializing a serialized timer unit with RandomizedDelaySec= set,
systemd should use the last inactive exit timestamp instead of current
realtime to calculate the new next elapse, so the timer unit actually
runs in the given calendar window.

Provides coverage for:
  - https://github.com/systemd/systemd/issues/18678
  - https://github.com/systemd/systemd/pull/27752
2025-09-25 12:55:04 +02:00
Frantisek Sumsal
5730a400fd test: restarting elapsed timer shouldn't trigger the corresponding service
Provides coverage for:
  - https://github.com/systemd/systemd/issues/31231
  - https://github.com/systemd/systemd/issues/35805
2025-09-24 09:52:36 +02:00
Frantisek Sumsal
953c347fb6 test: rename TEST-53-ISSUE-16347 to TEST-53-TIMER
And split the existing test into a separate subtest.
2025-09-24 09:52:36 +02:00
Yu Watanabe
e2c5e9c011 test: use relative paths to executables
This also makes shebang always use env command, and drops unnecessary
'bash -c' or 'sh -c' when a signle command is invoked in the shell,
like sleep or echo.
2025-09-23 15:48:53 +01:00
Lennart Poettering
347a3c925c test: add simple testcase for io.systemd.Repart.ListCandidateDevices 2025-09-23 09:25:11 +02:00
Daan De Meyer
d4da97400c test: Add tests for systemd's kernel oom kill handling 2025-09-19 13:54:54 +02:00
Daan De Meyer
9cf6ad16dd core: Expose oom kills and managed oom kills as properties
It can be useful for users to know this information so let's expose
it as properties so it can be queried.
2025-09-19 13:54:54 +02:00
Mike Yuan
afba4d4387 TEST-81-GENERATORS: libmount disallows omitting fstype
It's not well-formed to begin with. And util-linux's mount(8)
is pretty much ubiquitously employed, hence it will be rejected
elsewhere too. Just stop pretending it is valid just because
glibc parser is sloppy.
2025-09-18 20:22:42 +02:00
Yu Watanabe
aa5aac9e40 test-sysusers: show diffs in stderr
Otherwise, the diffs are eaten by 'meson test' command unless --verbose
option is specified.
2025-09-17 22:20:42 +09:00
Yu Watanabe
87a87b02b9 test-udev: pass test_env to make the test use systemd-detect-virt in build directory
Otherwise, the test fails if the running host does not have
systemd-detect-virt.
2025-09-17 22:20:42 +09:00
Zbigniew Jędrzejewski-Szmek
28021f6e88 Some post unmerged-usr cleanups (#38696)
I noticed in our NixOS packaging that we were working around the fact
that core/swap.c looks for swapon and swapoff in /sbin

Lets make it configurable just like all the other util-linux binaries
through meson and make it default to /usr/sbin/{swapon,swapoff}

This way mounts work on a systemd without the /sbin -> /usr/sbin
compatibility symlink. (And as a side-effect has NixOS be able to have
it in /nix/store too like the other util-linux tools).

Given that `unmerged-usr` support was dropped in 255 I think this is a
safe change?
2025-09-17 14:22:05 +02:00
Luca Boccassi
119d332d9c machine: do not allow unprivileged users to register other users' processes as machines
Registering a process as a machine means a caller can get machined
to send sigterm to it, and more. If an unpriv user is registering,
ensure the registered process is actually owned by the user.

Follow-up for adaff8eb35
2025-09-16 15:58:28 +01:00
Luca Boccassi
52ff4de962 Revert "TEST-55-OOMD: Verify that ExecStopPost= runs on oom-kill"
The test consistently fails on CentOS 9:

TEST-55-OOMD.sh[678]: + test -f /run/testbloat-exec-stop-post
[FAILED] Failed to start TEST-55-OOMD.service.

https://github.com/systemd/systemd/actions/runs/17689186773/job/50293446228?pr=38911

This reverts commit 5bf7438ff0.
2025-09-15 19:38:28 +01:00
Luca Boccassi
876c4c5129 test: call mksquashfs with -noappend to be safe on reruns
If the test VM reboots and the test re-runs, creating the images
fails as they already exist:

[  218.227766] TEST-50-DISSECT.sh[889]: + mksquashfs testkit/ testkit.raw
[  218.238754] TEST-50-DISSECT.sh[2964]: FATAL ERROR: Could not read $HOME, use -recovery-path or -no-recovery options
[  218.239284] TEST-50-DISSECT.sh[2964]: Found a valid exportable SQUASHFS superblock on testkit.raw.
[  218.239554] TEST-50-DISSECT.sh[2964]: 	Compression used gzip
[  218.240176] TEST-50-DISSECT.sh[2964]: 	Inodes are compressed
[  218.240459] TEST-50-DISSECT.sh[2964]: 	Data is compressed
[  218.241072] TEST-50-DISSECT.sh[2964]: 	Fragments are compressed
[  218.241526] TEST-50-DISSECT.sh[2964]: 	Xattrs are compressed
[  218.241953] TEST-50-DISSECT.sh[2964]: 	Fragments are present in the filesystem
[  218.242411] TEST-50-DISSECT.sh[2964]: 	Always-use-fragments option is not specified
[  218.242843] TEST-50-DISSECT.sh[2964]: 	Duplicates are removed
[  218.243560] TEST-50-DISSECT.sh[2964]: 	Xattrs are stored
[  218.243889] TEST-50-DISSECT.sh[2964]: 	Filesystem size 0.38 Kbytes (0.00 Mbytes)
[  218.244563] TEST-50-DISSECT.sh[2964]: 	Block size 131072
[  218.245051] TEST-50-DISSECT.sh[2964]: 	Number of fragments 1
[  218.245512] TEST-50-DISSECT.sh[2964]: 	Number of inodes 6
[  218.245851] TEST-50-DISSECT.sh[2964]: 	Number of ids 1
[  218.246393] TEST-50-DISSECT.sh[2964]: Parallel mksquashfs: Using 2 processors
[  218.246820] TEST-50-DISSECT.sh[2964]: Scanning existing filesystem...
[  218.247286] TEST-50-DISSECT.sh[2964]: Read existing filesystem, 5 inodes scanned
[  218.252974] TEST-50-DISSECT.sh[2964]: Appending to existing 4.0 filesystem on testkit.raw, block size 131072
[  218.253593] TEST-50-DISSECT.sh[2964]: All -b, -noI, -noD, -noF, -noX, -noId, -no-duplicates, -no-fragments,
[  218.253848] TEST-50-DISSECT.sh[2964]: -always-use-fragments, -exportable and -comp options ignored
[  218.257196] TEST-50-DISSECT.sh[2964]: If appending is not wanted, please re-run with -noappend specified!

https://github.com/systemd/systemd/actions/runs/17674609143/job/50233691148?pr=38867
2025-09-15 14:42:03 +01:00
Luca Boccassi
27833c409d test: consolidate checks for unpriv nspawn support in TEST-13-NSPAWN
[   69.058386] systemd-nspawn[4371]: varlink: Sending message: {"method":"io.systemd.NamespaceResource.AllocateUserRange","parameters":{"name":"nspawn-4371-zurps","mangleName":true,"size":65536,"userNamespaceFileDescriptor":0}}
[   69.058447] systemd-nsresourcework[4339]: varlink-6-6: Received message: {"method":"io.systemd.NamespaceResource.AllocateUserRange","parameters":{"name":"nspawn-4371-zurps","mangleName":true,"size":65536,"userNamespaceFileDescriptor":0}}
[   69.058455] systemd-nsresourcework[4339]: varlink-6-6: Changing state idle-server → processing-method
[   69.058479] systemd-nsresourcework[4339]: varlink-6-6: Sending message: {"error":"io.systemd.NamespaceResource.UserNamespaceInterfaceNotSupported","parameters":{}}
[   69.058482] systemd-nsresourcework[4339]: varlink-6-6: Changing state processing-method → processed-method
[   69.058486] systemd-nsresourcework[4339]: varlink-6-6: Changing state processed-method → idle-server
[   69.058599] systemd-nspawn[4371]: varlink: Received message: {"error":"io.systemd.NamespaceResource.UserNamespaceInterfaceNotSupported","parameters":{}}
[   69.058604] systemd-nspawn[4371]: varlink: Changing state calling → called
[   69.058609] systemd-nspawn[4371]: varlink: Changing state called → idle-client
[   69.058614] systemd-nspawn[4371]: Unprivileged user namespace delegation is not supported on this system.
[   69.058637] systemd-nsresourcework[4339]: varlink-6-6: Got POLLHUP from socket.
[   69.058647] systemd-nsresourcework[4339]: varlink-6-6: Changing state idle-server → pending-disconnect
[   69.058653] systemd-nsresourcework[4339]: varlink-6-6: Changing state pending-disconnect → processing-disconnect
[   69.058656] systemd-nsresourcework[4339]: varlink-6-6: Changing state processing-disconnect → disconnected
[   69.058698] systemd-nspawn[4371]: Failed to allocate user namespace with 64K users: Operation not supported
[   69.058779] systemd[4344]: systemd-nspawn@zurps.service: Got notification message from PID 4371: STOPPING=1, STATUS=Terminating...

Follow-up for bfd356da63
2025-09-15 15:39:05 +02:00
Luca Boccassi
8fac2eb212 Revert "test: propagate log env vars in run-unit-tests.py wrapper"
The default is already to propagate the env vars, so this
was unnecessary and actually creates problem as it removes
custom PATHs

This reverts commit 994af53395.
2025-09-15 11:22:19 +02:00
Luca Boccassi
a0203ac14c test: ensure journal dir is writable by container in TEST-13-NSPAWN
The systemd-journal group is not mapped, so ensure the test directory
is owned by root:root so that the mapping works.

Follow-up for 88fce09026
2025-09-14 13:23:17 +01:00
Daan De Meyer
5bf7438ff0 TEST-55-OOMD: Verify that ExecStopPost= runs on oom-kill 2025-09-13 00:20:56 +01:00
Yu Watanabe
8685f8edd1 TEST-64-UDEV-STORAGE: forcibly create new physical volume
When the test VM is accidentally rebooted, there exists the previously
created volume, and the command fails with the following:
```
TEST-64-UDEV-STORAGE.sh[282]: + lvm pvcreate -y /dev/md/mdlvm
TEST-64-UDEV-STORAGE.sh[442]:   Can't initialize physical volume "/dev/md127" of volume group "mdlvm_vg" without -ff
TEST-64-UDEV-STORAGE.sh[442]:   /dev/md127: physical volume not initialized.
[FAILED] Failed to start TEST-64-UDEV-STORAGE-mdadm_lvm.service.
```
Let's ignore the existence of previous volume and forcibly create new one.

Workaround for issue #38240.
2025-09-11 00:06:33 +09:00
Luca Boccassi
994af53395 test: propagate log env vars in run-unit-tests.py wrapper
To make it easier to debug unit test failures
2025-09-10 14:34:01 +01:00
Luca Boccassi
9cc9e14ed4 test: remove extension from /var/lib/extensions at the end of the test
Otherwise it remains there, and another test case accidentally
uses it on refresh, which then makes another later test fail,
as the hierarchy is already merged:

[  203.969708] TEST-50-DISSECT.sh[890]: + systemd-sysext status
[  203.981831] TEST-50-DISSECT.sh[2795]: HIERARCHY EXTENSIONS SINCE
[  203.982196] TEST-50-DISSECT.sh[2795]: /opt      app0       Mon 2025-09-08 11:49:11 UTC
[  203.982551] TEST-50-DISSECT.sh[2795]: /usr      app0       Mon 2025-09-08 11:49:11 UTC

[  204.119772] TEST-50-DISSECT.sh[2799]: Hierarchy '/usr' is already merged.

Fixes https://github.com/systemd/systemd/issues/38282
2025-09-09 08:52:37 +02:00
Luca Boccassi
28edbbdc1b test: add more debug output
The test occasionally fails with:

TEST-50-DISSECT.sh[3852]: Hierarchy '/usr' is already merged.

I can't really tell what is already merged as all previous ops
look as they are undone from the logs, so add status/list commands
just before the failing operation to hopefully give more info

For https://github.com/systemd/systemd/issues/38282
2025-09-05 12:13:25 +02:00
Luca Boccassi
7b53fd6215 Clean up redirection ops in tests (#38827) 2025-09-05 09:41:53 +01:00
Zbigniew Jędrzejewski-Szmek
e1485c0546 tests: drop pointless redirection of stderr from 'command -v'
The whole point of using 'command -v' is that it's a very portable
way to check if an executable exists. It doesn't print an error.
2025-09-05 08:29:52 +02:00
Zbigniew Jędrzejewski-Szmek
51fac9a0bf TEST-75-RESOLVED: drop whitespace after shell redirection ops 2025-09-05 08:29:52 +02:00
Daan De Meyer
cadeaef67c test: Add test for nspawn's handling of cap_net_bind_service 2025-09-05 08:24:39 +02:00
Daan De Meyer
f70754b34f TEST-13-NSPAWN: Fix typo 2025-09-05 08:24:39 +02:00
Yu Watanabe
2985840855 test: re-enable journal checks for varlink-idl and so on
Previously, we have checked journal after TEST-XX-YYYYY.sh, but it was
forgotten when we switched to mkosi.
This re-enable the check but through ExecStartPost=, and drops unnecessary
workarounds for end.service. Then, this drops unnecessary end.service
and testsuite.target.
2025-09-04 19:50:28 +09:00
Yu Watanabe
df25e4af16 test: do not call GetUserRecord without "service" argument
Otherwise, following debugging log will be saved and the checker for
the varlink-idl log triggers failure:
```
systemd-userwork: processing[3110]: varlink-6-6: Parameters for method
  io.systemd.UserDatabase.GetUserRecord() didn't pass validation on field 'service': No anode
```
2025-09-04 19:50:28 +09:00
Yu Watanabe
b10619484d Cleanups for test/units directory (#38807) 2025-09-04 18:11:27 +09:00