Commit Graph
8933 Commits
Author SHA1 Message Date
Lennart Poettering 51cc3825d1 tree-wide: use sd_bus_message_send() instead of sd_bus_send() wherever possible
Also, add a coccinelle script that patches this automatically.
2025-06-24 23:23:40 +09:00
Yu Watanabe 4aedee430b core: turn ordering cycle log message into a recognizable one + catalog entry (#37893)
Fixes: #35642
2025-06-24 02:56:07 +09:00
Lennart Poettering becbd2ec4e core: when removing a job from a transaction, include in structured log message which 2025-06-23 16:47:06 +02:00
Lennart Poettering 6650e21349 core: cast log_oom() got void 2025-06-23 16:47:06 +02:00
Lennart Poettering fe458ad68e core: change ordering cycle log message log levels
Let's downgrade the log message about our attempts to deal with an
ordering cycle to warning, because this is a "positive" thing, we try to
improve an earlier error.

OTOH increase the log level when we first log about the cycle to error,
since that highlights the actual problem.
2025-06-23 16:47:06 +02:00
Lennart Poettering 5bbad6244f core: make log cycle messages recognizable via message IDs 2025-06-23 16:47:06 +02:00
Lennart Poettering 201647e3f2 core: output log cycle path in one log message, not many
Fixes: #35642
2025-06-23 16:47:06 +02:00
Yu Watanabe 2a5f950e56 glob-util: rework safe_glob()
Currently, callers of safe_glob() set an empty glob_t or glob_t with
opendir func, and all other components are always zero.
So, let's introduce safe_glob_full() which optionally takes opendir
function, rather than glob_t, and returns result strv, rather than
storing results in glob_t.
Also, introduce safe_glob() which is a trivial wrapper of
safe_glob_full() without opendir func.

No functional change, just refactoring.
2025-06-23 23:11:44 +09:00
Valentin David 0dc39dffbd Use paths specified from environment variables for /etc configuration files
Some configuration files that need updates are directly under in /etc. To
update them atomically, we need write access to /etc. For Ubuntu Core this is
an issue as /etc is not writable. Only a selection of subdirectories can be
writable. The general solution is symlinks or bind mounts to writable places.
But for atomic writes in /etc, that does not work. So Ubuntu has had a patch
for that that did not age well.

Instead we would like to introduce some environment variables for alternate
paths.

 * SYSTEMD_ETC_HOSTNAME: /etc/hostname
 * SYSTEMD_ETC_MACHINE_INFO: /etc/machine-info
 * SYSTEMD_ETC_LOCALTIME: /etc/localtime
 * SYSTEMD_ETC_LOCALE_CONF: /etc/locale.conf
 * SYSTEMD_ETC_VCONSOLE_CONF: /etc/vconsole.conf
 * SYSTEMD_ETC_ADJTIME: /etc/adjtime

While it is for now expected that there is a symlink from the standard, we
still try to read them from that alternate path. This is important for
`/etc/localtime`, which is a symlink, so we cannot have an indirect symlink or
bind mount for it.

Since machine-id is typically written only once and not updated. This commit
does not cover it. An initrd can properly create it and bind mount it.
2025-06-23 15:32:11 +02:00
Lennart Poettering 222b0b05ce core: escape UTF-8 in mount unit Where field before sending to clients
Followup for: 4804da5853 #27541

Fixes: #36206
2025-06-21 02:22:28 +09:00
Lennart Poettering 9ea5a6e7d6 fs-util: replace symlink_atomic_full_label() by a flag to symlinkat_atomic_full()
More porting work to label_ops_pre()/label_ops_post()

This also enables labelling of the /etc/localtime symlink in
systemd-firstboot, which should address one small facet of #37857
2025-06-18 10:21:25 +02:00
Lennart Poettering 279962a9e8 core/timer: Introduce RandomOffsetSec= knob (#36437)
This is like RandomDelaySec, but it doesn't reset whenever the manager
restarts.

Fixes https://github.com/systemd/systemd/issues/21166
2025-06-17 16:05:12 +02:00
Mike Yuan 85352c095e various: turn off SO_PASSRIGHTS where fds are not expected 2025-06-17 13:16:44 +02:00
Mike Yuan 5c12797fc3 core/socket: introduce AcceptFileDescriptors=
This controls the new SO_PASSRIGHTS socket option in kernel v6.16.
Note that I intentionally choose a different naming scheme than
Pass*=, since all other Pass*= options controls whether some extra
bits are attached to the message, while this one's about denying
file descriptor transfer and it feels more explicit this way.
And diverging from underlying socket option name is precedented
by Timestamping=. But happy to change it to just say PassRights=
if people disagree.
2025-06-17 13:16:42 +02:00
Mike Yuan 35462aa14a core/socket: add PassPIDFD= 2025-06-17 13:16:41 +02:00
Mike Yuan b81a14b91e core/socket: use universal format string for socket option warnings 2025-06-17 13:16:08 +02:00
Mike Yuan b36ab0d4ce core/socket: don't suggest PassFileDescriptorsToExec= is a socket option
by not interleaving it among socket options.
2025-06-17 13:16:07 +02:00
Mike Yuan d9bf815093 string-util: introduce strprepend_with_separator() 2025-06-11 12:50:51 +09:00
Lennart Poettering d83ceacc7e tree-wide: say in log message that we ignore error conditions of certain sockopts
Follow our usual style on this.

Follow-up for: #37793
2025-06-10 16:34:51 +09:00
Luca Boccassi bb887cf22e socket: downgrade not-supported logging for SO_PASSSEC
Kernel 6.16 started returning EOPNOTSUPP when a required kconfig
is disabled. Downgrade to debug level in that case.

Fixes https://github.com/systemd/systemd/issues/37783
2025-06-09 21:51:39 +02:00
Yu Watanabe b5aed60222 selinux-setup.c: drop redundant inclusion of selinux/selinux.h
The header is anyway included by selinux-util.h in below.
2025-06-09 22:45:23 +09:00
A. Wilcox 6b783209a8 tree-wide: basename -> path_extract_filename 2025-06-06 19:06:48 +09:00
Lennart Poettering d65dc4c593 core: break lines in some overly long function calls 2025-06-06 09:04:45 +02:00
Yu Watanabe eefcf8de64 core: adding CGroup for io.systemd.Unit.List (second PR) (#37646)
This PR adds CGroup context/runtime for io.systemd.Unit.List method.

This is follow up for https://github.com/systemd/systemd/pull/37432.
2025-06-06 06:07:35 +09:00
Mike Yuan 29d1082002 core/varlink: split out dynamic-user stuff into its own source files 2025-06-06 04:31:42 +09:00
Daan De Meyer fdbfda7245 core: Various fixes for cgroup and pid namespaces (#36815) 2025-06-05 15:21:59 +02:00
Ivan Kruglov 8006ab9047 core: adding CGroup runtime for io.systemd.Unit.List 2025-06-05 04:05:05 -07:00
Ivan Kruglov dffde7708a core: adding CGroup context for io.systemd.Unit.List 2025-06-05 04:05:05 -07:00
Ivan Kruglov 27a10f4f2a core: *ret = NULL for early return in unit_mounts_for_build_json() 2025-06-05 03:59:36 -07:00
Daan De Meyer f8f67eab70 core: Make sure we handle DelegateSubgroup= in combo with cgroupns
Currently, if we use a cgroup namespace together with DelegateSubgroup=,
the subgroup becomes the root of the cgroup namespace because we move the
service process to the subgroup before we unshare the cgroup namespace, and
the current cgroup becomes the root of the cgroup namespace when we unshare
the cgroup namespace.

Let's fix the problem by not moving the service process to the subgroup until
we've unshared the cgroup namespace. Note that this doesn't break the primary use
case of CLONE_INTO_CGROUP since we still use it to immediately clone into the service
main cgroup, just not anymore into the subgroup, but this shouldn't matter in practice.

Additionally, we need special handling for control processes, as those *do*
need to get spawned into the subcgroup immediately if delegation is configured to
avoid violating the cgroupsv2 "no inner processes" rule.

Effectively, this leaves us with the following logic:
- In exec_spawn(), spawn into subgroup if we're spawning a control process
  that needs to be spawned into a subgroup immediately. Otherwise, spawn into
  main service cgroup.
- In exec_invoke(), move into subgroup early if we don't need a cgroup namespace.
  Otherwise, move into subgroup after we've unshared the cgroup namespace.
2025-06-05 12:37:02 +02:00
Daan De Meyer 2d8191f4af core: Disable pid namespacing for control processes
PID namespaces frankly don't make any sense for control processes, so
let's gracefully degrade to no pid namespaces for control processes.
2025-06-05 12:37:02 +02:00
Mike Yuan ea763af4a9 core/cgroup: make various functions static
Not used externally anymore with previous commits.
2025-06-04 22:03:48 +02:00
Mike Yuan 9fe837d529 core/unit-printf: port to unit_get_cgroup_path_with_fallback() 2025-06-04 22:03:48 +02:00
Mike Yuan 23ac08115a core: rework how we track cgroup realized state
Prompted by https://github.com/systemd/systemd/pull/37646#discussion_r2126882561

Follow-up for 879952a853

Currently, almost all cgroup attr getters check cgroup_path for whether
cgroup is around. This is actually great, because we never want to expose
a non-existent cgroup path via IPC and such. However, it is spuriously
initialized at places where it shouldn't be, e.g. in unit_warn_leftover_processes().
This matters especially to units that *may* carry processes to run, but
not *always*, notably socket units. unit_warn_leftover_processes() is supposed
to be informative only and not try to set cgroup tracking to realized in
a half-assed way.

Hence, let's kill cgroup_realized field, and make sure cgroup_path is set
only if cgroup has been created. Be extra careful with deserialization
though, since the previous versions don't follow this rule and we need
to patch cgroup_path manually based on cgroup_realized we got from deserialization.

Calls to unit_watch_cgroup*() are dropped in cgroup_runtime_deserialize_one(),
because unit_deserialize_state() will invalidate cgroup realized state and
reapply later.
2025-06-04 22:03:47 +02:00
Mike Yuan 50f2ee4576 core/cgroup: don't ever try to get SPECIAL_ROOT_SLICE from Manager.cgroup_unit
This tries to query unit name in cgroup_unit hashmap, which
always returns NULL. Just return NULL directly instead.
2025-06-04 22:03:47 +02:00
Mike Yuan 73d7bee852 core/unit-serialize: drop deserialization compat for state_change_timestamp
This was from v228, i.e. before cgroup v2 got introduced.
Nowadays cgroup v1 is outright rejected during initialization,
i.e. upgrading isn't possible whatsoever. Remove the compat glue there.
2025-06-04 22:03:47 +02:00
Jelle van der Waa 1cce9d930a treewide: correct argument comment to 'ret' where applicable
For functions with one return argument prefer 'ret' as argument comment.
2025-06-04 13:32:24 +02:00
Yu Watanabe 813fcf2a8a core/varlink: use forward.h at two more places 2025-06-04 04:57:32 +09:00
Zbigniew Jędrzejewski-Szmek b83f69952b Deduplicate error string patterns (#37676)
I wanted to see if moving moving out constant string arguments our of
error messages results in smaller binary sizes. Turns out it does, but
the savings are not consistent. Sometimes we get a few kB in a single
binary, sometimes there is no size change.
2025-06-02 15:34:17 +02:00
Adrian Vovk 554130faf3 Define uid range for greeter
In multi-seat scenarios, a display manager might need to start multiple
greeter sessions. But systemd allows at most one graphical session per
user. So, display managers now have a range of UIDs to dynamically
allocate users for their greeter sessions.
2025-06-02 11:19:12 +02:00
Zbigniew Jędrzejewski-Szmek 42ba99748d various: do not include file names directly in error messages
git grep -l 'Failed to open /'|xargs sed -r -i 's|"Failed to open (/[^ ]+): %m"|"Failed to open %s: %m", "\1"|g'
git grep -l $'Failed to open \'/'|xargs sed -r -i $'s|"Failed to open \'(/[^ ]+)\': %m"|"Failed to open %s: %m", "\\1"|g'
git grep -l "Failed to open /"|xargs sed -r -i $'s|"Failed to open (/[^ ]+), ignoring: %m"|"Failed to open %s, ignoring: %m", "\\1"|g'
+ some manual fixups.
2025-06-02 11:10:38 +02:00
Zbigniew Jędrzejewski-Szmek 3f1812180b core/smack-setup: use RET_NERRNO and RET_GATHER 2025-05-31 16:36:43 +02:00
Zbigniew Jędrzejewski-Szmek 5890a77540 core/smack-setup: rework message to include full paths to files
We'd print the filename, but not the full path. Error messages without
the full path are annoying to users since they might not know where the file
is located, esp. if the name is fairly generic, and it is harder to search
for the error message too.

Use a trailing slash to indicate when we're trying to open a directory.
Drop quotes from around paths which are static and known to contain no
whitespace.
2025-05-31 16:03:55 +02:00
Zbigniew Jędrzejewski-Szmek 2b2ca7ff2a core: do not include names directly in error messages
This allows some strings constants to be deduplicated.
libsystemd-core.so + systemd are about 2k smaller.

Also tweak some messages for consistency. We used 'exec' in one place and
'execute' in all other messages.
2025-05-31 15:35:02 +02:00
Lennart Poettering 1105f8d20f tree-wide: only use .si_pid field in siginfo_t, if .si_code indicates that's safe
Fixes: #37498
2025-05-31 14:48:37 +02:00
Christian Glombek 0af9937691 portable,sysext: match extension OS ID also against host ID_LIKE 2025-05-31 10:02:11 +09:00
Yu Watanabe 8e9c003e29 core/cgroup: update comment
We do not have SetProperty() method, but SetProperties().
2025-05-31 04:15:04 +09:00
Yu Watanabe ab5587d674 core/transaction: restart dependency loop when a new dependency is added (#37465)
Fixes #36031.
2025-05-31 04:01:06 +09:00
Mike Yuan 6131dc0aad core/exec-invoke: skip query of /dev/console $TERM if we're child of pid1 2025-05-29 21:25:28 +02:00
Mike Yuan 8ffebaaf4d core/exec-invoke: propagate $COLORTERM and $NO_COLOR from pid1 as well
Follow-up for 19aff5f775
2025-05-29 21:16:28 +02:00