Commit Graph
9247 Commits
Author SHA1 Message Date
Yu Watanabe fd7d749494 core: add varlink Reload/Reexecute methods (#39561)
Same as the D-Bus ones
2025-11-15 04:17:01 +09:00
Yu Watanabe be33b202e6 core: record transactions that have seen ordering cycles and expose them via IPC (#39210)
Closes #3829.
2025-11-14 00:41:46 +09:00
Luca Boccassi 55a1b36e91 core: add varlink Reload/Reexecute methods
Same as the D-Bus ones
2025-11-13 00:07:23 +00:00
Luca Boccassi 00c084fe02 core: prepare reload/reexec for varlink 2025-11-13 00:06:36 +00:00
Yu Watanabe 3866923a68 musl: core: there is one less usable signal when built with musl
musl internally reserves one more signal, hence we can only use 29
signals.
2025-11-13 08:02:05 +09:00
Yu Watanabe 5bb9063505 musl: hostname-util: introduce LINUX_HOST_NAME_MAX
glibc defines HOST_NAME_MAX as 64 and our code rely on that, but musl
defines the constant as 255. Let's provide our own definition for the
maximum length.
2025-11-13 08:02:05 +09:00
Mike Yuan 58686034eb core: expose transactions with ordering cycle
Closes #3829
Alternative to #35417

I don't think the individual "WasOnDependencyCycle" attrs on units
are particularly helpful and comprehensible, as it's really about
the dep relationship between them. And as discussed, the dependency
cycle is not something persistent, rather local to the currently
loaded set of units and shall be reset with daemon-reload (see also
https://github.com/systemd/systemd/issues/35642#issuecomment-2591296586).

Hence, let's report system state as degraded and point users to
the involved transactions when ordering cycles are encountered instead.
Combined with log messages added in 6912eb315f
it should achieve the goal of making ordering cycles more observable,
while avoiding all sorts of subtle bookkeeping in the service manager.
The degraded state can be reset via the existing ResetFailed() manager-wide
method.
2025-11-12 23:47:39 +01:00
Mike Yuan d3da74696b core: record transactions that have seen ordering cycles 2025-11-12 23:47:39 +01:00
Mike Yuan 0d9e79d5ca core/transaction: assign unique ids to transactions and encode them in log
Preparation for later commits, but I think this one makes
a ton of sense on its own. When debug logging is enabled
it's otherwise difficult to dig up the portion of journal
for transaction construction.
2025-11-12 23:47:38 +01:00
Mike Yuan 7ca94ff4b1 core/manager-serialize: minor coding style cleanups 2025-11-12 23:47:38 +01:00
Yu Watanabe fe6e6cb6a0 time-util: several fixlets/workarounds for supporting musl (#39688) 2025-11-13 05:18:25 +09:00
Yu Watanabe 6431f2e072 musl: time-util: introduce get_tzname() helper function
musl leaves the DST timezone name unset if there is no DST.
The helper function maps that back to no DST.
2025-11-13 03:13:55 +09:00
Mike Yuan 8be3780699 core/dbus-service: validate type of received ExecContext fds 2025-11-12 15:44:51 +01:00
Yu Watanabe 9b55c4b859 tree-wide: drop redundant inclusion of linux/prctl.h
sys/prctl.h anyway includes linux/prctl.h and actually these .c files
includes sys/prctl.h. Hence, it is not necessary to explicitly include
linux/prctl.h.
2025-11-12 14:17:44 +08:00
Yu Watanabe a2366debce core/exec-credentials: port to new mount API, ensure atomicity for creds installation (#39637) 2025-11-12 09:00:23 +09:00
Mike Yuan 1d73c596fa core/exec-invoke: do not check array being non-NULL
Addresses
https://download.copr.fedorainfracloud.org/results/packit/systemd-systemd-39680/fedora-rawhide-i386/09787959-systemd/builder-live.log.gz
2025-11-11 22:41:24 +00:00
Mike Yuan bc48ac39c4 core/exec-credential: remove no longer needed per-cred atomic update logic
Now that we guarantee at higher level that we work on unique
credential dir, this becomes unnecessary.
2025-11-10 23:06:14 +01:00
Mike Yuan 44f23805b0 core/exec-credential: work around tmpfs reconfigure bug 2025-11-10 23:06:14 +01:00
Mike Yuan d796c6b7c6 core/exec-credential: port to new mount API, ensure atomicity for creds installation
This allows us to kill a great deal of complexity imposed
by the mountns and workspace reuse.
2025-11-10 23:06:14 +01:00
Mike Yuan e4c7e4c27a mount-util: introduce fsmount_credentials_fs()
While at it, remove effectively unused size and ro params.
2025-11-10 22:38:21 +01:00
Mike Yuan 4338440c97 core/exec-credential: do not pass CGroupContext deep down the stack
The repetitive re-evaluation of device_nodes_restricted() is wasteful.
Just pre-determine whether we need to always go by IPC and store it
in a bool.
2025-11-10 22:38:21 +01:00
Mike Yuan a07c1ed05f core/namespace: hide the correct credentials tree when running in user scope 2025-11-09 22:39:42 +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
Mike Yuan 63edae360f core/import-creds: use RET_GATHER 2025-11-09 18:46:37 +01:00
Mike Yuan 61e018dfad core/import-creds: use FOREACH_ARRAY at one more place 2025-11-09 18:46:37 +01:00
Mike Yuan d0fcb614cb core/import-creds: rename import_credentials_context_free() to _done()
This is allocated on stack, hence rename as per our coding style.
While at it, make sure the struct name is consistent with funcs.
2025-11-09 18:46:36 +01:00
Mike Yuan 89e74275ad core/execute: morph exec_output_is_* to _forward_to_*
Follow-up for 379d9ae222

After the commit, the functions are only used to determine
whether journals shall be forwarded to selected targets,
hence rename as such and remove effectively unused condition
on EXEC_OUTPUT_TTY.
2025-11-08 08:54:13 +09:00
Yu Watanabe f0fdb69a8d core: assign TTY to PAM context when TTYPath= is specified
Fixes #38486 again, which was fixed by
1405d46bf9, but regressed again by
f875a8026e.

This also make it use exec_input_is_terminal().

Follow-up for f875a8026e.
2025-11-08 06:12:20 +09:00
Mike Yuan 96d4750e7e core/exec-invoke: pass the correct pid (1) to processes in pidns 2025-11-05 17:47:42 +01:00
Mike Yuan 675a4841cc core/service: do not pass $MANAGERPID and friends if pidns is employed 2025-11-05 17:28:44 +01:00
Mike Yuan dfb4b39d4d core/socket: fix alignment, extract common conditions 2025-11-05 17:28:25 +01:00
Chris Down 666cd35be4 core: Only apply unprivileged userns logic to user managers
Commit 38748596f0 ("core: Make DelegateNamespaces= work for user
managers with CAP_SYS_ADMIN") refactored the logic for when an
unprivileged process should create a new user namespace for sandboxing.

This refactor inadvertently removed a check (`params->runtime_scope !=
RUNTIME_SCOPE_USER`) that differentiated between system services and user
services.

This causes a regression in rootless containers where systemd runs
unprivileged. When starting a system service (like `dbus-broker`) that
uses sandboxing features (eg. with `PrivateTmp=yes`), systemd now
incorrectly creates a new, minimal `PRIVATE_USERS_SELF` namespace.

This new namespace only maps UID/GID 0. When dbus-broker attempts to
drop privileges to the `dbus` user (GID 81), the `setresgid(81, 81, 81)`
call fails because GID 81 is not mapped.

Restore the check to ensure that the special unprivileged sandboxing
logic is only applied to user services, as was the original intent.
System services in a rootless context will now correctly run in the
container's main user namespace, where all necessary UIDs/GIDs are
mapped.

Fixes: https://github.com/systemd/systemd/issues/39563
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2391343
2025-11-05 21:12:52 +08:00
Mike Yuan f873ac8727 core/manager: rearrange several struct fields 2025-11-05 10:40:22 +01:00
Mike Yuan 4fc9e19f7f core/manager: drop unneeded "struct" 2025-11-05 10:40:21 +01:00
Mike Yuan 185af6ebd3 core/manager: kill unused default_unit_job_id field
While at it, make sure the "Queued ... job for default target"
message is always logged, i.e. also when we fall back to
start job instead of isolate.
2025-11-05 10:39:30 +01:00
Yu Watanabe 5963cdf498 tree-wide: add missing '#pragma once' 2025-11-05 05:16:34 +09:00
Yu Watanabe 71d64f0527 core/service: reload fixlets (#39376)
Fixes https://github.com/systemd/systemd/issues/37515
2025-11-05 02:54:38 +09:00
Yu Watanabe d954161f9b core/exec-invoke: gracefully handle lack of privilege for initgroups() in user mode (#39039)
Fixes #39038
2025-11-05 02:53:05 +09:00
Mike Yuan b03e1b09af core/service: rework ExecReload= + Type=notify-reload interaction, add ExecReloadPost=
When Type=notify-reload got introduced, it wasn't intended to be
mutually exclusive with ExecReload=. However, currently ExecReload=
is immediately forked off after the service main process is signaled,
leaving states in between essentially undefined. Given so broken
it is I doubt any sane user is using this setup, hence I took a stab
to rework everything:

1.  Extensions are refreshed (unchanged)
2.  ExecReload= is forked off without signaling the process
3a. If RELOADING=1 is sent during the ExecReload= invocation,
    we'd refrain from signaling the process again, instead
    just transition to SERVICE_RELOAD_NOTIFY directly and
    wait for READY=1
3b. If not, signal the process after ExecReload= finishes
    (from now on the same as Type=notify-reload w/o ExecReload=)
4.  To accomodate the use case of performing post-reload tasks,
    ExecReloadPost= is introduced which executes after READY=1

The new model greatly simplifies things, as no control processes
will be around in SERVICE_RELOAD_SIGNAL and SERVICE_RELOAD_NOTIFY
states.

See also: https://github.com/systemd/systemd/issues/37515#issuecomment-2891229652
2025-11-04 12:18:33 +01:00
Mike Yuan 1b4cf02ada core/service: fix missing error handling for refresh-extensions control process 2025-11-04 12:17:33 +01:00
Mike Yuan 5fb8387c67 core/service: reset all reload-related states once a cycle completes
Fixes #37515
2025-11-04 12:17:33 +01:00
Mike Yuan 584e89f26e core/service: consolidate where to initialize reload_result 2025-11-04 12:17:32 +01:00
Mike Yuan 98734ac74d core/service: forbid reverting STOPPING=1
We don't permit state transition from STOPPING back to RUNNING,
hence refrain from resetting notify_state too.
2025-11-04 12:17:32 +01:00
Mike Yuan ed834f11cb core/service: split out service_notify_message_process_state()
No functional change, preparation for later changes.
2025-11-04 12:17:32 +01:00
Mike Yuan 3d888e2dad core/service: add missing serialization for notify_state
This really should be persisted across daemon-reload since
it might contain deferred state transitions.
2025-11-04 12:17:32 +01:00
Mike Yuan 38ea58a907 core/service: remove effectively unused NOTIFY_UNKNOWN state
We usually use _INVALID enum value as placeholder.

While at it, reset notify_state in service_enter_dead() for consistency.
2025-11-04 12:17:31 +01:00
Mike Yuan 1b5a9a7d56 core/service: avoid duplicate unit_add_to_dbus_queue() call
If we're changing state anyways, service_set_state() -> unit_notify()
will take care of dbus signaling for us.
2025-11-04 12:17:31 +01:00
Mike Yuan 1b272d778a core/service: introduce SERVICE_STATE_WITH_WATCHDOG 2025-11-04 12:17:31 +01:00
Mike Yuan 1773d2a207 core: drop redundant pidref_done() calls
{service,socket}_unwatch_control_pid() -> unit_unwatch_pidref_done()
is unconditionally called everywhere.
2025-11-04 12:17:31 +01:00
Mike Yuan 16a0cbe915 core/service: merge service_enter_reload_mounting() into _refresh_extensions() 2025-11-04 12:17:31 +01:00