Commit Graph
9408 Commits
Author SHA1 Message Date
Mike Yuan 95a7b7d474 core: several follow-ups for varlink EnqueueMarkedJobs() method (#40365) 2026-01-30 08:38:13 +01:00
Yu Watanabe 1d60b723a3 Fix bug in DM iteration and standardise how to iterate through DM layers (#40426)
get_block_device_harder_fd() currently only traverses one level of
device mapper stacking when looking for the underlying block device.
This causes issues with nested DM setups like dm-crypt on top of
dm-integrity, where we don't traverse enough to get the actual physical
device.

Fix this by iterating through all DM layers until we reach a device with
no underlying device. And while we're at it also make cgroups use the
same logic.

Fixes: #40419
2026-01-30 15:36:03 +09:00
Zbigniew Jędrzejewski-Szmek 64eb78135c shared/install: rework error propagation again
The immediate impulse for this change is the fedora scriptlet which called:
  /usr/lib/systemd/systemd-update-helper install-system-units cryptsetup-pre.target cryptsetup.target getty@.service ... system-systemd\x2dcryptsetup.slice system-systemd\x2dveritysetup.slice ...
which called
  systemctl preset cryptsetup-pre.target cryptsetup.target getty@.service ... system-systemd\x2dcryptsetup.slice system-systemd\x2dveritysetup.slice ...
which threw an error that system-systemdx2dcryptsetup.slice does not exist
and did nothing at all. (The backslash is consumed by the shell.)
The obvious fix here is to figure out more levels of escaping… But we should
do something more robust in such cases.

If we fail in processing of a single unit, let preset all continue processing
units, report the failure through 'changes'. At the end, return failure. In
general, for operations which operate on a list of units specified by the user,
fail the whole operation if any of the individual operations failed. The only
operation where we don't do this is 'preset-all'.

$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/ preset asdf1.servie asdf2.path; echo $?
Cannot find unit asdf1.servie.service.
Cannot find unit asdf2.path.
Failed to preset unit: Unit asdf1.servie.service does not exist
Failed to preset unit: Unit asdf2.path does not exist
1

While at it, fix double logging in the manager: dump_unit_changes() already
logs about errors, so the manager should only log on success.
2026-01-29 08:49:44 +01:00
Zbigniew Jędrzejewski-Szmek 69d130aac5 preparations for installer PR (#40446)
As suggested by @keszybz the generic preparatory work split out of
#38764
2026-01-27 15:04:47 +01:00
Lennart Poettering 6ecfa12af0 conf-files: add support for root_fd based operation
Let's make sure we can safely load configuration files based on a root
fd, including XAT_FDROOT.

(While we are at it, always pass path to root fs before fd to root fs,
following our recently updated CODING_STYLE)
2026-01-25 20:51:50 +01:00
Lennart Poettering 8d55f319fb exec-invoke: remove one level of indentation 2026-01-25 20:29:05 +01:00
Lennart Poettering c28aeab184 exec-invoke: handle PRIVATE_USERS_SELF cases together
And moving things to a switch/case sttement.
2026-01-25 20:29:05 +01:00
Mike Yuan f7823fdae0 core/varlink-manager: report individual job enqueue result if client sets 'more'
One nice property varlink has is that we can nicely report result
of individual operations on each unit, through the 'more' mechanism.
Hence do so for the EnqueueMarkedJobs() method.

Also, apply 502d6f4bc9 for varlink
method too.

While at it, use lowerCamelCase for method reply fields,
as requested in
https://github.com/systemd/systemd/pull/40365#discussion_r2702344239.
2026-01-24 00:48:03 +01:00
Mike Yuan 927b861add core/unit: make unit_queue_job_check_and_mangle_type() report bus error
Our internal logic speaks dbus errors, and that's not changing
anytime soon. Bus errors carried more comprehensive error message
hence let's always return a sd_bus_error on failure, and introduce
varlink_error_id_from_bus_error() for translation.
2026-01-24 00:48:02 +01:00
Mike Yuan 7228da61b9 core/varlink-manager: move varlink_unit_queue_job_one() to varlink-unit
It's quite likely that we'll introduce StartUnit() and alike
for varlink in the future, so the job enqueuing interface
should be generic. On top of that, the errors really belong
to Unit rather than Manager.
2026-01-24 00:48:02 +01:00
Mike Yuan 339fa01d21 core/varlink-manager: fix reload unit marker handling
If both restart and reload markers are set, the former takes
precedence.
2026-01-24 00:48:02 +01:00
Mike Yuan 24c73c7920 core/exec-invoke: switch PRIVATE_USERS_FULL to direct "0 0 UINT32_MAX" mapping
This was intended for v259. Let's get it done now, in v260.
2026-01-23 19:29:48 +01:00
Mike Yuan 6ed05d6414 core/exec-invoke: group setup_private_users*() together 2026-01-23 18:48:31 +01:00
Lennart Poettering fa41ce1142 hostnamed: after unescaping fancy name, validate it's valid UTF-8
The fancy name could contain arbitrary bytes, in escaped fashion. Before
using it, let's validate that this contains only valid UTF-8.

(Note that D-Bus might kick us off the bus if we don't ensure everything
we send around is UTF-8).

(While we are at it, do the same in PID 1, even though it's not that
important there)

Addresses this issue found by @YHNdnzj:

https://github.com/systemd/systemd/pull/40367#discussion_r2714614301

Follow-up for: #40367
2026-01-23 13:35:43 +01:00
Chris Down 7b8c4d01e6 blockdev-util: Add recursive lookup flag
Originating device lookups currently use separate entry points and
callers must decide between the single-step helper and manual looping.

Add a recursive flag to block_device_get_originating() and
block_get_originating(), and update callers to pass an explicit value.
2026-01-23 13:26:08 +08:00
Lennart Poettering d6749f35ae pid1: show fancy name field at boot, if specified 2026-01-21 21:32:49 +01:00
Mike Yuan f0f66976e7 core/dbus-execute: use strextendf_with_separator() where appropriate 2026-01-19 23:30:58 +01:00
Mike Yuan 00f459f30f core/dbus-execute: fix memleak on Mount/ExtensionImages parse failure
Define mount_image_free_many() in our usual fashion for use in
CLEANUP_ARRAY and ensure proper cleanup on error paths.
2026-01-19 23:22:32 +01:00
Mike Yuan e1388041c0 core/dbus-util: several cleanups for bus_read_mount_options()
* Make sure ret_options is initialized on success.
* Return empty mount options as-is rather than NULL-ing it -
  dbus property parser for RootImageOptions relies on it
  for resetting options for a specific partition designator.
* Format partition:options properly with strextendf, currently
  multiple ":" will be emitted.
* Allow separator to be unset if in_out_format_str is not
  needed.
2026-01-19 17:49:29 +01:00
Mike Yuan 079be1e71b core/varlink-execute: skip empty mount options
This keeps things in line with bus_append_mount_options().
2026-01-19 17:35:38 +01:00
Mike Yuan 831eb5453a core/dbus-execute: constify MountOptions 2026-01-19 17:35:37 +01:00
Yu Watanabe b7dd507cae tree-wide: use consistent format of short comment for constant argument
Follow-ups for recent changes after 93378148d4.
2026-01-20 00:22:15 +09:00
Mike Yuan 1a0df07843 core/cgroup: obsolete DefaultMemoryMin/Low=
Now that our kernel baseline is v5.7 and memory_recursiveprot
is universally enabled, remove userspace workarounds.
2026-01-19 13:33:28 +01:00
Mike Yuan d57fdbb5e2 core/cgroup: do not consider cgroup_context_has_io_config() if only IOAccounting=yes
This makes things in line with unit_has_memory_config(),
and suppresses pointless application of IO configs.
2026-01-19 13:33:28 +01:00
Mike Yuan 8292b859f3 core/cgroup: drop trusted.survive_final_kill_signal fallback for kernel < 5.7 2026-01-19 13:33:28 +01:00
Mike Yuan 6fd7c5ecdf core/namespace: remove availability checks for procfs hidepid=/subset= opts 2026-01-19 13:33:27 +01:00
Mike Yuan a91bb7459b core/exec-invoke: dedup error handling
Also, do not log about errno if it's suffciently encoded
in the log text already.
2026-01-18 16:42:22 +01:00
Mike Yuan 64a2712db5 core: rearrange MemoryTHP=
* Place related logic closer to MemoryKSM=, do not interleave
  it with various BPF delegation knobs
* MemoryTHP= is a execute directive, not namespace
2026-01-18 16:42:21 +01:00
Mike Yuan bbce82dfab core/unit: drop unneeded unit_modify_nft_set() call during coldplug
We re-realize all unit cgroups upon daemon-reload, and
cgroup_context_apply() would take care of NFT set refreshing.
No need to duplicate that in unit_coldplug().
2026-01-18 16:34:12 +01:00
Mike Yuan 417a8223af core/exec-credential: group write_credential() with maybe_decrypt_and_write_credential()
As requested in
https://github.com/systemd/systemd/pull/40093#discussion_r2661389365
2026-01-18 16:34:11 +01:00
Yu Watanabe 01885138be Assorted cleanups (#40373) 2026-01-18 14:41:44 +09:00
Heran YangandJian Wen c55aadc13e core/unit: re-find dropin paths of a unit after writting settings
Fixes: ab932a622d ("core: simplify unit_need_daemon_reload() a bit")
Fixes #35710

Co-authored-by: Jian Wen <wenjianhn@gmail.com>
2026-01-18 14:14:24 +09:00
Mike Yuan 12effc32da core/unit: several cleanups for unit_queue_job_check_and_collapse_type()
* Rename to _mangle_type() - it turned out this one doesn't collapse
  anything, but rather mangles the type if reload_if_possible is set.
  Hence name accordingly.
* Use -ELIBEXEC rather than -EUNATCH to denote dependency only units.
* Add a comment about the JOB_STOP and load state check.
2026-01-17 15:00:10 +01:00
Mike Yuan 490067d41c core/dbus-manager: be explicit that job enqueue errors are from EnqueueMarkedJobs call
Follow-up for 502d6f4bc9
2026-01-17 15:00:10 +01:00
Mike Yuan 7fb883fea8 core/dbus-unit: remove reference to cgroup v1 attribute 2026-01-17 15:00:09 +01:00
Mike Yuan 0fcad6eead core/main: use saturate_add() where appropriate 2026-01-17 15:00:09 +01:00
Lennart Poettering 947ecb0812 socket: turn of loud logging when setting up sockopts in container fails due to privs
Various socktops will fail if we run in a container, due to lack of
privs (for example SO_RECVFORCE as used by the journald sockets). That's
typically not a big issue. Hence downgrade the log level.

Follow-up for: f7df0eab8d
2026-01-17 08:47:14 +09:00
Yu Watanabe b5100a4569 conf-files: several cleanups and fixlets (#40290)
Fixes #40313.
Closes #40285.
2026-01-17 02:51:17 +09:00
Luca Boccassi 3e2a5dc2e1 dissect: support mount options when going through mountfsd, requiring privileges via polkit (#39394)
RootImageOptions=/ExtensionImages=/MountImages= all support custom
mount options, but mountfsd does not support it. Add varlink
parameters to allow callers to specify mount options so that
those directives can work as expected. Require additional privs via
polkit.
2026-01-16 14:55:02 +00:00
Yu Watanabe 2aa496312e conf-files: introduce CONF_FILES_WARN flag and set it at various places
Closes #40285.
2026-01-16 23:05:33 +09:00
Franck Bui 502d6f4bc9 core/dbus-manager: propagate meaningful dbus errors from EnqueueMarkedJobs
Previously, when `systemctl reload-or-restart --marked` failed the following
error was shown:

  Failed to start jobs: Failed to enqueue some jobs, see logs for details: Invalid argument

but no details were actually logged.

This change records failure reasons in the journal to help users identify root causes:

  # journalctl -b -e
  [...]
  systemd[1]: Queuing reload/restart jobs for marked units…
  systemd[1]: Operation refused, unit klogd.service may be requested by dependency only (it is configured to refuse manual start/stop).
2026-01-16 14:36:40 +01:00
Luca Boccassi 1bbeb78ea2 manager: add EnqueueMarkedJobs varlink method
Same as the D-Bus method. Returns array of job IDs.
2026-01-16 12:45:48 +00:00
Daan De Meyer 3fa3a4fd15 vpick: Fix pick_filter_image_any
Currently, pick_filter_image_any matches any image
with any suffix, which is way more than it should
be doing. It should only be matching images with
the .raw suffix.

Let's address this shortcoming by allowing to pass
multiple filters to path_pick(), and define
pick_filter_image_any as the combination of the
raw and directory image filters.

Fixes #40083
2026-01-16 13:07:47 +01:00
Michal Sekletar bcbf80c43d core: only activate transaction that contain useful jobs
If no real jobs were added to the transaction, do not activate it.
The JOB_NOP anchor does not perform any useful work and activating
such transaction only wastes resources.

Fixes #9751
2026-01-15 12:53:50 +01:00
Yu Watanabe 7f6cf19513 mountpoint-util: make is_mount_point_at() take usual dir_fd + path style arguments 2026-01-13 10:21:05 +09:00
Yu Watanabe 5366dbdbd4 core: fix typo
Follow-up for 32614b9aab.
2026-01-08 12:20:22 +09:00
Luca Boccassi 3a8759e5d4 dissect: support mount options when going through mountfsd
RootImageOptions=/ExtensionImages=/MountImages= all support
custom mount options, use the new mountfsd parameters to
configure them if they are specified.

This requires additioanl privileges via polkit due to security
implications of mount options, so document an example policy
that allows to use the nosuid mount option.
2026-01-07 00:47:53 +01:00
Yu Watanabe 17ea504efb core: change mount options settings so that last defined wins (#39449) 2026-01-07 04:11:29 +09:00
Luca Boccassi 9de41f677c core: change mount options settings so that last defined wins
Currently mount options are handled in such a way that the first
definition for a given partition wins, and documented as such.
Change them so that they behave like other options, and the
last specified wins.
Applies to RootImageOptions=, MountImages= and ExtensionImages=.
Switch from a linked list to an array indexed by the partition
specifier to store them.
2026-01-06 17:59:10 +01:00
Usama Arif 32614b9aab core: introduce MemoryTHP= unit file setting
Transparent Hugepages (THP) is a Linux kernel feature that manages
memory using larger pages (2MB on x86, compared to the default 4KB).
The main goal is to improve memory management efficiency and system
performance, especially for memory-intensive applications.
However, it can cause drawbacks in some scenarios, such as memory
regression and latency spikes. THP policy is governed for the entire
system via /sys/kernel/mm/transparent_hugepage/enabled.
However, it can be overridden for individual workloads via prctl(2)
call.
MemoryTHP= is used to disable THPs at exec-invoke to stop
providing THPs for workloads where the drawbacks outweigh the advantages.
When set to "disable", MemoryTHP= disables THPs completely for the
process, irrespecitive of global THP controls.
When set to "madvise", MemoryTHP= disables THPs for the process except
when specifically madvised by the process with MADV_HUGEPAGE or MADV_COLLAPSE.
2026-01-06 03:26:14 -08:00