Commit Graph
5492 Commits
Author SHA1 Message Date
Yu Watanabe 7487115766 mountpoint-util: statx() may return EINVAL if the kernel does not support the syscall
When statx() is called with AT_STATX_DONT_SYNC, glibc's fallback code
returns EINVAL. See statx_generic() in glibc.
2023-07-22 02:20:22 +09:00
Yu Watanabe d35ff4b60e stat-util: fix error handling of statx()
When newer glibc is used, but kernel does not support statx(), then
glibc try to fallback with fstatat(). That's quite similar to our
implementation, but the supported flags are different, and if
unsupported flags are specified, it returns EINVAL.

Let's handle the case more gracefully.
2023-07-22 02:14:54 +09:00
Dmitry V. Levin f0406e118f locale-util: fix _() definition
The previous definition was not quite appropriate for the library code
because it relied on the message domain set by textdomain() invocation
which is not necessarily the same message domain defined in
GETTEXT_PACKAGE macro.

The only code that uses _() so far is located in pam_systemd_home.c.

Fixes: 20f56fddcd ("Add gettext support")
2023-07-19 14:02:04 +02:00
Joerg Behrmann c46f5680ca analyze: don't warn about version spec compliant versions
This commits adds version_is_valid_versionspec and uses it in
analyze-compare-version.c.

version_is_valid_versionspec differs from version_is_valid in that it acepts
empty strings and since valid characters in a version spec version are all
ASCII letters and digits as well as "-.~^", but ",_+" allowed by
version_is_valid are not.

Also give a more specific warning message on invalid characters.
2023-07-18 15:57:15 +01:00
Luca Boccassi 9027aff9d4 Merge pull request #27867 from keszybz/vconsole-reload-again
Restore ordering between vconsole-setup and firstboot services
2023-07-14 23:06:18 +01:00
Luca Boccassi 2c941b4e07 Merge pull request #28401 from keszybz/set-console-size
Set console size when we reset it
2023-07-14 23:02:41 +01:00
Luca Boccassi 224029fcaa Merge pull request #28097 from goenkam/maanya/dissect-tool-support-for-confext
systemd-confext: image-based systemd-wide config update including dm-verity support​
2023-07-14 23:01:26 +01:00
Frantisek Sumsal be492020ec tree-wide: a bunch of Coccinelle-suggested tweaks
rc2 edition
2023-07-14 22:49:01 +01:00
Luca Boccassi d3634ac46b Merge pull request #28301 from berrange/cvm-lockdown
Avoid using SMBIOS for kernel cmdline injection in sd-stub in confidential VMs
2023-07-14 22:47:37 +01:00
Maanya Goenka 484d26dac1 confext: add dissect tool support for confext images
Allow image wide systemd tool support for confext images by adding dissect
tool support for these images
2023-07-14 16:59:34 +00:00
Maanya Goenka 8a324d1648 sysext: change the table lookup string to be more verbose 2023-07-14 16:50:33 +00:00
Luca Boccassi a9273824d8 Merge pull request #28355 from yuwata/unit-skip-battery-check-by-kernel-command-line
unit: skip battery check when systemd.skip-battery-check specified on boot
2023-07-14 15:57:13 +01:00
Daniel P. Berrangé 129b9e3f42 fundamental: share constants for confidential virt detection
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-07-14 14:06:51 +01:00
Daan De Meyer 102f36efd1 terminal-util: Document boolean parameter in one more place 2023-07-14 09:12:54 +02:00
Daan De Meyer 29f5a5aef0 tree-wide: Set /dev/console size when we reset it
If a size is configured for /dev/console via the kernel cmdline,
let's make sure we take that into account when resetting /dev/console.
2023-07-14 09:11:29 +02:00
Yu Watanabe 0bf091a626 proc-cmdline: re-implement proc_cmdline_filter_pid1_args() without using getopt_long()
If getopt_long() is called for a list of arguments and it is freed, then
calling getopt_long() for another list will trigger use-after-free.

The function proc_cmdline_filter_pid1_args() may be called before or during
parsing program arguments (typically named as parse_argv()), hence we cannot
use getopt_long() in proc_cmdline_filter_pid1_args().

Fixes #28366.
2023-07-14 13:36:50 +09:00
Zbigniew Jędrzejewski-Szmek a0043bfa51 pid1,vconsole-setup: take a lock for the console device
When systemd-firstboot (or any other unit which uses the tty) is started,
systemd will reset the terminal. If systemd-vconsole-setup happens to be
running at that time, it'll error out when it tries to use the vconsole fd and
gets an EIO from ioctl.

e019ea738d was the first fix. It added an
implicit ordering between units using the tty and systemd-vconsole-setup.
(The commit title is wrong. The approach was generalized, but the commit title
wasn't updated.)
Then cea32691c3 was added to restart
systemd-vconsole-setup.service from systemd-firstboot.service. This was OK,
with the ordering in place, systemd-vconsole-setup.service would wait until
systemd-firstboot.service exited. But this wasn't enough, because we want the
key mappings to be loaded immediately after systemd-firstboot writes the
config. 8eb668b9ab implemented that, but actually
reintroduced the original issue. I had to drop the ordering between the two
units because otherwise we'd deadlock, waiting from firstboot for
vconsole-setup which wouldn't start while firstboot was running.
Restarting vconsole-setup.service from systemd-firstboot.service works just
fine, but when vconsole-setup.service is started earlier, it may be interrupted
by systemd-firstboot.service.

To resolve the issue, let's take a lock around the tty device. The reset is
performed after fork, so the (short) delay should not matter too much.

In xopenat_lock() the assert on <path> is dropped so that we can call
xopenat(fd, NULL) to get a copy of the original fd.

Fixes #26908.
2023-07-13 10:47:12 +02:00
Yu Watanabe c619033f09 hashmap: introduce hashmap_dump_sorted() and friends 2023-07-13 17:06:47 +09:00
Lennart Poettering d89457a145 loop-write: do strlen() implicitly if size is specified as SIZE_MAX
This reduces repetition in the function calls, since quite often we
write out strings with loop_write().

Noticed while reviewing #28077.
2023-07-13 09:59:28 +09:00
Daan De Meyer 608aa606cf Merge pull request #28365 from DaanDeMeyer/udevadm-query
Various fixes and improvements
2023-07-12 21:48:04 +02:00
Daan De Meyer 2507731374 basic: Fix color + underline functions/macros
We currently concatenate ANSI_UNDERLINE to the color of our choice
in DEFINE_ANSI_FUNC_UNDERLINE() and DEFINE_ANSI_FUNC_UNDERLINE_256().
The first thing that ANSI_UNDERLINE does is reset all previous ansi
escape sequences, so you just get underlining without any colors.

Let's fix the issue by actually concatenating _UNDERLINE to the given
color macro name so this works properly.

Also add missing color macros that this uncovered.
2023-07-12 20:05:20 +02:00
Lennart Poettering 8620854aa1 Merge pull request #28344 from YHNdnzj/compare-device-node
hibernate-resume: add & use devnode_same to compare device nodes
2023-07-12 17:59:28 +02:00
Zbigniew Jędrzejewski-Szmek 84214541fa Revert "pid1: order units using TTYVHangup= after vconsole setup"
This reverts commit e019ea738d.

In the new approach, a lock on /dev/console will be used. This lock will solve
the issue for services which run in early boot. Services which run later are
ordered after sysinit.target, so they'll run much later anyway so this
automatic dependency is not useful. Let's remove it again to make the code
simpler.
2023-07-12 15:54:33 +02:00
Yu Watanabe 627cdcc785 tree-wide: fix typos reported by Fossies Codespell report 2023-07-12 10:14:50 +09:00
Mike Yuan e3c9e09383 path-util: make path_equal_or_inode_same static inline
No functional change, just refactoring.
2023-07-11 18:01:49 +08:00
Luca Boccassi 840ac5cd1a process-util: use clone2 on ia64
glibc does not provide clone() on ia64, only clone2. But only as a
symbol in the shared library, there's no prototype in the gblic
headers, so we have to define it, copied from the manpage.
2023-07-10 11:39:35 +01:00
Luca Boccassi f692c4a6cf Print ssize_t as %zd
On some architectures (x32) ssize_t is int, not long int.

../src/basic/confidential-virt.c: In function ‘msr’:
../src/basic/confidential-virt.c:133:27: error: format ‘%ld’ expects argument of type ‘long int’, but argument 7 has type ‘ssize_t’ {aka ‘int’} [-Werror=format=]
  133 |                 log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring",
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  134 |                           rv,
      |                           ~~
      |                           |
      |                           ssize_t {aka int}
../src/basic/log.h:214:86: note: in definition of macro ‘log_full_errno_zerook’
  214 |                         ? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \
      |                                                                                      ^~~~~~~~~~~
../src/basic/log.h:242:28: note: in expansion of macro ‘log_full’
  242 | #define log_debug(...)     log_full(LOG_DEBUG,   __VA_ARGS__)
      |                            ^~~~~~~~
../src/basic/confidential-virt.c:133:17: note: in expansion of macro ‘log_debug’
  133 |                 log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring",
      |                 ^~~~~~~~~
../src/basic/confidential-virt.c:133:41: note: format string is defined here
  133 |                 log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring",
      |                                       ~~^
      |                                         |
      |                                         long int
      |                                       %d
2023-07-10 10:57:16 +01:00
Luca Boccassi f00022eb86 Merge pull request #28242 from berrange/cond-sec-cvm
Detect and expose the confidential virtualization technology in various places
2023-07-06 19:14:26 +01:00
Daniel P. Berrangé a577a61625 add APIs for detecting confidential virtualization
This code uses various CPUID checks to be able to identify

 * AMD SEV
 * AMD SEV-ES
 * AMD SEV-SNP
 * Intel TDX

On HyperV/Azure, it has special checks for detecting SEV-SNP
since the normal CPUID is blocked.

Related: https://github.com/systemd/systemd/issues/27604
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-07-06 12:20:04 +01:00
Dan Streetman 3f27ba9954 basic/alloc-util: add greedy_realloc_append()
Add function to perform greedy realloc as well as copying the new data into the
newly allocated space.
2023-07-05 17:33:55 -04:00
Lennart Poettering 6c1d10fe03 update syscall tables for upcoming v254 2023-07-05 23:18:16 +02:00
Lennart Poettering 09d04ad325 core: introduce a new job mode JOB_RESTART_DEPENDENCIES
This new job mode will enqueue a start job for a unit, and all units
depending on the unit will get a restart job enqueued. This is then used
for automatic sevice restarts: the unit itself is only started, the
depending units restarted. This way the unit will not go down
unnecessarily, triggering OnSuccess= needlessly.

This also introduces a new state SERVICE_AUTO_RESTART_QUEUED that is
entered once the restart jobs are enqueued. Previously we'd stay in
SERVICE_AUTO_RESTART, but that's problematic, since we'd lose
information whether we still need to enqueue the restart job during a
serialization/deserialization cycle or not. By having an explicit state
for this we know exactly whether we still need to enqueue the job or
not. It's also good since when we are in SERVICE_AUTO_RESTART_QUEUED we
want to act on unit_start(), but on SERVICE_AUTO_RESTART we want to wait
for the holdoff time to pass before we act on unit_start().

Fixes: #27722
2023-07-03 17:31:25 +02:00
Yu Watanabe 86c2a76e09 Merge pull request #28132 from rpigott/dhcp-captive-portal
Implement RFC8910: captive portal dhcp options
2023-07-03 14:51:56 +09:00
Luca Boccassi b9d29a2028 Merge pull request #28226 from mrc0mmand/coverity-fixes
A couple of Coverity-related fixes
2023-07-02 15:54:56 +01:00
Frantisek Sumsal 5000cea8d2 tree-wide: explicitly ignore return value in a couple more places
Resolves:
  - CID#1490777
  - CID#1498366
  - CID#1508639
  - CID#1509084
  - CID#1509086
  - CID#1509087
2023-07-02 12:22:45 +02:00
Frantisek Sumsal 9cf7f7a82f virt: drop an unused assignment
As `v` gets overwritten by the following detect_vm_cpuid() call.

Resolves: CID#1509247
2023-07-02 12:22:41 +02:00
Zbigniew Jędrzejewski-Szmek da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Ronan Pigott 7040fd381a dhcp-client: parse RFC8910 captive portal dhcp option 2023-06-29 16:42:16 -07:00
Yu Watanabe be994c2640 battery-check: several follow-ups
Follow-ups for e3d4148d50.

- add reference to initrd-battery-check.service in man page, and move
  its section from 1 to 8,
- add link to man page in help message,
- introduce ERRNO_IS_NO_PLYMOUTH(),
- propagate error in battery_check_send_plymouth_message(),
- rename battery_check_send_plymouth_message() -> plymouth_send_message(),
- return earlier when the first battery level check passed to reduce
  indentation,
- fix potential use of invalid fd on battery restored,
- do not use emoji for /dev/console,
- add simple test (mostly for coverity),

etc, etc...
2023-06-29 15:41:00 +09:00
Luca Boccassi f18886fe17 Merge pull request #28164 from poettering/replace-env-var-fixes
pid1: warn about unset+invalid env var names when resolving ExecStart= expressions and similar
2023-06-28 19:40:51 +01:00
Lennart Poettering 4d8eca03e5 Merge pull request #28146 from keszybz/ansi-seq-skip
Pass ANSI sequences through when ellipsizing output
2023-06-28 19:18:27 +02:00
OMOJOLA JOSHUA e3d4148d50 PID1: detect battery level in initrd and if low refuse continuing to boot, print message and shut down. 2023-06-28 14:48:54 +01:00
Zbigniew Jędrzejewski-SzmekandJan Janssen cb558ab222 string-util: pass ANSI sequences through unchanged
Cutting off in the middle may leave the terminal in a bad state, breaking
further output. But we don't know what a given ANSI sequence does, e.g.
ANSI_NORMAL should not be skipped. But it is also nice to keep various
sequences intact, so that if we had part of the string in blue, and we cut out
the beginning of the blue part, we still want to keep the remainder in color.
So let's just pass them through, stripping out the characters that take up
actual space.

Also, use memcpy_safe as we may end up copying zero bytes when ellipsizing at
the start/end of a string.

Fixes: #24502

This also fixes an ugliness where we would ellipsize string with ANSI
sequences too much, leading to output that was narrower on screen than the
requested length:

  Starting AAAAAAAAAAAAAAAAAAAAA.service
  Starting BBBBBBBBBBBBBBBBBBBBB.service
  Starting LONG…ER.service

Co-authored-by: Jan Janssen <medhefgo@web.de>
2023-06-27 16:55:02 -06:00
Lennart Poettering f331434d13 env-file: when resolving env vars in command lines, collect list of unset/invalid ones
When resolving environment variables we currently silently resolve unset
and invalid environment variables to empty strings. Let's do this
slightly less silently: log about unset and invalid env vars, but still
resolve them to an empty string.

Fixes: #27036
2023-06-27 13:49:46 +02:00
Lennart Poettering 7658139c01 env-util: make strv_env_get() a static inline wrapper around strv_env_get_n()
Let's make length = SIZE_MAX also mean "call strlen()".
2023-06-27 13:49:46 +02:00
Lennart Poettering d5ce24c99e env-util: introduce proper flags type ReplaceEnvFlags for replace_env() 2023-06-27 13:49:46 +02:00
Lennart Poettering 10930fbb1c env-util: add explicit size check before strndupa() in strv_env_get_n()
Let's better be safe than sorry.
2023-06-27 13:49:46 +02:00
Lennart Poettering 2b07147e9c env-util: modernize env_name_is_valid_n() a bit
If the size is specified as SIZE_MAX, then imply strlen().
2023-06-27 13:49:46 +02:00
Lennart Poettering 6b9f600772 string-util: add strextendn() helper 2023-06-27 13:49:46 +02:00
Zbigniew Jędrzejewski-Szmek 9579e9a530 basic/utf8: make utf8_encoded_to_unichar() return length of the codepoint 2023-06-23 17:24:42 -06:00