Commit Graph

250 Commits

Author SHA1 Message Date
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
Daan De Meyer
b56920e36c kernel-install: Try some more initrd variants in 90-loaderentry.install
On CentOS/Fedora, dracut is configured to write the initrd to
/boot/initramfs-$KERNEL_VERSION...img so let's check for that as well
if no initrds were supplied.
2024-07-29 18:57:43 +02:00
Daan De Meyer
35c01ec59e kernel-install: Only read cmdline from /proc/cmdline when not in container
If we're running from within a container, we're very likely not going
to want to use the kernel command line from /proc/cmdline, so let's add
a check to see if we're running from a container to decide whether we'll
use the kernel command line from /proc/cmdline.
2024-07-29 18:56:30 +02:00
Jose Ignacio Tornos Martinez
eef4cd51f9 kernel-install: remove depmod generated file modules.weakdep
The new file, modules.weakdep, generated by depmod to get the weak
dpendencies information can be present
(05828b4a6e),
so remove it like the other similar files.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
2024-07-26 14:02:14 +01:00
Jörg Behrmann
99d4575e54 kernel-install: Remove existing loader entries and UKIs
When boot counting is enabled, adding a new loader entry or UKI can conflict
with an existing one that has booted successfully and therefore has its boot
counter removed. systemd-bless-boot will fail to bless the new successful boot,
since a file without a boot counter already exists. Since kernel-install will
clobber existing files without boot counting, we should therefore remove files
without a boot count as well, when we add a file with one.

Fixes: #33504
2024-07-15 10:16:36 +02:00
Daan De Meyer
6a4fcf8cef meson: Fix various versions
Follow up for 8b3b01c4b7

We switch to PROJECT_VERSION instead of PROJECT_VERSION_FULL where
we report our version and which is likely being parsed to avoid
breaking compat. If we didn't, the output would change from systemd
255 to systemd 255.1 which could break various tools.
2024-07-04 19:28:12 +02:00
Antonio Alvarez Feijoo
111f988992 kernel-install: correct the place where it works in man and help text 2024-06-20 03:01:22 +09:00
Lennart Poettering
309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Zbigniew Jędrzejewski-Szmek
3f5196ffb8 kernel-install,bootctl: unify the config parsing procedure
Fixes https://github.com/systemd/systemd/issues/32992.
2024-05-23 16:15:24 +02:00
Mike Yuan
4a77d4ceb9 kernel-install/60-ukify: also search in {/run,/usr/local/lib}/kernel/
After db26d8025e,
kernel-install takes config files under /run/
and /usr/local/lib/ into account too. The same
should apply to ukify.

Note that ukify when invoked alone searches under
/run/systemd/, /etc/systemd/, /usr/local/lib/systemd/,
and /usr/lib/systemd/, respectively, which is against
our usual order...
2024-04-22 22:38:11 +02:00
Lennart Poettering
4d619806d1 Revert "kernel-install: Add kernel version to title (#31581)"
This reverts commit 85b774de49.
2024-04-04 02:45:39 +09:00
Vitaly Kuznetsov
df94b28366 kernel-install/60-ukify: do not rebuild existing UKIs
In case kernel-install is called to install what's already a UKI, 60-ukify
must be skipped. E.g. when distro shipped and signed UKI is being installed,
it is counter-productive to try to rebuild it with ukify. Also, the existing
script is not ready to handle UKIs with embedded initramfs.

Note, it is already possible to disable 60-ukify by setting
KERNEL_INSTALL_UKI_GENERATOR to something but in case it is not set, 60-ukify
assumes it should run.
2024-03-26 03:01:30 +09:00
Yu Watanabe
839dce5ecb Merge pull request #31862 from keszybz/add-strdup_to-helper
Add strdup_to() helper
2024-03-21 14:47:05 +09:00
Zbigniew Jędrzejewski-Szmek
6a705f1234 Replace strdup_or_null() by strdup_to()
I didn't know that this helper existed… It is very similar to strdup_to_full(),
but all callers can actually be replaced by strdup_to(), which has more fitting
semantics.
2024-03-20 15:18:21 +01:00
Gerd Hoffmann
3037616d8e kernel-install: fix uki-copy deinstall
For "kernel-install remove ..." only the kernel version is passed, not
the kernel image.  So auto-detecting KERNEL_INSTALL_IMAGE_TYPE and
setting KERNEL_INSTALL_LAYOUT does not work for uninstall.

The 90-uki-copy.install plugin must consider this and *not* exit early
for the "remove" command, otherwise $BOOT_ROOT will be filled with stale
kernel images.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-03-20 11:35:13 +09:00
Zbigniew Jędrzejewski-Szmek
ec596fe34e Merge pull request #30480 from keszybz/kernel-install-more-paths
Read kernel-install config from /run/kernel too
2024-03-08 08:25:07 +01:00
Zbigniew Jędrzejewski-Szmek
db26d8025e kernel-install: support full set of config files and drop-ins
This brings the handling of config for kernel-install in line with most of
systemd, i.e. we search the set of paths for the main config file, and the full
set of drop-in paths for drop-ins.

This mirrors what 07f5e35fe7 did for udev.conf.
That change worked out fine, so I hope this one will too.

The update in the man page is minimal. I think we should split out a separate
page for the config file later on.

One motivating use case is to allow a drop-in to be created for temporary
config overrides and then removed after the operation is done.
2024-03-07 19:14:36 +01:00
Zbigniew Jędrzejewski-Szmek
5ea4afcf00 udev,backlight,kernel-install: reword sentences starting with "Skipping to"
That's not gramatically correct.

In backlight, change "assocation" to "deduplication". Without the context,
it's probably not clear at all that we "associate" them to ignore them.
2024-03-07 18:49:44 +01:00
Daan De Meyer
76940e0a04 Use VERSION_TAG instead of GIT_VERSION in kernel-install scripts
GIT_VERSION only makes sense for C files as it depends on C preprocessor
macro expansion now so let's use VERSION_TAG instead of GIT_VERSION
for the two remaining usages of GIT_VERSION that are not in C files.
2024-03-06 15:15:55 +01:00
Mike Yuan
2560dcbfe6 stat-util: generalize is_* and verify_* handling 2024-03-04 19:53:51 +00:00
Guilhem Lettron
85b774de49 kernel-install: Add kernel version to title (#31581)
When using uki, kernel installations always have the same name in
systemd-boot menu.

Signed-off-by: Guilhem Lettron <guilhem@barpilot.io>
2024-03-03 12:36:57 +00:00
Lennart Poettering
f4a63ce25f dissect-image: add flag for explicitly enabling userspace verity signature checking
let's make userspace verity signature checking optional. This adds a
dissection flag to enable the logic and patches through all our users to
enable it by default, thus effectively not changing anything from the
status quo ante. However, know we have a knob to turn this off in
certain scenarios.
2024-02-28 16:17:40 +01:00
Daan De Meyer
ea2a57bee3 meson: Start adding devel and rc suffixes to the project version
Let's make sure that versions generated by meson-vcs-tag.sh always
sort higher than official and stable releases. We achieve this by
immediately updating the meson version in meson.build after a new
release. To make sure this version always sorts lower than future
rcs, we suffix it with "~devel" which will sort lower than "~rcX".

The new release workflow is to update the version in meson.build
for each rc and the official release and to also update the version
number after a new release to the next development version.

The full version is exposed as PROJECT_VERSION_FULL and used where
it makes sense over PROJECT_VERSION.

We also switch to reading the version from a meson.version file in
the repo instead of hardcoding it in meson.build. This makes it
easier to access both inside and outside of the project.

The meson-vcs-tag.sh script is rewritten to query the version from
meson.version instead of passing it in via the command line. This
makes it easier to use outside of systemd since users don't have to
query the version themselves first.
2024-02-14 15:36:34 +01:00
Lennart Poettering
69f3c61990 tree-wide: port over various pieces of code to strv_extend_many() 2024-01-17 11:32:11 +01:00
Yu Watanabe
f8a6fc51a6 Merge pull request #30851 from lnussel/kernel-install
kernel-install fixes
2024-01-16 14:55:35 +09:00
Daan De Meyer
16e4efa7d3 tree-wide: Load entry-token and layout.conf from /usr/lib/kernel/ as well 2024-01-16 14:54:04 +09:00
Ludwig Nussel
ec9ff6ea94 kernel-install: silence num kernels installed 2024-01-15 17:16:37 +01:00
Ludwig Nussel
27d420f466 kernel-install: fix context_copy
Don't reopen or dup values that weren't set before. Fixes add-all.
2024-01-15 17:16:37 +01:00
Daan De Meyer
50cc0ee647 Add --root= support for list and prepare add-all for --root= support
Let's make sure these follow the rest of kernel-install and always
operate on the given root directory, even if the verb itself can't
support --root= just yet.
2024-01-12 14:37:00 +00:00
Antonio Alvarez Feijoo
398760c84a kernel-install: clarify what is currently supported with --root and --image
`list` and `add-all` ignore `--root` or `--image`, working on the running
system instead.
Also improve the error message if `--image` is used.
2024-01-10 12:40:35 +00:00
Antonio Alvarez Feijoo
d1b1cf8f26 kernel-install: fix memory leak 2024-01-10 09:20:15 +01:00
Zbigniew Jędrzejewski-Szmek
0b4cf0a540 Merge pull request #30232 from keszybz/ukify-imports
Use exec() to import ukify
2023-12-13 14:38:03 +01:00
Daan De Meyer
dbab005645 kernel-install: Fix inspect with --root= when no version is specified
Using the kernel version from the host is incorrect in this case, so
fix the logic so it handles no version being specified correctly with
--root=.
2023-12-11 12:06:51 +00:00
Daan De Meyer
fc7cdb2dde kernel-install: Look for uki.conf in /usr/lib/kernel as well 2023-12-11 10:29:57 +01:00
Zbigniew Jędrzejewski-Szmek
2060509d12 kernel-install/60-ukify: use exec() instead of runpy
As suggested by Daniele Nicolodi.

Also drop left-over debug line.
2023-12-01 10:30:16 +01:00
Paymon MARANDI
b99e4922ea ukify: be more explicit about where to find ukify
when KERNEL_INSTALL_UKIFY is not supplied we set ukify to $PWD/ukify

that will fail (perhaps only for manual installations):
FileNotFoundError: [Errno 2] No such file or directory: '/usr/src/linux-6.7-rc1/ukify'

this will make sure we have a sane default for UKIFY

Signed-off-by: Paymon MARANDI <paymon@utubeipod.xyz>
2023-11-25 12:53:29 +09:00
Yu Watanabe
54bc114fec kernel-install: do not resolve symlink in paths passed to plugins
When we resolve symlinks, paths (especially filenames) may be changed,
but plugins may expect to see the kernel added under the name specified,
not under the final name that the symlink chain resolves to.

This makes symlinks in specified paths that passed to plugins are not
resolved when neither --root nor --image specified.

Fixes #29317.
2023-11-21 12:57:00 +00:00
Yu Watanabe
0c710e0377 test: add test cases about plugin exit code 2023-11-20 10:17:54 +09:00
Yu Watanabe
e42931b0ac kernel-install: propagate failures in plugins
This fixes a regression introduced by
42551ea7e9.

In the shell script version, plugin failures are propagated to the
caller. But after the commit, failures in plugins are logged, but never
propagated as the exit code of the execution.

Fixes #30087.
2023-11-20 09:55:53 +09:00
Yu Watanabe
c62345ffc7 tree-wide: fix typo 2023-11-08 14:57:33 +09:00
Lennart Poettering
8353229e10 update CI 2023-11-07 16:08:06 +01:00
Lennart Poettering
758d14767d kernel-install: make "inspect" work more like "add" regarding omission of parameters
This makes "kernel-install inspect" work more "kernel-install add": if
the version or kernel image is specified as "-" or omitted we'll make it
up.
2023-11-07 16:07:57 +01:00
Lennart Poettering
ec1399f567 kernel-install: add add-all verb 2023-11-07 16:07:55 +01:00
Lennart Poettering
9d9e99a8f0 kernel-install: make version/kernel image parameters optional for "add"
Let's make kernel-install a bit easier to use:

If the kernel version is not specified, let's imply "uname -r", so that
we regnerate the entries for the current kernel.

If the kernel image is not specified let's imply using
/usr/lib/modules/$version/vmlinuz, i.e. the location distros like Fedora
drop the kernel into, which we generally recommend people to use.

If the kernel is not found there, don't try to automatically pick the
kernel path, and fail, as before.
2023-11-07 16:07:25 +01:00
Lennart Poettering
658e6cc4ae kernel-install: add command to list installed kernels
This simply dumps the dirs in /usr/lib/modules/ and whether they contain
a vmlinuz binary.
2023-11-07 16:07:05 +01:00