1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00
Commit Graph

4185 Commits

Author SHA1 Message Date
Luca Boccassi
b44a72da57
Merge pull request #29711 from berrange/tests-silverblue
Fix test suite when developing on Fedora SilverBlue (rpm-ostree) host
2023-10-26 21:17:03 +01:00
Luca Boccassi
63862de4b7 core: do not post-process skipped mounts
When a mount is gracefully skipped (e.g.: BindReadOnlyPaths=-/nonexistent)
we still post-process it, like making it read-only. Except if nothing
has been mounted, the mount point will be made read-only for no reason.
Track when mounts are skipped and avoid post-processing.

One day we'll switch all of this to the new mount api and do these
operations atomically or not at all.

Fixes https://github.com/systemd/systemd/issues/29725
2023-10-26 21:15:41 +01:00
Daniel P. Berrangé
3570ee3688 test-fstab-generator: skip test impacted by /mnt symlink
On rpm-ostree distributions such as Fedora SilverBlue /mnt
(and other well known paths) will be a symlink to a location
under /var. The fstab generator emits correct output in this
case, however, the data does not match the expected output
stored in the source tree.

Rather than trying to adapt the test data, just skip this
single test scenario when we see /mnt is a symlink.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-10-26 14:46:15 +01:00
Daniel P. Berrangé
8473ece90e test-systemd-tmpfiles: skip when /tmp has unexpected ownership
The systemd-tmpfiles binary will report a fatal error if /tmp is not owned
either by root, or by the current user:

  Detected unsafe path transition /tmp (owned by nobody) →
    /tmp/test-systemd-tmpfiles.a8qc6n18 (owned by berrange)
    during canonicalization of
    tmp/test-systemd-tmpfiles.a8qc6n18/test-content.7chd7rdi

When doing development inside a 'toolbox' container (which is required
on a Fedora SilverBlue distro), /tmp is owned by 'nobody', because it
has been passed through from the host and host UID 0 gets mapped to
UID 65536 by usernamespaces. This triggers the unsafe path transition
error message.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-10-26 14:46:15 +01:00
Luca Boccassi
e34836aa59
Merge pull request #29529 from yuwata/core-namespace-check-priv
core/namespace: check if we have enough privilege
2023-10-26 14:27:56 +01:00
Yu Watanabe
e9af462aba test: add a simple test for PrivateNetwork= 2023-10-26 19:09:49 +09:00
Yu Watanabe
dd59a609be test-network: suppress too much outputs of state file
Follow-up for 0f9efffaeb.
2023-10-26 12:26:19 +09:00
Daan De Meyer
c173be0d4c
Merge pull request #29708 from DaanDeMeyer/bootctl-always
Always build bootctl
2023-10-25 22:59:59 +02:00
Frantisek Sumsal
d08b67e55e test: slightly extend systemd-tpm2-setup's coverage 2023-10-25 18:18:48 +02:00
Frantisek Sumsal
af70e2021e test: add a couple more tests for systemd-pcrextend 2023-10-25 18:18:47 +02:00
Frantisek Sumsal
45534eefe6 test: make the TPM event log checking a bit more robust
Don't hardcode the event number, so the test works correctly even if
someone wrote to the event log before us. Also, explicitly pick the
sha256 bank when checking digests, as the indexing may vary depending on
current TPM's capabilities.
2023-10-25 18:18:11 +02:00
Daan De Meyer
dedb925eaf meson: Always build bootctl
bootctl is rather useful to have, even if on a system without UEFI,
as it has a number of verbs that are unrelated to UEFI (e.g kernel-identify),
and more importantly, it supports --root to operate on directory trees
(which could be intended to be deployed on UEFI) so let's make sure we
always build it.
2023-10-25 16:49:24 +02:00
Frantisek Sumsal
29be59555f test: split TEST-70-TPM2 into subtests 2023-10-25 14:48:30 +02:00
Luca Boccassi
7470e161cf
Merge pull request #29553 from keszybz/analyze-cat-config-tldr
analyze/cat-config: add switch to print only "interesting" parts of conffiles
2023-10-25 09:53:19 +01:00
Frantisek Sumsal
b9439855d2
Merge pull request #29687 from yuwata/network-state-file-sync
network: several fixlets for state file
2023-10-25 08:29:58 +00:00
Yu Watanabe
0f9efffaeb test-network: wait for the state file being updated
Also, sync state files before read.

Addresses the first issue in #29678.
2023-10-24 23:22:27 +09:00
Zbigniew Jędrzejewski-Szmek
063c838206 analyze/cat-config: add switch to print only "interesting" parts of config files
When looking at configuration, often a user wants to suppress the comments and
just look at the parts that actually configure something, roughly equivalent to
  systemd-analyze cat-config … | rg -v '^(#|;|$)
This switch implements this natively, skipping lines that start with a comment
character or only contain whitespace.

For formats that have section headers, section headers are skipped, if only
followed by stuff that would be skipped. (The last section header is printed
when we're about to print some actual output.)

Note that the caller doesn't know if the format has headers or not. We do format
type detection in pretty-print.c. So the caller only specifies tldr=true|false, and
conf_files_cat() figures out if the format has headers and whether those should
be handled specially.

The comments that show the file name are always printed, even if all of the file
is suppressed.

This is a partial answer to the discussions in
https://github.com/systemd/systemd/pull/28919,
https://github.com/systemd/systemd/pull/29248. If the default config is shown in
config files, the user can conveniently use '--tldr' to show the relevant parts.
2023-10-24 15:59:34 +02:00
Frantisek Sumsal
270b20b98b test: shorten service stop/abort timeouts for TEST-69-SHUTDOWN
In several Ubuntu CI jobs I noticed timeouts in TEST-69, which are
apparently caused by a very stubborn bash/login process:

$ journalctl -o short-monotonic --no-hostname --file artifacts/TEST-69-SHUTDOWN.journal
[ 2011.698430] systemd[1]: shutdown.target: starting held back, waiting for: veritysetup.target
[ 2011.698473] systemd[1]: sysinit.target: stopping held back, waiting for: user@0.service
[ 2045.884982] systemd[1]: systemd-oomd.service: Got notification message from PID 54 (WATCHDOG=1)
[ 2071.576424] systemd[1]: Received SIGCHLD from PID 65 (bash).
[ 2071.576941] systemd[1]: Child 65 (bash) died (code=killed, status=1/HUP)
[ 2071.577026] systemd[1]: session-13.scope: Child 65 belongs to session-13.scope.
[ 2071.577100] systemd[1]: session-13.scope: cgroup is empty
[ 2071.577249] systemd[1]: session-13.scope: Deactivated successfully.

$ journalctl -o short-monotonic --no-hostname --file artifacts/TEST-69-SHUTDOWN.journal _PID=65
[ 3038.661488] login[65]: ROOT LOGIN  on '/dev/pts/0'

Since, in this case, we really care only about the actual shutdown,
let's shorten the service stop/abort timeouts to let systemd SIGKILL all
remaining processes in the 60s `expect` window.
2023-10-24 12:51:03 +02:00
Frantisek Sumsal
5ab2f737cd test: introduce $TEST_SKIP_SHUTDOWN
To get rid of some boilerplate.
2023-10-24 12:35:03 +02:00
Franck Bui
a1af99df8e test: install af_packet kernel module on openSUSE
Currently needed by test-dhcp-server unit test, af_packet is not built-in on
openSUSE distributions.
2023-10-21 11:39:10 +01:00
Luca Boccassi
665a3d6d15 systemctl: automatically softreboot/kexec if set up on reboot
Automatically softreboot if the nextroot has been set up with an OS
tree, or automatically kexec if a kernel has been loaded with kexec
--load.

Add SYSTEMCTL_SKIP_AUTO_KEXEC and SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT to
skip the automated switchover.
2023-10-20 11:45:37 +01:00
Luca Boccassi
f5a7476677
Merge pull request #29628 from mrc0mmand/systemd-executor-test
test: slightly improve sd-executor's coverage
2023-10-19 19:39:39 +01:00
Frantisek Sumsal
e98f7f9122 test: skip Protect{Home,System}= tests with coverage builds
With coverage builds we disable Protect{Home,System}= via a service.d
dropin in /etc, which has, unfortunately, higher priority than our
transient systemd-run stuff. Let's just skip the affected tests in that
case instead of making the test setup even more complicated.
2023-10-19 18:03:57 +01:00
Frantisek Sumsal
a2dd592002 test: unify checking for user xattrs support in cgroupfs
Also, run the coredump forwarding test only if user xattrs are
supported.
2023-10-19 18:01:07 +01:00
Frantisek Sumsal
4701425dd5 test: add coverage for #29610
As reproducing it is actually pretty easy, with the benefit of hindsight:

~# systemd-run -P -p MountImages="/this/should/definitely/not/exist.img:/run/img2\:3:nosuid" false
Running as unit: run-u42.service
free(): double free detected in tcache 2
2023-10-19 16:23:28 +02:00
Frantisek Sumsal
447894be41 test: add a real-world state to the corpus
To give the fuzzer a nice head start.
2023-10-19 16:12:45 +02:00
Luca Boccassi
1ca8cc9fb6
Merge pull request #29595 from YHNdnzj/systemctl-failed-system
systemctl: is-failed: check if system is degraded when no unit given
2023-10-19 12:07:37 +01:00
Frantisek Sumsal
892eb4d795 core: don't assert when serializing malformed state 2023-10-18 22:44:16 +02:00
Frantisek Sumsal
81c4be64da test: add a fuzzer for exec_{serialize,deserialize}_invocation() 2023-10-18 22:44:16 +02:00
Mike Yuan
2ee346160c
systemctl: is-failed: check if system is degraded when no unit given
Closes #3335
2023-10-19 00:12:28 +08:00
Frantisek Sumsal
7e9c7d6f5b test: use Type=exec for the test unit
Make sure everything we need is set up before continuing further with
the test. This should, hopefully, help with a race where we check
a dynamic user before it's created by NFTSet= stuff.

Before:
$ journalctl -o short-monotonic --grep '(test-nft|NFT|testsuite-75)' --no-hostname
...
[ 3657.929223] testsuite-75.sh[48]: + systemd-run -u test-nft.service -p DynamicUser=yes -p 'NFTSet=cgroup:inet:sd_test:c user:inet:sd_test:u group:inet:sd_test:g' sleep 10000
...
[ 3657.977372] systemd[1]: test-nft.service: Changed dead -> running
[ 3657.977388] systemd[1]: test-nft.service: Job 376 test-nft.service/start finished, result=done
[ 3657.977407] testsuite-75.sh[853]: Running as unit: test-nft.service; invocation ID: 8776af2ec7864a60a058cb5d403d1ca6
[ 3657.982437] testsuite-75.sh[856]:                 elements = { "system.slice/test-nft.service" }
[ 3657.984570] testsuite-75.sh[48]: + grep -qF test-nft.service /tmp/tmp.uqXKfyzcpJ
[ 3657.985400] testsuite-75.sh[859]: ++ getent passwd test-nft
[ 3657.986434] systemd[1]: varlink-12: New incoming message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test-nft","service":"io.systemd.DynamicUser"}}
[ 3657.986503] systemd[1]: varlink-12: Sending message: {"error":"io.systemd.UserDatabase.NoRecordFound","parameters":{}}
[ 3657.986643] systemd[1]: testsuite-75.service: Child 48 belongs to testsuite-75.service.
[ 3657.986660] systemd[1]: testsuite-75.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
[ 3657.986681] systemd[1]: testsuite-75.service: Failed with result 'exit-code'.
...
[ 3657.989885] systemd[1]: test-nft.service: User lookup succeeded: uid=64568 gid=64568
[ 3657.989936] systemd[1]: Added NFT set: family inet, table sd_test, set u, ID 64568
[ 3657.989965] systemd[1]: Added NFT set: family inet, table sd_test, set g, ID 64568

After:
$ journalctl -o short-monotonic --grep '(test-nft|NFT|testsuite-75)' --no-hostname
[ 1523.874408] testsuite-75.sh[49]: + systemd-run -u test-nft.service --service-type=exec -p DynamicUser=yes -p 'NFTSet=cgroup:inet:sd_test:c user:inet:sd_test:u group:inet:sd_test:g' sleep 10000
...
[ 1523.924091] systemd[1]: Starting test-nft.service...
[ 1523.928891] systemd[1]: test-nft.service: User lookup succeeded: uid=64568 gid=64568
[ 1523.929102] systemd[1]: Added NFT set: family inet, table sd_test, set u, ID 64568
[ 1523.929220] systemd[1]: Added NFT set: family inet, table sd_test, set g, ID 64568
...
[ 1523.933263] systemd[1]: Started test-nft.service.
[ 1523.933626] testsuite-75.sh[849]: Running as unit: test-nft.service; invocation ID: d1a5c3eacbc647a7a5fcbd46c7b2f863
[ 1523.940810] testsuite-75.sh[852]:                 elements = { "system.slice/test-nft.service" }
[ 1523.942880] testsuite-75.sh[49]: + grep -qF test-nft.service /tmp/tmp.gWka2x3mQq
[ 1523.944031] testsuite-75.sh[855]: ++ getent passwd test-nft
[ 1523.945496] systemd[1]: varlink-18: New incoming message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test-nft","service":"io.systemd.DynamicUser"}}
[ 1523.951593] systemd[1]: varlink-18: Sending message: {"parameters":{"record":{"userName":"test-nft","uid":64568,"gid":64568,"realName":"Dynamic User",...
2023-10-18 16:08:44 +01:00
Frantisek Sumsal
41231bec0c test: don't restart journal-upload on an expected fail
In c08bec1587 the journal-upload unit gained Restart=on-fail, which goes
against this one particular test that expects the unit to fail, making
the test flaky. Let's disable the automatic restarts just for this test
to make it stable once again.
2023-10-17 14:55:12 +01:00
Daan De Meyer
37ba73b1b2
Merge pull request #28373 from DaanDeMeyer/udevadm-query
Add --json and filtering options for --export-db to udevadm info
2023-10-17 10:16:43 +02:00
Lennart Poettering
e0eb051f95
Merge pull request #29546 from poettering/run-invoc-id
run: output invocation ID when starting service and scope units
2023-10-16 19:00:18 +02:00
Daan De Meyer
a6b4b2fa01 udev: Enable filtering the output of udevadm info --export-db
Let's support the same filtering options that we also support in
udevadm trigger in udevadm info to filter the devices produced by
--export-db.

One difference is that all properties specified by --propery-match=
have to be satisfied in udevadm info unlike udevadm trigger where just
one of them has to be satisfied.
2023-10-16 17:02:00 +02:00
Lennart Poettering
cde8cc946b
Merge pull request #29272 from enr0n/coredump-container
coredump: support forwarding coredumps to containers
2023-10-16 16:13:16 +02:00
Luca Boccassi
7c83d42ef8 mount-util: use mount beneath to replace previous namespace mount
Instead of mounting over, do an atomic swap using mount beneath, if
available. This way assets can be mounted again and again (e.g.:
updates) without leaking mounts.
2023-10-16 14:33:47 +01:00
Lennart Poettering
7693661a84 run: output invocation ID when starting service and scope units 2023-10-16 14:30:11 +02:00
Daan De Meyer
d6e5f170ef Add --json switch to udevadm info
This allows getting the udevadm info --export-db and query "all" output
as JSON.
2023-10-16 13:01:54 +02:00
Lennart Poettering
f5151fb459 sysext: make some calls available via varlink 2023-10-16 12:08:39 +02:00
Daan De Meyer
36d87065f2
Merge pull request #29558 from mrc0mmand/varlinkctl-tests
varlink: add a couple of tests + accompanying fixes
2023-10-16 09:49:42 +02:00
Frantisek Sumsal
abcf59970d core: don't downgrade multi-state settings to boolean
Protect{Home,System,Proc,Subset}= are not booleans, so make sure we use
the intended value instead of just true/false.

See: https://github.com/systemd/systemd/pull/29552
Follow-up to: 79d956d
2023-10-15 14:04:28 +08:00
Frantisek Sumsal
78ea6a549f test: update Ubuntu CI instructions 2023-10-14 17:40:07 +02:00
Frantisek Sumsal
779e7b4410 varlink: don't panic on malformed method definition 2023-10-14 17:40:07 +02:00
Frantisek Sumsal
13de7c7e66 test: add a fuzzer for the varlink IDL stuff 2023-10-14 17:40:07 +02:00
Frantisek Sumsal
4b2391c4e3 test: add a couple of tests for varlinkctl 2023-10-14 17:40:07 +02:00
Luca Boccassi
0e3986bc1c
Merge pull request #29525 from poettering/confext-sysext-multimodal
dissect: make sure we can dissect and inspect DDIs that are both confext *and* sysext
2023-10-14 00:28:47 +01:00
Luca Boccassi
ccba67f494
Merge pull request #27890 from bluca/executor
core: add systemd-executor binary
2023-10-13 22:01:16 +01:00
Nick Rosbrook
097e28736a test: add a test for container support in coredump 2023-10-13 15:28:50 -04:00
Luca Boccassi
bb5232b6a3 core: add systemd-executor binary
Currently we spawn services by forking a child process, doing a bunch
of work, and then exec'ing the service executable.

There are some advantages to this approach:

- quick: we immediately have access to all the enourmous amount of
  state simply by virtue of sharing the memory with the parent
- easy to refactor and add features
- part of the same binary, will never be out of sync

There are however significant drawbacks:

- doing work after fork and before exec is against glibc's supported
  case for several APIs we call
- copy-on-write trap: anytime any memory is touched in either parent
  or child, a copy of that page will be triggered
- memory footprint of the child process will be memory footprint of
  PID1, but using the cgroup memory limits of the unit

The last issue is especially problematic on resource constrained
systems where hard memory caps are enforced and swap is not allowed.
As soon as PID1 is under load, with no page out due to no swap, and a
service with a low MemoryMax= tries to start, hilarity ensues.

Add a new systemd-executor binary, that is able to receive all the
required state via memfd, deserialize it, prepare the appropriate
data structures and call exec_child.

Use posix_spawn which uses CLONE_VM + CLONE_VFORK, to ensure there is
no copy-on-write (same address space will be used, and parent process
will be frozen, until exec).
The sd-executor binary is pinned by FD on startup, so that we can
guarantee there will be no incompatibilities during upgrades.
2023-10-12 15:01:51 +01:00