Commit Graph

9184 Commits

Author SHA1 Message Date
Daan De Meyer
9e26ced980 core: Add RootDirectoryFileDescriptor=
RootDirectory= but via a open_tree() file descriptor. This allows
setting up the execution environment for a service by the client in
a mount namespace and then starting a transient unit in that execution
environment using the new property.

We also add --root-directory= and --same-root-dir= to systemd-run to
have it run services within the given root directory. As systemd-run
might be invoked from a different mount namespace than what systemd is
running in, systemd-run opens the given path with open_tree() and then
sends it to systemd using the new RootDirectoryFileDescriptor= property.
2025-10-31 13:09:51 +01:00
Daan De Meyer
456ee3c5f9 core: Rename bus_set_transient_std_fd() and remove unused name argument 2025-10-30 23:37:06 +01:00
Mike Yuan
a274cb0cff core/exec-invoke: switch keep_fds to heap allocation
Hardcoding total size of the array is error-prone, especially
considering the exeuctable_fd is added far below, so the '4' is
not entirely obvious. Also we seldomly do VLAs.
2025-10-30 17:47:30 +01:00
Mike Yuan
f70346fb87 core/exec-invoke: store all stashed fds in ExecParameters, incl. OpenFile= ones
Keeping a half-detached counter around brings nothing
but confusion, and leads to fd leak in error paths.
2025-10-30 17:47:30 +01:00
Mike Yuan
f4314f2fbc core/exec-invoke: do not discard stashed fds when stdio is connected to socket
This makes zero sense. Not sure how it got introduced...
2025-10-30 17:47:30 +01:00
Mike Yuan
d93fff5c0c core/service: also pass sockets to control processes when stdio is named fd 2025-10-30 17:47:30 +01:00
Mike Yuan
c954830fa9 core/service: only pass socket fds to control processes
If socket is used as stdio, we'd currently imply EXEC_PASS_FDS
and dump the whole set of fds to the control processes. This is
pretty much unexpected and unnecessary though, instead let's
pass only the socket fds.

Yes, this is a compat break, but a relatively minor one I'd
argue. And we can always revisit things if users do complain.
2025-10-30 17:47:29 +01:00
Mike Yuan
d85d98f406 core/execute: merge n_storage_fds and n_extra_fds into stashed_fds
The distinction between fdstore and extra fds is only meaningful
to struct Service. As far as executor is concerned they're just
some fds to pass to the service. Let's just merge it hence,
for the sake of simplicity.
2025-10-30 17:47:29 +01:00
Mike Yuan
f78e7ca7da core/execute: serialize fd_names only if there're fds to pass 2025-10-30 17:47:29 +01:00
Mike Yuan
3299fb4ba7 core/execute: reorder ExecParameters fields 2025-10-30 17:47:28 +01:00
Mike Yuan
75e05a9880 core/exec-invoke: rename process earlier
This is independent of any other setup stages, and should
happen as early as possible to make comm logged by journald
accurate.
2025-10-30 17:45:34 +01:00
Mike Yuan
edb8fcd813 core/exec-invoke: set exit_status on exec_context_named_iofds() failure 2025-10-30 16:12:14 +01:00
Mike Yuan
04072ad9ed core/exec-invoke: do not attempt to use fdstore/extra fds for stdio
According to systemd.exec(5):

> The fd:name option connects standard input to a specific, named
> file descriptor provided *by a socket unit*. ...

Currently however we're looking at the whole fd array passed,
fix it.
2025-10-30 16:12:14 +01:00
Mike Yuan
234d8f8bc3 core/exec-invoke: drop redundant stdio_fdname checks
exec_context_fdname() would never return NULL if corresponding
stdio mode is set to named fd.
2025-10-30 16:12:14 +01:00
Mike Yuan
e984e2ca26 core/execute: mark exec_context_fdname() as pure 2025-10-30 16:12:13 +01:00
Mike Yuan
2fd2d8d575 core/execute: remove unused ExecParameters.cgroup_supported
Follow-up for 188286eec6
2025-10-30 16:12:13 +01:00
Lennart Poettering
6fa83be763 main: switch explicitly to tty1 on soft-reboot
Fixes: #39462
2025-10-29 13:09:20 +01:00
Daan De Meyer
35e03f6302 core: Don't setup mount propagation tunnel if not required
If we know we have mount_setattr(), then we don't need the mount
propagation tunnel, so don't set it up.
2025-10-29 12:01:02 +01:00
Mike Yuan
a169a952b6 core/exec-invoke: use strnpcpy() where appropriate 2025-10-25 19:31:06 +02:00
Yu Watanabe
f03b49b079 core/exec-invoke: relax restriction for process name length
Previously, we limit the length of process name by 8.
This relax the restriction then at least process comm or
program_invocation_name contains the untrucated process name.

Closes #38367.
2025-10-25 18:50:32 +02:00
Yu Watanabe
63649394cc pcre2-util: drop trivial pattern_free() wrapper 2025-10-25 11:43:00 +09:00
Yu Watanabe
afb9b7c581 apparmor-util: drop 'sym_' prefix from cleanup functions 2025-10-25 11:21:12 +09:00
Yu Watanabe
d0520b1ee7 module-util: drop 'sym_' prefix from cleanup functions 2025-10-25 11:12:16 +09:00
Yu Watanabe
256d6f3f2f capability-util: rework capability_gain_cap_setpcap() and capability_bounding_set_drop()
This makes the functions use CapabilityQuintet, capability_get(), and
capability_apply().
2025-10-24 01:52:59 +09:00
Yu Watanabe
8eefd0f4de core: increment start limit counter only when we can start the unit
Otherwise, e.g. requesting to start a unit that is under stopping may
enter the failed state.

This makes
- rename .can_start() -> .test_startable(), and make it allow to return
  boolean and refuse to start units when it returns false,
- refuse earlier to start units that are in the deactivating state, so
  several redundant conditions in .start() can be dropped,
- move checks for unit states mapped to UNIT_ACTIVATING from .start() to
  .test_startable().

Fixes #39247.
2025-10-23 15:51:28 +02:00
theSillywhat
3331d99b49 Missing policies for polkit as mentioned in freedesktop.org/software/systemd/man 2025-10-22 16:20:44 +02:00
Daniel Foster
c7a444a9c1 tree-wide: extend $LISTEN_FDS protocol with $LISTEN_PIDFDID
Although extremely unlikely, there is a race present in solely checking the
$LISTEN_PID environment variable, due to PID recycling. Fix that by introducing
$LISTEN_PIDFDID, which contains the 64-bit ID of a pidfd for the child process
that is not subject to recycling.
2025-10-22 09:34:14 +02:00
Ivan Kruglov
959a8e49f4 core: enable SELinux checks in io.systemd.Unit.List 2025-10-20 03:58:55 -07:00
Ivan Kruglov
6c2c2e0598 core: io.systemd.Unit.List can lookup by InvocationID 2025-10-20 03:58:53 -07:00
Ivan Kruglov
6b78d931cd core: io.systemd.Unit.List can lookup unit by CGroup 2025-10-20 03:58:39 -07:00
Ivan Kruglov
4ddd3fe1fb core: make name/pid lookup params use AND logic in io.systemd.Unit.List 2025-10-20 02:10:57 -07:00
Daan De Meyer
b8ee7c2206 tree-wide: Various forward header cleanups
- Make sure forward headers have the iwyu pragma to always keep them
- Make sure we always include the daemon specific forward header
  instead of shared-forward.h
- Remove shared-forward.h include where the daemon specific forward
  header is already included
2025-10-17 21:11:23 +09:00
Mike Yuan
28aa0a1f25 core/mount: properly handle REMOUNTING_* states in mount_stop() (#39269) 2025-10-16 20:50:03 +02:00
Matteo Croce
e1e16b4763 core: fix build error due to merge conflict in varlink-execute.h
During last refactor, an include wasn't changed and led to a build
error.

Follow-up for fdb2c0dd6f
2025-10-16 19:47:40 +01:00
Luca Boccassi
c92b14ec13 dissect: add support for verity-protected bare filesystems via mountfsd (#39325)
Needed to implement support for RootHashSignature=/RootVerity=/RootHash=
and friends when going through mountfsd, for example with user units,
so that system and user units provide the same features at the same
level
2025-10-16 19:43:45 +01:00
Daan De Meyer
06d73c5046 implement ExecContext for io.systemd.Unit.List (#38212) 2025-10-16 19:06:46 +02:00
Lennart Poettering
0aad728daa kmod-setup: don't load unix.ko as a module anymore
Building unix.ko as a module always has been a really bad idea, from day
1. Debian used to do this, but has long been fixed. Kernel developers
saw the light too, and removed support for it in 6.5
(97154bcf4d1b7cabefec8a72cff5fbb91d5afb7b). Let's hence drop support for
this here too, and delete some old cruft. AF_UNIX is simply our most
basic IPC system and supporting systems without it being around is just
not realistic.
2025-10-16 17:42:33 +02:00
Luca Boccassi
fad01f798d dissect: add support for verity-protected bare filesystems via mountfsd
Needed to implement support for RootHashSignature=/RootVerity=/RootHash=
and friends when going through mountfsd, for example with user units,
so that system and user units provide the same features at the same
level
2025-10-16 16:22:33 +01:00
Daan De Meyer
f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Luca Boccassi
ac9391c552 Support ExtensionImages=/MountImages= in user services via mountfsd and PrivateUsers=yes (#39341) 2025-10-16 15:49:46 +01:00
Luca Boccassi
68b476a298 core: also enable PrivateUsers= for user services when using images via mountfsd
RootDirectory= and other options already implicitly enable PrivateUsers=
since 6ef721cbc7 if they are set in user
units, so that they can work out of the box.
Now with mountfsd support we can do the same for the images settings,
so enable them and document them.
2025-10-16 12:58:59 +01:00
Luca Boccassi
29e97643e7 Support ExtensionImages=/MountImages= in user services via mountfsd
Support for RootImage= was added by 046a1487db
but it was not wired in for ExtensionImages=/MountImages=
2025-10-16 12:58:59 +01:00
Daan De Meyer
f875a8026e core: Don't use TTYPath= for PAM unless StandardInput=tty
Fixes #39334
2025-10-16 13:46:19 +02:00
Zbigniew Jędrzejewski-Szmek
6c80ab85f5 core/cgroup: two follow-ups for recent OOMKills PR (#39215)
Follow-ups for #38906.
2025-10-16 13:38:01 +02:00
Ivan Kruglov
fdb2c0dd6f core: ExecContext for io.systemd.Unit.List method 2025-10-16 03:52:08 -07:00
Ivan Kruglov
3064c04473 core: exec_log_level_max_with_exec_params() 2025-10-16 03:52:08 -07:00
Ivan Kruglov
fbfc439438 core: move cpuset_build_json() to varlink-common 2025-10-16 03:52:02 -07:00
Daan De Meyer
73623f1984 core: Make sure we don't clobber return argument on failure
As documented in the coding style, let's make sure we follow it.
2025-10-16 11:06:43 +01:00
Ivan Kruglov
aacfa999dd json: helper macros JSON_BUILD_PAIR_CONDITION_*() 2025-10-15 09:14:10 -07:00
Zbigniew Jędrzejewski-Szmek
53ff5b361f core: Delete redundant log_parse_environment(), v2 (#39278)
Reworked version of #39175.
2025-10-15 17:50:59 +02:00