Commit graph

49179 commits

Author SHA1 Message Date
Luca Boccassi ff30e7e3af
Merge pull request #32520 from YHNdnzj/sd-daemon-followup
sd-daemon: minor cleanup and follow-up
2024-04-27 15:22:35 +02:00
Mike Yuan 119bc912a8
Merge pull request #32516 from YHNdnzj/core-cleanup
core: several cleanups
2024-04-27 19:43:27 +08:00
Mike Yuan 3baab23b25
sd-daemon: downgrade log level for library code, use correct errno
Follow-up for 13b67b61b3
2024-04-27 19:38:16 +08:00
Mike Yuan 3e9fcc2163
sd-daemon: minor modernization, use assert_return 2024-04-27 19:26:49 +08:00
Dmitry V. Levin c309b9e9c3 treewide: fix a few typos in NEWS, docs, comments, and log messages 2024-04-27 12:11:13 +02:00
Mike Yuan 66825795b4
core/namespace: modernize mount_private_dev 2024-04-27 17:23:18 +08:00
Mike Yuan 6117dda8de
core/namespace: modernize clone_device_node 2024-04-27 17:14:03 +08:00
Luca Boccassi ec361ea9ce Fix spelling errors found by Lintian 2024-04-27 10:58:35 +02:00
Mike Yuan 16871b608e
core/namespace: use FOREACH_ARRAY at one more place 2024-04-27 14:30:29 +08:00
Mike Yuan 0afd4d214f
core/execute: switch mount_apivfs to tristate
No functional change, just refactoring.
2024-04-27 14:30:29 +08:00
Mike Yuan b0c49dbcd7
core/manager-serialize: deserialize handoff-timestamp fds
Follow-up for 817062e621

Fixes #32512
2024-04-27 14:30:29 +08:00
Mike Yuan 0541d2959a
core: use close_and_replace more when deserializing
Addresses https://github.com/systemd/systemd/pull/32441#discussion_r1579149873
2024-04-27 14:30:28 +08:00
Mike Yuan 00dc018fa6
core/load-fragment: add one missing assertion 2024-04-27 14:28:53 +08:00
Luca Boccassi 89d53001da
Merge pull request #32504 from bluca/test_failure
test: do not fail if mknod() fails in a build system
2024-04-26 19:55:24 +02:00
Luca Boccassi e86e9ebf60 test: modernize test-dirent-util
Follow-up for 6a57d86bf9
2024-04-26 17:20:04 +01:00
Luca Boccassi 7d967aacce test: do not fail if mknod() fails in a build system
mknod fails in a Salsa container when building Debian packages, skip the check

Follow-up for 6a57d86bf9
2024-04-26 17:20:04 +01:00
Frantisek Sumsal 6a68270c97 import: skip the whole subdir when building with -Dimportd=false
Resolves: #32501
2024-04-26 17:14:07 +02:00
Frantisek Sumsal fea14ca15e mountfsd: drop explicit dependencies for systemd-mountwork
As the executables are automagically linked against libshared.
2024-04-26 17:14:07 +02:00
Daan De Meyer 13b67b61b3 sd-daemon: Replace SO_LINGER with shutdown() + recv()
Let's shutdown the write end and wait for EOF from the other side
before continuing to make sure that the receiver has received all
data we sent on the socket.
2024-04-26 15:11:38 +02:00
Mike Yuan 01a0896f3c
core/exec-invoke: use FOREACH_ARRAY more, drop unnecessary initialization
for some fields
2024-04-26 10:24:39 +08:00
Mike Yuan e2663cbd39
core/namespace: check error first, add missing assertion 2024-04-26 10:24:38 +08:00
Mike Yuan a0a09da45e
mount-setup: fix typo 2024-04-26 10:24:38 +08:00
Luca Boccassi ffd8149bc0 sd-radv: remove unnecessary check
in6_addr_prefix_intersect() returns a bool, so the check < 0 is
dead code. Flagged by codeql.

Follow-up for c7c56724a5
2024-04-26 07:03:27 +09:00
Lennart Poettering b24c384b5d varlink: make errors returned by verify_unix_socket() systematic
Previously, if we encountered a non-socket fd we'd return ENOTSOCK the
first time, but the subsequent times we'd return ENOMEDIUM, due to
caching. Let's make sure we return the same errors all the the time.
2024-04-25 22:17:30 +02:00
Daan De Meyer 74e07b33b0 sd-daemon: Set SO_LINGER on AF_VSOCK notify socket fds
We're still seeing problems in mkosi CI where we lose notify messages
sent over vsock from virtual machines because the virtual machine shuts
down before the socket buffers are flushed.

Let's try setting SO_LINGER on vsock sockets so that the kernel waits
until the buffers are flushed when we close the file descriptor.

To make sure it works, let's get rid of our previous workaround that
sends EXIT_STATUS earlier to reduce the chance of it not arriving.
This way, if it doesn't work, we'll notice it immediately due to CI
failures.
2024-04-25 21:29:34 +02:00
Łukasz Stelmach e85be4983d Fix _do_log conditions in log_exec_* macros
The expression for calculation of the _do_log values in the log_exec_*
macros need to be the same as the unit_log_level_test() function, used
to calculate _do_log in unit.h. The only difference between execute.h
and unit.h is the lack of the Unit structure.

Fixes: b646fc324a ("core: ensure execute/spawn functions can work without Unit object")
Fixes: 210ca71cb5 ("core/execute: clean up log_exec_full_errno and friends")
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
2024-04-25 18:24:36 +02:00
Daan De Meyer 2541f28e4b
Merge pull request #32477 from DaanDeMeyer/fixes
Various fixes
2024-04-25 18:24:09 +02:00
Luca Boccassi 8e0bd955fe
Merge pull request #32474 from poettering/varlink-no-pidfd
varlink: tweak fallback for SO_PEERPIDFD on old kernels
2024-04-25 17:27:18 +02:00
Luca Boccassi c929c6a987
Merge pull request #32467 from yuwata/network-radv-cleanup
undefined
2024-04-25 17:10:27 +02:00
Antonio Alvarez Feijoo 5cef6b5393 cryptsetup-tokens: fix pin asserts
If a user only presses ENTER when the PIN is requested (without actually typing
the PIN), an assertion is reached and no other unlock method is requested.

```
sh-5.2# systemctl status systemd-cryptsetup@cr_root
× systemd-cryptsetup@cr_root.service - Cryptography Setup for cr_root
     Loaded: loaded (/etc/crypttab; generated)
    Drop-In: /etc/systemd/system/systemd-cryptsetup@.service.d
             └─pcr-signature.conf
     Active: failed (Result: core-dump) since Thu 2024-04-25 08:44:30 UTC; 10min ago
       Docs: man:crypttab(5)
             man:systemd-cryptsetup-generator(8)
             man:systemd-cryptsetup@.service(8)
    Process: 559 ExecStartPre=/usr/bin/pcr-signature.sh (code=exited, status=0/SUCCESS)
    Process: 604 ExecStart=/usr/bin/systemd-cryptsetup attach cr_root /dev/disk/by-uuid/a8cbd937-6975-4e61-9120-ce5c03138700 none x-initrd.attach,tpm2-device=auto (code=dumped, signal=ABRT)
   Main PID: 604 (code=dumped, signal=ABRT)
        CPU: 19ms

Apr 25 08:44:29 localhost systemd[1]: Starting Cryptography Setup for cr_root...
Apr 25 08:44:30 localhost systemd-cryptsetup[604]: Assertion '!pin || pin_size > 0' failed at src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c:60, function cryptsetup_token_open_pin(). Aborting.
Apr 25 08:44:30 localhost systemd[1]: systemd-cryptsetup@cr_root.service: Main process exited, code=dumped, status=6/ABRT
Apr 25 08:44:30 localhost systemd[1]: systemd-cryptsetup@cr_root.service: Failed with result 'core-dump'.
Apr 25 08:44:30 localhost systemd[1]: Failed to start Cryptography Setup for cr_root.
```

In this case, `cryptsetup_token_open_pin()` receives an empty (non-NULL) `pin`
with `pin_size` equals to 0.

```
🔐 Please enter LUKS2 token PIN:

Breakpoint 3, cryptsetup_token_open_pin (cd=0x5555555744c0, token=0, pin=0x5555555b3cc0 "", pin_size=0, ret_password=0x7fffffffd380,
    ret_password_len=0x7fffffffd378, usrptr=0x0) at ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c:42
42	                void *usrptr /* plugin defined parameter passed to crypt_activate_by_token*() API */) {
(gdb) continue
Assertion '!pin || pin_size > 0' failed at src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c:60, function cryptsetup_token_open_pin(). Aborting.
```
2024-04-25 17:07:11 +02:00
Daan De Meyer aa976d8788 tree-wide: Use log_setup() everywhere
Otherwise the default log target is the console and we won't use
the journal socket even if it is available.
2024-04-25 17:06:43 +02:00
Daan De Meyer f449a29bb9 portable: Don't fail if /etc/resolv.conf doesn't exist
The portable profiles assume /etc/resolv.conf exists, which isn't
always the case. Let's mark the mounts as optional so we don't fail
to start the unit if /etc/resolv.conf doesn't exist.
2024-04-25 17:06:42 +02:00
Daan De Meyer cf5e1b5d39 test: Skip meson integration tests if SYSTEMD_INTEGRATION_TESTS != 1
We cannot mark a test suite as excluded by default in meson. Instead,
let's require that SYSTEMD_INTEGRATION_TESTS=1 and skip any integration
test if it's not set. This is effectively the same as excluding it by
default. If the integration-test option is enabled, we'll set the
environment variable by default, just like we do with SYSTEMD_SLOW_TESTS
and the slow-tests meson option.
2024-04-25 17:06:40 +02:00
Lennart Poettering be3444f119 execute: make ExecStatus dump more useful by showing passed time
Let's show the runtimes of our commands and preparations for them. It's
actually quite interesting, we sometimes are irritatingly slow with our
handoffs.
2024-04-25 13:40:41 +02:00
Lennart Poettering 2b5321817f swap: hook up with handoff timestamps 2024-04-25 13:40:41 +02:00
Lennart Poettering 19ae89869e mount: hook up with handoff timestamps 2024-04-25 13:40:41 +02:00
Lennart Poettering 1f41b10ee0 socket: hookup handoff timestamps with processes forked off by socket units 2024-04-25 13:40:41 +02:00
Lennart Poettering 3c1d1ca146 manager: switch service unit type over to using new handoff timestamping logic
Also: rename Handover → Handoff. I think it makes it clearer that this
is not really about handing over any resources, but that the executor is
out off the game from that point on.
2024-04-25 13:40:41 +02:00
Lennart Poettering 12001b1bf0 execute: send handoff timestamps from executor to service manager
This changes the executor to systematically send handoff timestamps to
the service manager if a socket for that is supplied. This drops the
code that did this via Type=exec messages, and reverts that part to the
old behaviour before 93cb78aee2.

Benefits of this approach:

1. We can collect the handoff for any command we fork off, regardless
   if it's ExecStart= something else, regardless whether it's Type=exec,
   Type=simple or some any other service type, regardless of the unit
   type.

2. We collect both CLOCK_REALTIME and CLOCK_MONOTONIC, as we do for the
   other process timestamps.

3. It's entirely backwards compatible, as this doesn't change the
   protocol between service manager and executor, but just extends it.
2024-04-25 13:33:03 +02:00
Lennart Poettering 817062e621 manager: add socket for receiving handoff timestamps from forked children
This adds an AF_UNIX socket pair to the manager that we can collect
handoff timestamp messages on.

The idea is that forked off children send a datagram with a timestamp
and we use its sender PID to match it against the right forked off
process.

This part only implements the receiving side: a socket is created, and
listened on. Received datagrams are parsed, verified and then dispatched
to the interested units.
2024-04-25 13:33:03 +02:00
Lennart Poettering 33fc8b0d95 core: fix assertions in manager_dispatch_user_lookup_fd()
assert_se() should not be used here, these checks are paranoia only and
have no side-effect after all.

hence fix this to use assert(), or in fact ASSERT_PTR()
2024-04-25 13:32:25 +02:00
Lennart Poettering 78ef66354c varlink: fix varlink_get_peer_pidref() fallback
let's properly handle old kernels that have no pidfd, and use regular
pids in that case, as intended originally.
2024-04-25 12:44:00 +02:00
Lennart Poettering 47bb0b8c29 errno-util: consider ENOPROTOOPT another "not supported"
It's generated by not supported getsocktopt()/setsockopt() options, and
it's just another way for saying "not supported", hence treat it as
such.
2024-04-25 12:43:21 +02:00
Yu Watanabe 90db1582a9 run/run: fix invocation ID handling
Fixes a regression introduced by 8157cc0e3e.
2024-04-25 10:58:56 +02:00
Yu Watanabe d11ba681ab network/radv: use sd_ndisc_prefix and friends to manage prefixes and so on
No functional change, just refactoring.
2024-04-25 09:45:02 +09:00
Yu Watanabe 29d9672eb2 network/radv: rename pref64Prefix -> Prefix64
Also this made several coding style cleanups.
2024-04-25 09:44:57 +09:00
Yu Watanabe 30eab38020 network/route: use our definitions of route preference
Including linux/icmpv6.h easily trigger conflicts when another header
includes netinet/icmp6.h. Let's drop the dependency and use our
definition of the same values.
2024-04-25 09:23:31 +09:00
Yu Watanabe 68ee2ba1ee
Merge pull request #32464 from YHNdnzj/journal-object-invocation-id
journal: small fixes for OBJECT_SYSTEMD_INVOCATION_ID
2024-04-25 06:40:45 +09:00
Rasmus Villemoes dc3058e490 systemctl: list-jobs: interchange 'waiting for' and 'blocking' in output
The current output of 'systemctl list-jobs' with the --after and/or --before
switches seems backwards. With artificial units

# check-oil.service
[Unit]
Description=Check the oil level
Before=engine-ready.target

# fill-gas.service
[Unit]
Description=Fill the tank with gasoline
Before=engine-ready.target

# engine-ready.target
[Unit]
Description=The engine is ready

[Unit]
Description=Start the engine!
After=engine-ready.target
Wants=engine-ready.target

running 'systemctl list-jobs --before --after' produces

JOB UNIT                                              TYPE  STATE
93  check-oil.service                                 start running
└─      waiting for job 94 (engine-ready.target/start)   -     -
102 fill-gas.service                                  start running
└─      waiting for job 94 (engine-ready.target/start)   -     -
94  engine-ready.target                               start waiting
└─      waiting for job 111 (start-engine.service/start) -     -
└─      blocking job 93 (check-oil.service/start)        -     -
└─      blocking job 102 (fill-gas.service/start)        -     -
111 start-engine.service                              start waiting
└─      waiting for job 1 (multi-user.target/start)      -     -
└─      blocking job 94 (engine-ready.target/start)      -     -

Obviously, job 93 is not waiting for job 94, but rather blocking it.
2024-04-24 21:31:28 +02:00
Luca Boccassi cea14db914
Merge pull request #32458 from poettering/manager_get_units_for_pidref
core: split out manager_get_units_for_pidref() and use it at multiple places
2024-04-24 21:28:52 +02:00