1
0
mirror of https://github.com/systemd/systemd synced 2024-07-09 04:26:06 +00:00
Commit Graph

84 Commits

Author SHA1 Message Date
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
Mike Yuan
52e555fa27 hibernate-resume-config: apply ENABLE_EFI ifdef correctly
Currently, validate_efi_hibernate_location is
fully conditioned out if !ENABLE_EFI, but
get_efi_hibernate_location() still calls it.
2024-04-09 09:40:21 +02:00
Mike Yuan
8f8e481f03
hibernate-resume: introduce --clear for clearing hibernate storage var 2024-04-03 22:07:17 +08:00
Mike Yuan
89c727e0f4
hibernate-resume: add options handling 2024-04-03 21:59:59 +08:00
Mike Yuan
9fa0f584ec
hibernate-resume-config: expose get_efi_hibernate_location 2024-04-03 21:59:59 +08:00
Mike Yuan
667b0c48f2
hibernate-resume: EINVAL -> ENOTBLK where appropriate 2024-04-03 21:59:59 +08:00
Mike Yuan
fbc88824b6
hibernate-util: make clear_efi_hibernate_location_and_warn return 1 if
actually cleared the variable
2024-04-03 21:59:59 +08:00
Lennart Poettering
f0e4244b2f tree-wide: use JSON_ALLOW_EXTENSIONS when disptching at various places
If we want to allow method replies to be extended without this breaking
compat, then we should set this flag. Do so at various method call
replies hence.

Also do it when parsing user/group records, which are expressly
documented to be extensible, as well as the hibernate JSON record.
2024-01-05 12:43:06 +01:00
Mike Yuan
0e3638380d various: unexport a few internal structs
We don't expose destructors for these internal structs already.
Let's make the struct itself implementation detail too.
2024-01-03 08:40:33 +09:00
Mike Yuan
6cfce71b50 hibernate-resume: don't wait forever if hibernate info is from EFI 2023-12-12 12:36:58 +00:00
Mike Yuan
8ad973ed99 hibernate-util: de-duplicate clear_efi_hibernate_location 2023-12-10 14:08:46 +09:00
Mike Yuan
24ab77c3cd
hibernate-resume: always clear HibernateLocation if system info matches
Follow-up for a628d933cc

HibernateInfo.from_efi is not actually useful. info.efi is only
set if the system identifier stored in EFI variable matches with
that of the running system, and thus the variable should be cleared
no matter whether resume= is set from kernel cmdline or not.
2023-12-05 16:52:19 +08:00
Mike Yuan
b7c1f9eaf4 hibernate-resume: actually set HibernateInfo.offset
Follow-up for a628d933cc
2023-11-23 18:15:37 +00:00
Lennart Poettering
9942f855a9 tree-wide: take in all *our* JSON structures also decimal strings
Let's be friendly in what we accept: whenever we define a JSON
structure, let's also allow decimal strings where we want an integer.

This patch purely replaces JSON_VARIANT_UNSIGNED by
_JSON_VARIANT_TYPE_INVALID in the various JsonDispatch[] tables, so that
we'll happily accept any type in json_dispatch(), so that
json_dispatch_uint64() and related tools can do their thing.

This does not switch over OCI (as a JSON structure not defined by us).
2023-11-07 14:25:40 +01:00
Lennart Poettering
f1b622a00c varlink,json: introduce new varlink_dispatch() helper
varlink_dispatch() is a simple wrapper around json_dispatch() that
returns clean, standards-compliant InvalidParameter error back to
clients, if the specified JSON cannot be parsed properly.

For this json_dispatch() is extended to return the offending field's
name. Because it already has quite a few parameters, I then renamed
json_dispatch() to json_dispatch_full() and made json_dispatch() a
wrapper around it that passes the new argument as NULL. While doing so I
figured we should also get rid of the bad= argument in the short
wrapper, since it's only used in the OCI code.

To simplify the OCI code this adds a second wrapper oci_dispatch()
around json_dispatch_full(), that fills in bad= the way we want.

Net result: instead of one json_dispatch() call there are now:

1. json_dispatch_full() for the fully feature mother of all dispathers.
2. json_dispatch() for the simpler version that you want to use most of
   the time.
3. varlink_dispatch() that generates nice Varlink errors
4. oci_dispatch() that does the OCI specific error handling

And that's all there is.
2023-11-02 01:19:21 +00:00
Mike Yuan
a3f7047f00
hibernate-resume: add missing static for arg_info 2023-10-23 23:12:27 +08:00
Zbigniew Jędrzejewski-Szmek
fed0a899b2 hibernate-resume: remove kernel/image version comparison when resuming
We already had a similar check that was removed, see
8340b762e4 (*). The kernel supports loading of a
resume image from a different kernel version. This makes sense, because the
goal of "resume" is to replace the running system by a saved memory image, so
it doesn't really matter that the short-lived kernel is different.

By removing the check, we make the process more reliable: for example, the user
may select a different kernel from a list, or not have the previously running
kernel in /boot at all, etc. Requiring the exact same kernel version makes the
process more fragile for no benefit.

Similar reasoning holds for the image version: the image may be updated, and
for example an older kernel+initrd might be used, with an embedded VERSION_ID
that is not the latest. This is fine, and the check is not useful.

I left the check for ID/IMAGE_ID: we probably don't want to use the resume
image if the hibernation was done from a different installation.

(Note: why not check VERSION_ID/IMAGE_VERSION? Because of the following
scenario: a user has an installation of Fedora 35, and they upgrade to Fedora
36, which means that the os-release file on disk gets replaced and now
specifies VERSION_ID=36. But the running kernel is not replaced, and its
package is not removed because the running kernel version is never removed, so
we still have a boot entry that in initrd-release says VERSION_ID=35. Without
rebooting, the user does hibernation. When resuming, we want to resume, no
matter if one of the new entries with VERSION_ID=36 or one of the old entries
with VERSION_ID=35 is picked in the boot loader menu.

If the installation is image-based, i.e. it has IMAGE_ID+IMAGE_VERSION, the
situation is similar: after an upgrade, we may still have an boot entry from
before the upgrade. Using an older kernel+initrd to boot and switch-root into a
newer installation is supported and is rather common.

In fact, it is a rather common situation that the version reported by the boot
entry (or stored internally in the initrd-release in the initrd) does not match
the actual system on disk. Generally, this metadata is saved when the boot menu
entry is written and does not reflect subsequent upgrades. Various
distributions generally keep at least 3 kernels after a upgrade, and during an
upgrade only install one new, which means that after a major upgrade, generally
there will be at least two kernels which have mismatched version information.)

OTOH, I think it is useful to *write* all the details to the EFI var. As
discussed in https://github.com/systemd/systemd/issues/29037, we may want to
show this information in the boot loader. It is also useful for debugging.

(*) Also again discussed and verified in
https://github.com/systemd/systemd/pull/27330#discussion_r1234332080.

", ignored" is dropped, since this failure is likely to cause the following
check to fail. Better not to say anything then to say the misleading thing.
2023-10-12 12:30:12 +02:00
Mike Yuan
54d7fcc6a3
sleep-util: split into sleep-config and hibernate-util 2023-09-27 21:48:39 +08:00
Mike Yuan
17ad085993
hibernate-resume: add missing #pragma once 2023-09-22 21:03:48 +08:00
Mike Yuan
3494a8b904
hibernate-resume: break lines in meson.build files() 2023-09-22 21:02:55 +08:00
Mike Yuan
a628d933cc
hibernate-resume: split out the logic of finding hibernate location
Before this commit, the hibernate location logic only exists in
the generator. Also, we compare device nodes (devnode_same()) and
clear EFI variable HibernateLocation in the generator too. This is
not ideal though: when the generator gets to run, udev hasn't yet
started, so effectively devnode_same() always fails. Moreover, if
the boot process is interrupted by e.g. battery-check, the hibernate
information is lost.

Therefore, let's split out the logic of finding hibernate location.
The generator only does the initial validation of system info and
enables systemd-hibernate-resume.service, and when the service
actually runs we validate everything again, which includes comparing
the device nodes and clearing the EFI variable. This should make
things more robust, plus systems that don't utilize a systemd-enabled
initrd can use the exact same logic to resume using the EFI variable.
I.e., systemd-hibernate-resume can be used standalone.
2023-09-07 20:21:16 +08:00
Yu Watanabe
a8d3315ba4 tree-wise: drop unnecessary use of proc_cmdline_key_streq()
If the key does not contain '-' or '_', then it is not necessary to use
proc_cmdline_key_streq(), and streq() is sufficient.

This also adds missing assertions about 'key' argument.
2023-08-09 03:16:31 +09:00
Mike Yuan
caf8d692ed
hibernate-resume-generator: escape device path passed to hibernate-resume
Follow-up for #27330

Fixes #28668
2023-08-04 21:04:45 +08:00
Yu Watanabe
7409342236 meson: move declarations of hibernate-resume 2023-08-01 02:31:36 +09:00
Luca Boccassi
b0d3095fd6 Drop split-usr and unmerged-usr support
As previously announced, execute order 66:

https://lists.freedesktop.org/archives/systemd-devel/2022-September/048352.html

The meson options split-usr, rootlibdir and rootprefix become no-ops
that print a warning if they are set to anything other than the
default values. We can remove them in a future release.
2023-07-28 19:34:03 +01:00
Mike Yuan
0281927686
hibernate-resume: use devnode_same to compare device nodes
Addresses https://github.com/systemd/systemd/pull/28321#discussion_r1257866179

When devnode_same() fails we only debug log about it, because
the device nodes might not have appeared by the time the generator
is run.

Fixes #28340
2023-07-11 18:04:22 +08:00
Mike Yuan
4427194292
hibernate-resume: compare device nodes using path_equal_or_inode_same
Follow-up for 9deeca1275
2023-07-10 00:54:13 +08:00
Mike Yuan
ee1369d789
hibernate-resume: add missing newline to the generated unit 2023-07-10 00:35:31 +08:00
Mike Yuan
c089af84c4 hibernate-resume: refuse resume if resume_offset= is set but not resume= 2023-07-09 12:13:16 +01:00
Lennart Poettering
0b20c56ee1 hibernate-resume-generator: downgrade 'noresume' log message
This log message is shown pretty regular at boot in various scenarios
(such as CI builds), and it's not a reason for any concern, it's just the
immediate effect of explicit configuration. Hence let's downgrade from
LOG_NOTICE to LOG_INFO so that it is still usually in the boot output,
but not particularly highlighted, since there's really no reason to.
2023-07-04 12:30:33 +01:00
Mike Yuan
9deeca1275
hibernate-resume: support resuming through efivar HibernateLocation 2023-06-24 00:04:32 +08:00
Mike Yuan
760e99bb52
hibernate-resume: rework to follow the logic of sleep.c and use
main-func.h

Preparation for #27247
2023-06-23 23:57:49 +08:00
Lennart Poettering
a9b837aa34 generators: change TimeoutSec=0 to TimeoutSec=infinity
With these settings we intend to turn off timeouts for possibly
interactive/slow commands. The officially documented way to turn off the
time-outs is to setting them to infinity. So far we set them to zero
here though.

This lead to some confusiong, for example #18224. Let's fix this by
uniformly spelling out TimeoutSec=infinity.

This doesn't change behaviour. It just makes our generated files match
what we document, without relying on historic compat support.

Fixes: #18224
2023-06-06 12:38:16 +01:00
Zbigniew Jędrzejewski-Szmek
baa6a42d27 basic: create new basic/initrd-util.[ch] for initrd-related functions
I changed imports of util.h to initrd-util.h, or added an import of
initrd-util.h, to keep compilation working. It turns out that many files didn't
import util.h directly.

When viewing the patch, don't be confused by git rename detection logic:
a new .c file is added and two functions moved into it.
2022-11-08 13:41:13 +01:00
Lennart Poettering
32e2767080 tree-wide: use the term "initrd" at most places we so far used "initramfs"
In most cases we refernced the concept as "initrd". Let's convert most
remaining uses of "initramfs" to "initrd" too, to stay internally
consistent.

This leaves "initramfs" only where it's relevant to explain historical
concepts or where "initramfs" is part of the API (i.e. in
/run/initramfs).

Follow-up for: b66a6e1a58
2022-09-23 15:10:53 +02:00
Zbigniew Jędrzejewski-Szmek
b8110a3eb8 hibernate-resume-generator: use DEFINE_MAIN_GENERATOR_FUNCTION()
DEFINE_MAIN_GENERATOR_FUNCTION() always sets dest*, so there should be no
change in behaviour.
2022-07-15 13:09:38 +02:00
Lennart Poettering
ec61371fe6 devnum-util: define helper macros for formatting devnum major/minor pairs
And port some parts over.
2022-04-13 16:26:31 +02:00
Lennart Poettering
35cd0ba516 shared: clean up mkdir.h/label.h situation
Previously the mkdir_label() family of calls was implemented in
src/shared/mkdir-label.c but its functions partly declared ins
src/shared/label.h and partly in src/basic/mkdir.h (!!). That's weird
(and wrong).

Let's clean this up, and add a proper mkdir-label.h matching the .c
file.
2021-11-16 17:03:28 +01:00
Zbigniew Jędrzejewski-Szmek
835cf75aef meson: use jinja2 for rpm templates
The naming of variables is very inconsistent. I tried to use more
modern style naming (UNDERSCORED_TITLE_CASE), but I didn't change existing
names too much. Only SYSTEM_DATA_UNIT_PATH is renamed to SYSTEM_DATA_UNIT_DIR
to match SYSTEM_CONFIG_UNIT_DIR.
2021-05-19 10:25:26 +09:00
Yu Watanabe
d2acb93dc5 tree-wide: enable colorized logging for daemons when run in console
It may be useful when debugging daemons.
2021-02-01 01:13:44 +09:00
Lennart Poettering
c2bc710b24 string-util: imply NULL termination of strextend() argument list
The trailing NULL in the argument list is now implied (similar to
what we already have in place in strjoin()).
2021-01-06 17:24:46 +01:00
Yu Watanabe
db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
nabijaczleweli
90198bcbea Fix generator name in hibernate-resume-generator's drop-in
Introduced in ff757c9d29
2020-02-04 14:49:04 +09:00
Zbigniew Jędrzejewski-Szmek
ff757c9d29 hibernate-resume-generator: wait "infinitely" for the resume device
This makes changes similar to the parent commit, but for hibernate-resume-generator.
If resume= is specified on the kernel command line, we'll set JobRunningTimeoutSec=0
for the device. This matches what we do for the root device.

In practice, other timeouts will take effect. For example dracut tries (and
fails :[ ) to start dracut-emergency.service after some time.

Fixes #7242, https://bugzilla.redhat.com/show_bug.cgi?id=1705522.
2019-12-03 17:20:19 +01:00
Jonathan Rouleau
8b6805a25b hibernate-resume: add resumeflags= kernel option
Adds the resumeflags= kernel command line option to allow setting a
custom device timeout for the resume device (defaults to the same as the
root device).
2019-06-05 18:59:05 -06:00
Jonathan Rouleau
70e843fe92 hibernate-resume: fix resume device timeout
Fixes #7242

Sets the systemd device timeout for the resume device to the same as
the root device. This prevents systemd-hibernate-resume@.service from
silently timing out and booting into a fresh session instead of the
saved hibernation state when the user is using luks, has set
rootflags=x-systemd.device-timeout=X to longer than the default timeout,
and the luks password is entered after the default timeout.
2019-06-05 18:31:14 -06:00
Zbigniew Jędrzejewski-Szmek
ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Zbigniew Jędrzejewski-Szmek
baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek
053254e3cb generators: drop umask calls
systemd already sets the umask (see e3b8d0637d). When
running under systemd, we don't need to set it. And when *not* running under
systemd, for example during development, there is no reason to override the user
config. Let's just drop those calls.

$ git grep -e 'umask\(' -l 'src/*generator*' |xargs perl -i -0pe 's|^[^\n]*umask\([^\n]+\n\n||gms'
2018-11-21 13:40:24 +01:00
Yu Watanabe
77182cc65e hibernate-resume-generator: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00