Commit Graph
294 Commits
Author SHA1 Message Date
Lennart Poettering 90d285ade7 recurse-dir: optionally, only enumerate dentries of a specific type
At various places we filter directory enumerations by inode type. Let's
add explicit support for that, so that the "struct dirent" array we
return already suppresses them.

This shortens code and makes things more robust.
2026-06-22 14:40:16 +02:00
Lennart Poettering eb3799a373 fd-util: add wildcard_fd_is_valid() helper and use it tree-wide
Many *at()-style helpers accept a directory fd that may be either a
regular, valid fd (>= 0) or one of the special AT_FDCWD/XAT_FDROOT
wildcard values, and open-code that check in their assertions. Add a
wildcard_fd_is_valid() helper for it and use it tree-wide.
2026-05-28 13:33:08 +01:00
Zbigniew Jędrzejewski-Szmek 39a3647539 tree-wide: get rid of old dispatch_verb
Also rename dispatch_verb_with_args to dispatch_verb.
2026-05-16 18:37:10 +02:00
Zbigniew Jędrzejewski-Szmek 587c522487 various: fix duplicated logging from parse_path_argument
As pointed out in review, parse_path_argument can fail for non-oom reasons.
But the function already logs, so the correct thing to do is to just
propagate the error.
2026-05-14 14:15:55 +02:00
Zbigniew Jędrzejewski-Szmek 71c3123b17 kernel-install: convert to the new option and verb parsers
The verb synopses are very long because of the many parameters.
Previously were shown without help and occupied all available columns.
With the autogenerated help format, this doesn't work great. So the
verbs and options tables are not synced, so that help for options can
use more columns. I think in this case this is better than the
alternatives.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-14 14:15:50 +02:00
Daan De Meyer 79862d33a0 chase: add explicit root_fd parameter to chaseat() and drop CHASE_AT_RESOLVE_IN_ROOT
Split the single directory fd that chaseat() used to take into two separate
fds: a root_fd that sets the chroot boundary (symlinks may not escape it,
absolute symlinks resolve relative to it), and a dir_fd that path resolution
starts from. This makes the chroot semantics of chaseat() explicit at every
call site instead of encoding them in the CHASE_AT_RESOLVE_IN_ROOT flag,
which is removed. It also decouples the starting directory from the root
boundary, so callers can descend from any inode inside the tree without
having to reopen the root separately.

XAT_FDROOT passed as root_fd means "no containment" (host root); as dir_fd
it means "start at root_fd". For a smoother transition, AT_FDCWD is also
accepted as root_fd and treated as XAT_FDROOT. When root_fd points to a
directory that is actually the host root, it is normalized to XAT_FDROOT
up front so the existing shortcut path can kick in.

Absolute paths returned by chaseat() are now relative to root_fd, and
relative paths are relative to dir_fd. The result is absolute only when
there is no chroot boundary (root_fd is XAT_FDROOT), or when an absolute
symlink made resolution jump out of the dir_fd subtree; otherwise callers
get a relative path they can feed straight back into an openat()-style
call against dir_fd. Specifically, when dir_fd == root_fd and we're not
operating on the host's root directory, we return a relative path even if
we received an absolute path or resolved an absolute symlink to allow
passing the path directly to openat() style functions. We do this to not
have to go modify every caller of chaseat() to make sure they deal properly
with any absolute paths they might receive. Only when root_fd != dir_fd do
we have to return an absolute path to indicate that the path is relative to
root_fd and not dir_fd.

The shortcut that skips the per-component walk is reworked around a new
chase_xopenat() helper that funnels CHASE_NOFOLLOW, CHASE_MUST_BE_* and
CHASE_TRIGGER_AUTOFS through xopenat_full()'s O_NOFOLLOW, O_DIRECTORY,
XO_REGULAR, XO_SOCKET and XO_TRIGGER_AUTOMOUNT flags. As a result these
flags no longer force us off the shortcut and can be dropped from
CHASE_NO_SHORTCUT_MASK, and the old openat_opath_with_automount() helper
goes away. A CHASE_MUST_BE_ANY alias is introduced for shortcut callers
(stat/access paths) that don't go through xopenat_full() and still need
to bail on those flags locally.

All *_and_* helpers built on top of chaseat() (chase_and_openat,
chase_and_opendirat, chase_and_statat, chase_and_accessat,
chase_and_fopenat_unlocked, chase_and_unlinkat, chase_and_open_parent_at)
gain the same root_fd parameter, and every call site in the tree is
ported to the new signature.

chase_and_open() is also fixed to correctly handle CHASE_EXTRACT_FILENAME
without CHASE_PARENT.
2026-04-20 23:35:31 +02:00
Lennart Poettering 853d0649d5 find-esp: return pinned fd to ESP/XBOOTLDR
The reworks the ESP/XBOOTLDR logic to pin the ESP/XBOOTLDR via an fd,
and return that as optional return parameter.

So far we only pinned the parent dir of the ESP/XBOOTLDR, which was
useful when verifying that ESP/XBOOTLDR is actually a mount point by
comparing mount ids. This however became obsolete with
a98a6eb95c. Hence, let's clean this up,
and pin the inode we really care about and return it.
2026-04-20 17:19:27 +02:00
Michael Vogt bd141bd818 many: fix remaining check-pointer-deref issues
The updated parsing_hacks.h file uncovered a bunch of extra
things that the check-pointer-deref coccinelle script flags.

This commit fixes them to make the tree check-pointer-deref clean.
2026-04-12 15:27:15 +02:00
Lennart Poettering d90d0a1f63 kernel-image: minor refactoring to inspect_kernel()
Let's add make three arguments optional, by splitting inspect_kernel()
from inspect_kernel_full().

Let's also downgrade logging to debug, so that this becomes more
library-like. Let's log on the call-site instead.
2026-04-03 08:15:27 +02:00
Cynthia 0c2747e789 kernel-install(uki): filter comments from cmdline
This change aligns the behaviour of UKI generation with the behaviour
of BLS. The latter filters out lines starting with a #, allowing users
to add comments and/or temporarily remove some flags from the kernel
command line.

The kernel-install test have been adjusted to use a multiline cmdline
with a comment in it. Without this patch, the test fails.
2026-03-26 14:28:22 +01:00
Robin Ebert 55e7dc5ce4 kernel-install: fix assert in context_copy 2026-03-20 15:17:44 +01:00
Zbigniew Jędrzejewski-Szmek 31ddd87da0 tree-wide: extend verbs functions with extra per-verb data parameter
We often have a pattern where the same verb function is used for
multiple actions. This leads to an antipattern where we figure out what
action needs to be taken from argv[0] multiple times: often once in
parse_argv() to figure out what options are allowed, then once again
implicitly in dispatch_verb(), and then again in the action verb itself.
Let's allow passing a parameter into the verb to simplify this.

This matches a pattern we have in conf-parser.h, where we have both
void *userdata (more global) and void *data (per-config item). Here,
I opted for uintptr_t userdata. It seems that most of the time we'll
want to just pass an enum value. This works OK with no casts. I also
tried a void* and union. In both cases, much more boilerplate is needed:
either a cast or a macro to help avoid compiler warnings. uintptr_t
seems generic enough to cover foreseeable usecases with no fuss.

This is a noop refactoring. See next commit for an example.
2026-03-18 10:28:47 +00:00
Lennart Poettering 8a2c423870 find-esp: introduce _full() flavour of ESP/XBOOTLDR discovery functions
These functions take so many return paramaters, and in many of our cases
we don't actually needt them. Hence introduce _full() flavours of the
funcs, and hide the params by default.
2026-03-18 10:25:59 +00:00
Lennart Poettering cfee2c1900 kernel-install: allocate "Context" object only in verb_xyz() functions, not already in run()
We soon want to add a Varlink interface to this, but that means that the
various paramaters for the Context object will be sourced from a Varlink
message not from the command line. Hence split apart the parsing logic
so that we alway parse the command line into arg_xyz first, and then,
inside the verb_abc() calls copy the data from there into the Context
object.

This matches a similar pattern in bootctl.
2026-02-09 10:21:16 +01:00
Lennart Poettering 533afe86c3 kernel-install: rework in preparation for varlink
This reworks things a bit, so that the "Context" object can later be
allocated for each Varlink call separately. For example we define a
more precise CONTEXT_NULL that invalidates truly all fields, so that we
can discern "defaults" from "unspecified" later on.

Other minor rearrangements too
2026-02-09 10:21:16 +01:00
Jörg Behrmann cab4b9defd kernel-install: handle removal unsuccessful UKIs and loader entries separately
When a tries file exists, 90-uki-copy.install removes a previous UKI of the
same kernel version and all it's unbooted variants. This removal is guarded
behind a check for the existence of the already booted UKI, i.e. if uki.efi
already exists, uki.efi and uki+*.efi will be removed.

This leaves the edge case that if uki.efi does not exist, but only an unbooted,
e.g. uki+3.efi, it will not be removed. This is not a problem, if the number of
tries is constant between both builds, since a new uki+3.efi would overwrite
the existing one, but if the number of tries is changed to, e.g. uki+5.efi, we
are left with both uki+3.efi and uki+5.efi.

The same is done for loader entries.
2026-01-27 15:53:48 +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
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
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De MeyerandYu Watanabe ee6b3d1aa2 test: Stop using grep -q in integration test
When a TTY is attached to the test unit, grep -q will generate SIGPIPE
for the previous command in the pipeline which in combo with `pipefail`
will cause the command to fail with exit status 141 which will fail the
test.

Replace with >/dev/null to avoid this from happening.

See also https://www.gnu.org/software/grep/manual/html_node/Usage.html
> There is a related problem with Bash’s set -e -o pipefail. Since grep
> does not always read all its input, a command outputting to a pipe read
> by grep can fail when grep exits before reading all its input, and the
> command’s failure can cause Bash to exit.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-12-10 12:09:10 +01:00
Antonio Álvarez Feijoo 4ae16cf9b7 kernel-install: exit with option --json=help (#39974)
In that case, `parse_json_argument()` returns 0.

Follow-up for bdd36c003d (v255).
2025-12-03 01:56:01 +09:00
Mike Gilbert 1a88817b83 test-kernel-install: respect TMPDIR in expected output 2025-12-01 13:23:42 +00:00
Lennart Poettering f8fcf7de7c kernel-install: move staging area to /var/tmp/
The generated files (UKIs...) can potentially be huge, hence create them
in /var/tmp/, rather than /tmp/.
2025-11-03 09:01:44 +01:00
Yu Watanabe d1893390e5 test-kernel-install: support the case when custom default locale is specified
This also makes 'diff' command output to stderr, otherwise the
difference is eaten by meson by default, so hard to debug.
2025-10-13 10:31:43 +02:00
Mike Yuan 6870f78dcd kernel-install: drop unneeded empty_to_root() 2025-10-08 09:22:07 +02:00
Lennart Poettering 435bef5d05 kernel-install: when listing kernels sort them by version 2025-09-18 09:31:35 +02:00
Zbigniew Jędrzejewski-Szmek 66b2d758c5 various: add a fixed name to log about plugin execution
Function execute_directories logged in a way that was meaningless
without additional context:
  systemd[1]: No executables found.
In execute_strv this was partially rectified by extracting the directory
name from one of the directories and using this as the identifier. But
the directory name is not always meaningful, and can also be set from
an environment variable. Let's simplify things by providing a fixed name
that can be used consistently in all log messages. In particular this will
make error messages easier to understand if users report just the error
without additional context.
2025-09-03 08:56:23 +02:00
Zbigniew Jędrzejewski-Szmek c5dcbd073e meson: use files() not find_program() for helper scripts
We went back and forth between 'prog.sh', files('prog.sh'), and
find_program('prog.sh'). We want to use files() or find_program() so that we
get a good error message if the file is missing. Behaviour of meson changed
over time, and in the past not all forms could be used in all places. For
example 0f4c4f3824 added find_program() in many
places to avoid repeated messages. But it seems that all recent meson versions
work fine with files().

find_program prints silly messages:
  Program tools/make-man-index.py found: YES
       (/home/zbyszek/src/systemd/tools/make-man-index.py)
  Program tools/meson-render-jinja2.py found: YES
       (/home/zbyszek/src/systemd/tools/meson-render-jinja2.py)
  ...
We know that those files will be found, they are part of the git checkout.
With files() this is gone and the meson output is easier to read.
2025-07-25 14:04:17 +02:00
Li Tian 9e3c496bd3 90-uki-copy.install: Skip removing UKI related when BOOT_ENTRY_TYPE=type1
Commit b6d4997683
("Add --entry-type=type1|type2 option to kernel-install.")

Skip removing UKI related contents when BOOT_ENTRY_TYPE=type1

Signed-off-by: Li Tian <litian@redhat.com>
2025-07-15 22:56:33 +09:00
vlefebvre 96ba43388f uki.conf is used by the ukify tool to create an Unified Kernel Image. It
would make sense to install it only if ukify is wanted.
2025-07-12 00:40:08 +09:00
Yu Watanabe 19d4040d71 kernel-install: regroup options in help meesage
And slightly updates the description.

Follow-up for b6d4997683.
2025-07-11 17:32:04 +09:00
Yu Watanabe 9026f17907 kernel-install: do not mix || and &&
This also slightly updates log message, and make it shown only when
verbose mode is enabled.

Follow-up for b6d4997683.
2025-07-11 17:32:02 +09:00
Li Tian b6d4997683 Add --entry-type=type1|type2 option to kernel-install.
Both kernel-core and kernel-uki-virt call kernel-install upon removal. Need an additional argument to avoid complete removal for both traditional kernel and UKI.

Signed-off-by: Li Tian <litian@redhat.com>
2025-07-10 18:07:23 +02:00
Zbigniew Jędrzejewski-Szmek 7d247d3cb8 meson: drop explicit custom_target names
[1] says:
> Since 0.60.0 the name argument is optional and defaults to the basename of
> the first output
We specify >= 0.62 as the supported version, so drop the duplicate name in all cases
where it is the same as outputs[0], i.e. almost all cases.

[1] https://mesonbuild.com/Reference-manual_functions.html#custom_target
2025-06-28 17:14:50 +02:00
Zbigniew Jędrzejewski-Szmek 4092f72274 kernel-install: print entry-token path that was not found 2025-05-20 14:41:33 +02:00
Zbigniew Jędrzejewski-Szmek 15ff783013 kernel-install/90-loaderentry.install: print message if quiting because of KERNEL_INSTALL_LAYOUT
60-ukify.install prints a message like this, and it is quite useful when
trying to figure out what is going on.
2025-05-20 14:32:05 +02:00
Daan De Meyer 8857aa74e5 tree-wide: Clean up includes
This commit cleans up the includes for all the small tools across
the tree.

A few cases of returning EXIT_SUCCESS are replaced with returning
0 to avoid including <stdlib.h>.

Split out of #37344.
2025-05-14 22:34:02 +02:00
Daan De Meyer 6553db6063 strv: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer 76d62b63ef main-func: Reduce transitive includes
Let's move some logic from _DEFINE_MAIN_FUNCTION() and other places
in main-func.h into functions that we implement in main-func.c to
allow moving some included headers from the header to the .c file.
2025-05-06 10:07:27 +02:00
Daan De Meyer daa2547e31 Add a few more bypass environment variables
When we're building ParticleOS images, we don't want the package
manager (or mkosi) to run systemd-sysusers, systemd-tmpfiles or
systemctl preset so let's add a few more bypass environment
variables that we can set to have execution of these skipped like
we already have $SYSTEMD_HWDB_UPDATE_BYPASS and $KERNEL_INSTALL_BYPASS.
2025-03-01 16:22:53 +01:00
Lennart Poettering 37252381d2 bootctl,kernel-install: suffix some paths referring to dirs in log messages with / 2025-02-10 01:15:52 +01:00
Yu Watanabe ab676c768a kernel-install: rename $ADDON_DIR -> $EXTRA_DIR
As the directory contains not only addons, but also credentials and
extensions.

No functional change, just refactoring.

Follow-up for 75ee025c5d.
Addresses the post-merge comment
https://github.com/systemd/systemd/pull/36218#discussion_r1940872236.
2025-02-07 19:46:57 +09:00
Luca Boccassi 75ee025c5d kernel-install: install addons in 90-uki-copy.install if they are present
mkosi now has a kernel-install plugin to build addons, mkosi-addon.
If there are addons in <uki>.extra.d/ install them too to
the ESP.
2025-02-01 18:12:47 +09:00
Luca Boccassi 0747e3b60e kernel-install: remove .extra.d/ directory too
When a UKI is removed, the per-UKI .extra.d/ directory (addons,
extensions, etc) is left behind.
2024-12-01 14:05:45 +09:00
Zbigniew Jędrzejewski-Szmek 23441a3d88 sd-json,tree-wide: add sd_json_format_enabled() and use it everwhere
We often used a pattern like if (!FLAGS_SET(flags, SD_JSON_FORMAT_OFF)),
which is rather verbose and also contains a double negative, which we try
to avoid. Add a little helper to avoid an explicit bit check.

This change clarifies an aditional thing: in some cases we treated
SD_JSON_FORMAT_OFF as a flag (flags & SD_JSON_FORMAT_OFF), while in other cases
we treated it as an independent enum value (flags == SD_JSON_FORMAT_OFF).
In the first form, flags like SD_JSON_FORMAT_SSE do _not_ turn the json
output on, while in the second form they do. Let's use the first form
everywhere.

No functional change intended.

Initially I wasn't sure if this helper should be made public or just internal,
but it seems such a common pattern that if we expose the flags, we might just
as well expose it too, to make life easier for any consumers.
2024-10-28 09:23:07 +01:00
Mike Yuan 3f8999a76e fs-util: rename laccess to access_nofollow
In order to distinguish it from libc function naming.
2024-10-05 01:30:43 +02:00
Mike Yuan 7c1dd9e288 various: correct laccess() error check
laccess is our own macro that uses RET_NERRNO.
2024-10-04 21:26:04 +02:00
cvlc12 4beac1034d kernel-install: add uki.conf example 2024-09-20 08:24:15 +09:00
Yu Watanabe 6e1816ef16 kernel-install: unquote plugin paths in KERNEL_INSTALL_PLUGINS
To support the case that paths to plugins contain spaces.

Prompted by #34459
2024-09-18 09:47:00 +09:00
rindeal 374aa1be7c kernel-install: discard comments in cmdline files
It was quite a surprise to find my comments in a booted kernel cmdline.
2024-08-16 17:15:39 +09:00