Commit Graph
7205 Commits
Author SHA1 Message Date
Luca Boccassi 27cead47be Merge pull request #27633 from DaanDeMeyer/repart-dropin
repart: Make sure we look up dropin files in the root directory
2023-05-12 21:29:38 +01:00
Daan De Meyer 947f59ba2b conf-parser: Add root argument to config_parse_many() 2023-05-12 17:52:32 +02:00
Frantisek Sumsal e8dba80626 core: fix memory leak during deserialization
when activation-details-unit-name is encountered multiple times.

Resolves: #27623
2023-05-13 00:42:25 +09:00
Daan De Meyer 153d5dfd87 core: Try to initialize TERM from systemd.tty.term.console as well
We already have the systemd.tty.xxx kernel cmdline arguments for
configuring tty's for services, let's make sure the term cmdline
argument applies to pid1 as well.
2023-05-12 08:38:20 +02:00
Daan De Meyer aaa27e2e21 core: Check if any init exists before switching root
If we switch root and can't execute an init program afterwards, we're
completely stuck as we can't go back to the initramfs to start
emergency.service as it will have been completely removed by the switch
root operation.

To prevent leaving users with a completely undebuggable system, let's
at least check before we switch root whether at least one of the init
programs we might want to execute actually exist, and fail early if
none of them exists.
2023-05-12 07:48:50 +02:00
Daan De Meyer 3f92250f4c core: Make sure systemctl exit <X> works outside of a container
When running in a VM, we now support propagating the exit status
via a vsock notify socket, so drop the restrictions on propagating
an exit status when not in a container to make sure this works
properly.
2023-05-12 07:48:29 +02:00
Yu Watanabe 4804da5853 core/mount: escape invalid UTF8 char in dbus reply
When What= or Options= may contain invalid UTF8 chars.

Replaces aaf7b0e411 (#27541).
2023-05-11 19:25:38 +09:00
Yu Watanabe bcf58ff559 Revert "core/mount: replace invalid UTF-8 code points in "what" and "options""
This reverts commit aaf7b0e411.

Not only /proc/mountinfo, .mount units not started yet may contain
invalid UTF-8 chars.
2023-05-11 19:24:42 +09:00
Yu Watanabe 6112c86139 core: replace hashmap_get() with hashmap_contains() where appropriate 2023-05-10 15:06:44 +09:00
Yu Watanabe 735f0645db core: drop unused argument 2023-05-10 15:06:39 +09:00
Yu Watanabe fcd7e0b7ed core: several cleanups for job_get_timeout()
- add missing assertion,
- rename the argument for storing result,
- always initialize result on success.
2023-05-10 15:06:39 +09:00
Yu Watanabe bc52801034 tree-wide: drop _pure_ attribute from non-pure functions
Prompted by #27595.
Follow-ups for 6723c28f36.
2023-05-10 15:06:24 +09:00
Michal Sekletar aaf7b0e411 core/mount: replace invalid UTF-8 code points in "what" and "options"
Previously, these strings were copied w/o any modification. However, if
mount table contained e.g. remote fs mount like NFS or CIFS that was
mounted from server running with non UTF-8 locale then those strings
might have contained some non UTF-8 characters.

If then client asked about status of such mount unit we tried to forward
these non UTF-8 strings over D-Bus. That is the violation of the
protocol and we ended up kicked from the bus.
2023-05-10 00:01:32 +01:00
Yu Watanabe c093bfe0ad Merge pull request #27534 from keszybz/deperlify
Rewrite udev-test.pl in Python
2023-05-09 18:06:51 +09:00
Zbigniew Jędrzejewski-Szmek 083e2ba445 pid1: drop duplicate include 2023-05-09 08:11:10 +02:00
Yu Watanabe 8d3beb00c0 Merge pull request #27579 from YHNdnzj/refuse-dbus-activation
core: refuse dbus activation if dbus is not running
2023-05-09 06:09:25 +09:00
Yu Watanabe f86a388de3 core/service: fix error cause in the log
Fixes a bug caused by a5648b8094.
Fixes #27575.
2023-05-09 06:08:14 +09:00
Mike Yuan 53964fd26b core: refuse dbus activation if dbus is not running
dbus-broker issues StartUnit directly for activation requests,
so let's add a check on bus state in bus_unit_queue_job to refuse
that if dbus is not running.

Replaces #27570
Closes #26799
2023-05-09 01:42:25 +08:00
Mike Yuan e886315065 core/manager: export manager_dbus_is_running 2023-05-09 01:42:25 +08:00
Yu Watanabe 210cb8d690 core/unit: check the validity of unit type with activation_details_vtable
Follow-up for 24e91e08f8.
2023-05-08 09:49:55 +02:00
Yu Watanabe d2132d3d8d parse-util: make parse_fd() return -EBADF
The previous error code -ERANGE is slightly ambiguous, and use more
specific one. This also drops unnecessary error handlings.

Follow-up for 754d8b9c33 and
e652663a04.
2023-05-08 09:49:55 +02:00
Frantisek Sumsal 24e91e08f8 core: check the unit type more thoroughly when deserializing
Resolves: #27523
2023-05-05 22:15:23 +02:00
Frantisek Sumsal 77be02ad3c core: use extract_first_word() instead of sscanf() 2023-05-05 22:15:23 +02:00
David Tardon b45e316708 main: improve log message 2023-05-05 14:18:17 +02:00
David Tardon e652663a04 tree-wide: use parse_fd() 2023-05-05 09:10:56 +02:00
David Tardon 9f2f16a344 main: add missing return
Follow-up-for: 2b5107e162
2023-05-05 08:49:37 +02:00
Lennart Poettering 3aaa376342 execute: remove credentials dir again when empty
This is closely related to the previous commit: if the credentials dir
is empty and nothing mounted on it, let's remove it again.

This will in particular happen if we decided to not actually install the
mount we prepared for the credentials because it is empty. In that case
the mount point inode is already there, and with this we'll remove it.
Primary effect, users will see ENOENT rather than EACCESS when trying to
access it, which should be preferable, given we already handle that
nicely in our credential consumption code.

This should also be useful on systems where we lack any privs to create
mounts, and thus operate on a regular dir anyway.
2023-05-04 12:10:06 +02:00
Lennart Poettering 21dd1de659 execute: suppress credentials mount if empty
Let's avoid creating another mount in the system if it's empty anyway.

This is mostl a cosmetic thing in one (pretty common) special case: if
creds settings are used in a unit but no creds actually available to be
passed.

(While we are at it this also does one more minor optimization: it
adjusts the MS_RDONLY/MS_NOSUID/… flags of the source mount we are about
to MS_MOVE into the right place only if we actually really move it, and
if we instead unmount it again we won't bother with the flags either)
2023-05-04 12:10:01 +02:00
Yu Watanabe 6cb105b877 core: fix use of uninitialized value
Fixes https://github.com/systemd/systemd/pull/27504#issuecomment-1533354787.
2023-05-04 00:33:33 +01:00
Lennart Poettering 5d63c7eb83 Merge pull request #27450 from poettering/switch-root-modernize
pid1: modernize switch root logic a bit
2023-05-03 20:12:20 +02:00
Lennart Poettering ef25552e8b core: minor coding style modernization in mount.c 2023-05-03 18:26:39 +02:00
Lennart Poettering f2c1d491a5 switch-root: don't require /mnt/ when switching root into host OS
So far, we invoked pivot_root() specifying /mnt/ as second argument,
which then unmounted right-after. We'd create /mnt/ if needed. This
sucks, because it means /mnt/ must strictly be pre-created on immutable
images.

Remove this limitation, by using pivot_root() with "." as source and
target, which will result in two stacked mounts afterwards: the new one
underneath, the old one ontop. We can then simply unmount the top one,
and have what we want without needing any extra /mnt/ dir.

Since we don't need /mnt/ anymore we can get rid of the extra
unmount_old_root parameter and simply specify it as NULL if we don't
want the old mount to stick around.
2023-05-03 17:55:55 +02:00
Lennart Poettering 7b0a126751 manager: add debug logging about BARRIER=1 messages 2023-05-03 14:58:17 +02:00
Lennart Poettering 4627645442 manager: simplify manager_process_barrier_fd() a bit 2023-05-03 14:58:17 +02:00
Yu Watanabe a76dc1f3a0 Merge pull request #27504 from mrc0mmand/fuzz-manager-serialize
test: add a simple fuzzer for manager serialization
2023-05-03 21:45:26 +09:00
Frantisek Sumsal 45b1017488 core: fix NULL pointer dereference during deserialization 2023-05-03 10:09:53 +02:00
Frantisek Sumsal 24e6759cbc test: add a simple fuzzer for manager serialization 2023-05-03 10:09:53 +02:00
msizanoen1 845824acdd core: check for SERVICE_RELOAD_NOTIFY in manager_dbus_is_running
This ensures that systemd won't erronously disconnect from the system
bus in case a bus recheck is triggered immediately after the bus service
emits `RELOADING=1`.

This fixes an issue where systemd-logind sometimes randomly stops
receiving `UnitRemoved` after a system update.

This also handles SERVICE_RELOAD_SIGNAL just in case somebody ever
creates a D-Bus broker implementation that uses `Type=notify-reload`.
2023-05-03 00:14:35 +09:00
Luca Boccassi b8fba0cded generators: skip private tmpfs if /tmp does not exist
When spawning generators within a sandbox we want a private /tmp, but it
might not exist, and on some systems we might be unable to create it
because users want a BTRFS subvolume instead.

Fixes https://github.com/systemd/systemd/issues/27436
2023-05-02 12:28:09 +02:00
Yu Watanabe bc6377762c core/path: do not enqueue new job in .trigger_notify callback
Otherwise,
1. X.path triggered X.service, and the service has waiting start job,
2. systemctl stop X.service
3. the waiting start job is cancelled to install new stop job,
4. path_trigger_notify() is called, and may reinstall new start job,
5. the stop job cannot be installed, and triggeres assertion.

So, instead, let's add a defer event source, then enqueue the new start
job after the stop (or any other type) job finished.

Fixes https://github.com/systemd/systemd/issues/24577#issuecomment-1522628906.
2023-04-29 08:54:29 +09:00
Yu Watanabe 34a4e22e97 core/path: align table 2023-04-29 08:45:06 +09:00
Lennart Poettering c23e9b6a64 pid1: unify implemenation of /run/ disk space safety check a bit
reload/reexec currently used a separate implementation of the /run/ disk
space check, different from the one used for switch-root, even though
the code is mostly the same. The one difference is that the former
checks are authoritative, the latter are just informational (that's
because refusing a reload/reexec is relatively benign, but refusing a
switch-root quite troublesome, since this code is entered when it's
already "too late" to turn turn back, i.e. when the preparatory
transaction to initiate the switch root are already fully executed.

Let's share some code, and unify codepaths.

(This is preparation for later addition of a "userspace reboot" concept)

No change in behaviour, just refactoring.
2023-04-28 23:27:20 +01:00
Lennart Poettering 5ae89ef347 core/systemctl: when switching root default to /sysroot/
We hardcode the path the initrd uses to prepare the final mount point at
so many places, let's also imply it in "systemctl switch-root" if not
specified.

This adds the fallback both to systemctl and to PID 1 (this is because
both to — different – checks on the path).
2023-04-28 23:26:20 +01:00
Yu Watanabe 75fd8ad008 Merge pull request #27424 from dtardon/auto-cleanup
More automatic cleanup
2023-04-28 18:46:36 +09:00
David Tardon 7fb1cc85ab transaction: make transaction_free() static
... as it's not needed outside transaction.c anymore.
2023-04-28 09:28:25 +02:00
David Tardon 32620826cf manager: use _cleanup_ in manager_propagate_reload() 2023-04-28 09:27:37 +02:00
David Tardon c7e3eb5dd5 manager: use _cleanup_ in manager_add_job() 2023-04-28 09:27:37 +02:00
David Tardon 542fe40845 transaction: introduce transaction_abort_and_free()
Will be used in following commits.
2023-04-28 09:26:20 +02:00
David Tardon 12da8805e7 transaction: modernize transaction_free() 2023-04-27 21:42:38 +02:00
Lennart Poettering bcd9b98159 core: change ownership of subcgroup we create recursively, it shall be owned by the user delegated to
If we create a subcroup (regardless if the '.control' subgroup we
always created or one configured via DelegateSubgroup=) it's inside of
the delegated territory of the cgroup tree, hence it should be owned
fully by the unit's users. Hence do so.
2023-04-27 12:18:32 +02:00