Commit Graph

53581 Commits

Author SHA1 Message Date
Mike Yuan
911de19c72 hibernate-resume-config: log louder on invalid kernel version/os-release id
Prompted by 45623d4ad6

We do make use of the os-release ids to determine whether to initial resume
if they're present, hence log at warning level if invalid. While at it,
raise the level for the kernel version too, which is generally interesting
to the user if something goes wrong.
2025-03-05 17:18:21 +01:00
Mike Yuan
97be702ffc factory-reset-tool: error out if we can't cancel pending reset
First of all, it seems very unlikely that we'd be in the pending state
if not booted via EFI in the first place. Moreover, the operation didn't
work out, hence let's not spurious report success.
2025-03-05 17:17:21 +01:00
Mike Yuan
f1d790a18b tpm2-clear: make it clear that we default to true for systemd.tpm2_allow_clear 2025-03-05 17:04:00 +01:00
Mike Yuan
5c7b3335db tpm2-clear: make getenv() failure fatal, correct one log level
This operation is destructive, and we bail if the proc_cmdline_get_bool()
call below fails already. Better be safe than sorry.
2025-03-05 17:03:59 +01:00
Mike Yuan
ab4c84b0e9 tpm2-clear: use plain DEFINE_MAIN_FUNCTION
We don't return any positive exit status.
2025-03-05 17:03:59 +01:00
Thorsten Kukuk
54cd851bd9 sysupdate: fix features and vaccum if all features are disabled
If all transfer definitions are features and disabled, a wrong error
is reported that there are no transfer definitions.
This breaks the features and vaccum verb, as they work on disabled
features, too.
2025-03-06 00:53:27 +09:00
Lennart Poettering
c22948f6c2 factory-reset: rework infrastructure, make it work with gpt-auto, and add support for resetting TPM as part of factory reset (#36512) 2025-03-05 15:25:36 +01:00
Yu Watanabe
b690298d7a sd-varlink: fix typo
Follow-up for 837849561b.
2025-03-05 23:17:36 +09:00
Luca Boccassi
383df6ff06 test-async: Wait for asynchronous_sync() to finish (#36611)
Otherwise, if the system is busy, TEST-02-UNITTESTS will fail as
systemd will time out trying to kill the transient unit that we're
running test-async in.
2025-03-05 12:36:45 +00:00
Lennart Poettering
b7ba8d55b8 run0: run agents during setup, until pty forwarder takes over
When services start up they might query for passwords, or issue polkit
requests. Hence it makese sense to run the password query agent and
polkit agent from systemd-run. We already ran the polkit agent, this
also ensures we run the password query agent.

There's one tweak to the story though: running the agents and the pty
forwarder concurrently is messy, since they both try to read from stdin
(one potentially, the other definitely). Hence, let's time the agents
properly: invoke them when we initialize, but stop them once the start
job for the unit we are supposed to run is complete, and only then run
the pty forwarder.

With this in place, the following series of commands starts to work
really nicely (which previously deadlocked):

    # homectl create foobar
    # run0 -u foobar

What happens in the background in run0 is this: a new session is invoked
for "foobar", which pulls in the user@.service instance for the user.
That user@.service instance will need to unlock the homedir first. Since
8af1b296cb this will happen via the askpw
logic. With this commit here this prompt will now be shown by run0. Once
the password is entered the directory is unlocked and the real session
begins. Nice!

This new behaviour is conditioned behind --pty-late (distinct from the
existing --pty switches). For systemd-run we will never enable this mode
by default, for compat with command lines that use ExecStartPre=
(because we won't process the pty anymore during that command) For
run0 however this changes the default to --pty-late (unless
--no-ask-password is specified). This reflects the fact that run0 is
more of an interctive tool and unlikely to be used in more complex
service start-up situations with ExecStartPre= and suchlike.

This also merges JobDoneContext into RunContext, since it doesn't really
make sense to have two contexts around to communicate between outer
stack frame and event handlers. Let's just have one, and pass it around
to all handlers the same way. In particular as we should delay exit only
until both the unit's job is complete *and* in case of --wait the unit
is exited, one of the two should not suffice.
2025-03-05 13:17:50 +01:00
Lennart Poettering
14ab9aafc2 gpt-auto: add common parse_gpt_auto_root() parser 2025-03-05 12:38:33 +01:00
Lennart Poettering
1c0b8270f4 gpt-auto-generator: if root=gpt-auto-force is specified ignore factory reset state 2025-03-05 12:38:28 +01:00
Lennart Poettering
9f0c830b5f udev: add builtin that reports current factory reset state 2025-03-05 12:38:13 +01:00
Lennart Poettering
73e53d2ee4 tpm2-clear: optionally reset TPM during a factory reset 2025-03-05 12:37:51 +01:00
Lennart Poettering
41d9ed93d9 factory-reset: revamp infrastructure
This introduces a bunch of facilities:

1. The factory-reset.target unit that requests a factory reset is now
   complemented by factory-reset-now.target that executes it at next
   boot.

2. This latter is added to the initial transaction via the new trivial
   systemd-factory-reset-generator.

3. A tool systemd-factory-reset has been added to query, request,
   cancel, complete factory reset operations (via EFI variables). Two of
   these are wrapped into units that are plugged into
   factory-reset.target and factory-reset-now.target respectively. The
   tool also provides a simple Varlink API.

This should make things a lot cleaner, and both be useful as explicit
implementation on UEFI, and as template + hookpoints for alternative
implementations on non-UEFI.
2025-03-05 12:37:26 +01:00
Lennart Poettering
9e050b0458 repart: port to new factory reset state apis 2025-03-05 12:37:24 +01:00
Lennart Poettering
45623d4ad6 shared: add generic factory reset state apis
Let's provide a generic implementation of the systemd.factory_reset
kernel cmdline checking repart implements. Moreover add support for
leaving the factory reset state again.

This only establishes the basic APIs, it does not hook them up with
anything.
2025-03-05 12:37:03 +01:00
Luca Boccassi
7eb1cd2f0c Ukify tweaks (#36389) 2025-03-05 11:26:47 +00:00
Aaron Rogers
08633ea902 cryptsetup: align tpm2-blob 2025-03-05 11:41:30 +01:00
Zbigniew Jędrzejewski-Szmek
6446c7d99b ukify: avoid treating invalid option as an argument
For some reason, argparse treats undefined options as positional args in
certain scenarios:

$ src/ukify/ukify.py --badopt='11'
ukify.py: error: unrecognized arguments: --badopt=11
$ src/ukify/ukify.py --badopt '11'
ukify.py: error: unrecognized arguments: --badopt
$ src/ukify/ukify.py --badopt '11 12'
Assuming obsolete command line syntax with no verb. Please use 'build'.
Traceback (most recent call last):
  File "/home/zbyszek/src/systemd/src/ukify/ukify.py", line 2497, in <module>
    main()
    ~~~~^^
  File "/home/zbyszek/src/systemd/src/ukify/ukify.py", line 2485, in main
    check_inputs(opts)
    ~~~~~~~~~~~~^^^^^^
  File "/home/zbyszek/src/systemd/src/ukify/ukify.py", line 671, in check_inputs
    value.open().close()
    ~~~~~~~~~~^^
  File "/usr/lib64/python3.13/pathlib/_local.py", line 537, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '--badopt=11 12'

I suspect that this is some crap compat for Windows, where option parsing is
an even bigger mess than here.

Being told about positional args, when no positional args were specified is
confusing, so add a check for this.
2025-03-05 11:17:33 +01:00
Daan De Meyer
35c59ac249 test-async: Wait for asynchronous_sync() to finish
Otherwise, if the system is busy, TEST-02-UNITTESTS will fail as
systemd will time out trying to kill the transient unit that we're
running test-async in.
2025-03-05 10:50:40 +01:00
Daan De Meyer
3041e377a8 async: Port to PidRef 2025-03-05 10:50:36 +01:00
Yu Watanabe
6ee112ed47 glibc bump followup (#36609) 2025-03-05 18:16:44 +09:00
Mike Yuan
33db9f214b missing_syscall: drop raw_getpid()
This used to be relevant since in old versions of glibc an internal
cache is maintained, while we might sidestep their invalidation
with raw_clone(). After glibc 2.25 getpid() is a trivial wrapper
for the syscall, and hence there's no need to have a separate
raw_getpid().
2025-03-04 23:03:24 +01:00
Mike Yuan
c133fcd5c0 locale-util: modernize is_locale_utf8() a bit 2025-03-04 23:03:23 +01:00
Mike Yuan
f2f9b82724 sd-journal/journal-send: use is_main_thread() where appropriate 2025-03-04 23:02:40 +01:00
Mike Yuan
87838420aa basic/sys/mount: sort includes 2025-03-04 23:02:39 +01:00
Mike Yuan
c74380cceb missing_fs: drop FS_KEY_DESCRIPTOR_SIZE
We now directly import linux/fscrypt.h, so this def is duplicate
2025-03-04 23:02:37 +01:00
Lennart Poettering
f0f5d54202 nspawn: add ability to poweroff container cleanly with ^]^]p
It's sometimes very useful to be able to terminate a container quickly
but cleanly while talking to it. Introduce a hotkey for that: ^]^]p for
powering it off. In similar style add ^]^]r for rebooting it.
2025-03-04 23:02:31 +01:00
Lennart Poettering
b1f9d0e46b ptyfwd: add support for additional out-of-band hotkeys in ptyfwd
Let's add the ability that ptyfwd tools can register additional hotkeys
that they then can handle.

So far the only hotkey we support is ^]^]^] to exit the ptyfwd session
abruptly. Staying close to this let's add ^]^]<char> for additional
commands.
2025-03-04 23:02:31 +01:00
Lennart Poettering
decae96905 ptyfwd: rename handler to hangup_handler
We'll add another type of handler callback in the next commit, hence
rename the existing handler to be more precise what it is about:
handling hangups (either inline via tty, or explicit via user request)
2025-03-04 22:58:49 +01:00
Yu Watanabe
c4eef17990 dirent-util: add several assertions in posix_getdents()
Follow-up for e86a492ff0.
2025-03-04 22:54:01 +01:00
Michal Koutný
cf62e00295 path: Close inotify FD asynchronously
inotify FD may take several milliseconds to close.  We measured
daemon-reload

        default: (0.427 ± 0.05) s
        async:   (0.323 ± 0.02) s

with 5 path units out of 422 units. I.e. ~1% of units cause ~25% of
delay, hence this fix seems like low-hanging fruit on the daemon-reload
critical path.

Particular inotify slowness pointed out by @fbuihuu.
2025-03-04 21:37:58 +01:00
Lennart Poettering
52d5043b5e pam-systemd: default to "lightweight" sessions if area is selected
We currently don't support invoking a per-area service manager instance,
hence don't try to pull in one if we log into an area.

Once we add support for per-area service managers we can relax this
again.
2025-03-04 18:09:37 +01:00
Lennart Poettering
837849561b varlink: optionally create leading dirs when binding AF_UNIX socket
This is such a common case, let's make it easy to do this.
2025-03-04 18:07:17 +01:00
Lennart Poettering
4f4c37bc07 log: explicitly size log_target_max_level()
We always validate that the target value is below _LOG_TARGET_SINGLE_MAX
before acessing it, but we don't actually size the array like that.
let's fix that.

This doesn#t effectively change anything, but it makes things more
explicit what the limit here is.
2025-03-04 18:07:00 +01:00
Lennart Poettering
facc9439a7 dns-stream: only read DNS packet data if we identified the peer properly
If we use TCP fastopen to connect to a DNS server via TCP, and it
responds really quickly between our connection attempt and our immediate
check back, then we have not identified the peer yet, and will not be
able to use the peer metadata to fill in our packet info.

Let's fix that, and simply not read from the socket until identification
is complete.

Fixes: #34956
2025-03-04 12:33:53 +00:00
Lennart Poettering
8113361e82 resolved: pick up new DNSSEC KSC from 2024
Import thew new key from https://data.iana.org/root-anchors/root-anchors.xml.

The old one remains valid, as per provided data.

Fixes: #36260
2025-03-04 11:51:34 +00:00
Zbigniew Jędrzejewski-Szmek
bd208a5421 ukify: drop dots from exception messages
In Python, exception messages are often embedded in surrounding text, so in
general they should not contain punctuation.

Also, no need to instantiate the exception object if no arguments are used.
2025-03-04 10:07:38 +01:00
Daan De Meyer
5abf819a5f basic: remove unnecessary definition in missing_xyz.h (#36565) 2025-03-04 08:41:14 +01:00
Yu Watanabe
f342c2420a chattr-util: two trivial cleanups (#36593) 2025-03-04 13:13:25 +09:00
Lennart Poettering
e5e8cd3eba tree-wide: several cleanups and fixlets prompted by Coverity (#36431) 2025-03-03 23:17:28 +01:00
Lennart Poettering
591e1492b7 Coverity fixups (#36503)
Details in individual commits.
2025-03-03 22:54:42 +01:00
Yu Watanabe
059d23c966 exec-invoke: add missing assertions and drop unnecessary conditions
Fixes CID#1534358.
2025-03-04 05:18:15 +09:00
Yu Watanabe
34b58da114 exec-invoke: modernize get_supplementary_groups()
- drop unused argument 'group',
- rename output arguments,
- add missing assertions for output arguments,
- always initialize output arguments on success.
2025-03-04 05:18:15 +09:00
Yu Watanabe
00575cfd69 hwdb-util: drop unused value assignment
The values assigned to 'r' were never used, and overwritten by the next
call of read_line_full().

Fixes CID#1548043 and CID#1548064.
2025-03-04 05:18:15 +09:00
Yu Watanabe
6529ab0b06 pe-binary: fix array overrun
This is a kind of paranoia, as memeqzero() does not read anyting if
length is zero. But, strictly speaking C language does not allow such,
and Coverity warn about that.

Fixes CID#1561177.
2025-03-04 05:18:15 +09:00
Yu Watanabe
2bf5d698d6 pe-binary: trivial coding style fixlets 2025-03-04 05:18:15 +09:00
Yu Watanabe
3428c4b818 generator: insert parentheses to make the code clearer
Silence CID#1563781.
2025-03-04 05:18:15 +09:00
Yu Watanabe
42f6a96e6c fileio: move call of label_ops_post() before error handling of creating files
Fixes CID#1563946.
2025-03-04 05:18:15 +09:00