1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00
Commit Graph

63896 Commits

Author SHA1 Message Date
Lennart Poettering
b9c1883a9c service: add ability to pin fd store
Oftentimes it is useful to allow the per-service fd store to survive
longer than for a restart. This is useful in various scenarios:

1. An fd to some security relevant object needs to be stashed somewhere,
   that should not be cleaned automatically, because the security
   enforcement would be dropped then.

2. A user namespace fd should be allocated on first invocation and be
   kept around until the user logs out (i.e. systemd --user ends), á la
   #16328 (This does not implement what #16318 asks for, but should
   solve the use-case discussed there.)

3. There's interest in allow a concept of "userspace reboots" where the
   kernel stays running, and userspace is swapped out (i.e. all services
   exit, and the rootfs transitioned into a new version of it) while
   keeping some select resources pinned, very similar to how we
   implement a switch root. Thus it is useful to allow services to exit,
   while leaving their fds around till the very end.

This is exposed through a new FileDescriptorStorePreserve= setting that
is closely modelled after RuntimeDirectoryPreserve= (in fact it reused
the same internal type), since we want similar behaviour in the end, and
quite often they probably want to be used together.
2023-04-13 06:44:27 +02:00
Lennart Poettering
c25fac9a17 service: rework how we release resources
Let's normalize how we release service resources, i.e. the three types
of fds we maintain for each service:

1. the fdstore
2. the socket fd for per-connection socket activated services
3. stdin/stdout/stderr

The generic service_release_resources() hook now calls into
service_release_fd_store() + service_close_socket_fd()
service_release_stdio_fd() one after the other, releasing them all for
the generic "release_resources" infra of the unit lifecycle.

We do no longer close the socket fd from service_set_state(), moving
this exclusively into service_release_resources(), so that all fds are
closed the same way.
2023-04-13 06:44:27 +02:00
Lennart Poettering
6ac62d61db service: release resources from a seperate queue, not unit_check_gc()
The per-unit-type release_resources() hook (most prominent use: to
release a service unit's fdstore once a unit is entirely dead and has no
jobs more) was currently invoked as part of unit_check_gc(), whose
primary purpose is to determine if a unit should be GC'ed. This was
always a bit ugly, as release_resources() changes state of the unit,
while unit_check_gc() is otherwise (and was before release_resources()
was added) a "passive" function that just checks for a couple of
conditions.

unit_check_gc() is called at various places, including when we wonder if
we should add a unit to the gc queue, and then again when we take it out
of the gc queue to dtermine whether to really gc it now. The fact that
these checks have side effects so far wasn't too problematic, as the
state changes (primarily: that services would empty their fdstores) were
relatively limited and scope.

A later patch in this series is supposed to extend the service state
engine with a separate state distinct from SERVICE_DEAD that is very
much like it but indicates that the service still has active resources
(specifically the fdstore). For cases like that the releasing of the
fdstore would result in state changes (as we'd then return to a classic
SERVICE_DEAD state).  And this is where the fact that the
release_resources() is called as side-effect becomes problematic: it
would mean that unit state changes would instantly propagate to state
changes elsewhere, though we usually want this to be done through the
run queue for coalescing and avoidance of recursion.

Hence, let's clean this up: let's move the release_resources() logic
into a queue of its own, and then enqueue items into it from the general
state change notification handle in unit_notify().
2023-04-13 06:44:27 +02:00
Lennart Poettering
47226e893b core: fix property getter method for NFileDescriptorStore bus property
Since da6053d0a7 this is a size_t, not an
unsigned. The difference doesn't matter on LE archs, but it matters on
BE (i.e. s390x), since we'll return entirely nonsensical data.

Let's fix that.

Follow-up-for: da6053d0a7

An embarassing bug introduced in 2018... That made me scratch my head
for way too long, as it made #27135 fail on s390x while it passed
everywhere else.
2023-04-13 06:41:27 +02:00
Franklin Yu
8dacdd28f4 Fix cross-reference of manual for LogsDirectory 2023-04-13 12:17:40 +09:00
David Schroeder
9c669abb71
pid1: fix coredump_filter setting
Correct what appears to be a copy/paste error in config_parse_exec_coredump_filter that is preventing the coredump_filter setting from working correctly.
2023-04-13 07:48:21 +08:00
Michal Sekletar
5015b5014b man: add util-linux to the package list for Fedora container
/bin/login is shipped in util-linux, however, systemd.spec on Fedora has
"Requires: (util-linux-core or util-linux)". If the dependency is
fulfilled just by installation of util-linux-core then users won't be
able to log in into the container after it boots. Let's add util-linux
package to the package list so that /bin/login is always present.
2023-04-12 20:25:16 +01:00
Lennart Poettering
112f27fdbf
Merge pull request #27153 from poettering/varlin-fd-pass
varlink: implement file descriptor passing
2023-04-12 20:34:01 +02:00
Mike Yuan
93ba4c1bc0
Merge pull request #27212 from DaanDeMeyer/notify-exit
core: Propagate exit status via notify socket when running in VM
2023-04-13 01:12:03 +08:00
Mike Yuan
7581da99a1
Merge pull request #27229 from poettering/dissect-policy-confext
dissect: follow-up for image policy merge
2023-04-13 00:14:30 +08:00
Zbigniew Jędrzejewski-Szmek
5a9e2dff47 man: link to Fedora 37
Fedora 36 is a bit old at this point and will be EOL in about 6 weeks.
Fedora 38 is not out yet, so the cloud link wouldn't work.
2023-04-13 00:13:44 +08:00
Yu Watanabe
8e1d6003fb
Merge pull request #27217 from yuwata/boot-entry-at
boot-entry: introduce _at() variant
2023-04-12 22:59:54 +09:00
Lennart Poettering
db1f7c84ea varlink: honour "sensitive" flag of json variant objects all the way into the socket
Let's honour the flag if it is set, just to be safe.

(This only handles the case for the writing side: whenever the client
code hands us a json object with the flag set we'll honour it till the
it's out of reach for us. This does *not* handle the reading side, which
is left for a later patch once needed. We probably should add a
per-connection flag that simply globally enables the sensitive logic for
all messages coming in on a specific varlink conneciton.)
2023-04-12 15:14:21 +02:00
Lennart Poettering
7947dbe322 test: add varlink fd passing test 2023-04-12 15:14:21 +02:00
Lennart Poettering
d37cdac6ce varlink: implement file descriptor passing
Let's add infrastructure to implement fd passing in varlink, when used
over AF_UNIX.

This will optionally associate one or more fds with a message sent via
varlink and deliver it to the server.
2023-04-12 15:14:21 +02:00
Lennart Poettering
790446bd6c varlink: add helper that clears the currently processed incoming message JSON object
Some minor refactoring. This adds a helper call whose only job is to
unref the JSON object of the currently processed incoming message.

This doesn't make too much sense on its own, given this just replaces
one line by another. However, in a later patch when we'll add fd passing
we'll extend the function to also destroy associated fds, and then it
will start to make more sense.
2023-04-12 15:14:21 +02:00
Lennart Poettering
8531631763 varlink: get rid of "reply" field
So far, if we do a synchronous varlink call from the client side via
varlink_call(), we'll
move the returned json object from "v->current" into "v->reply", and
keep it referenced there until the next call. We then return a pointer
to it. This ensures that the json object remains valid between two
varlink_call() invocations.

But the thing is, we don't need a separate field for that, we can just
leave the data in "v->current". This means VARLINK_IDLE_CLIENT state
will be permitted with and without v->current initialized. Initially,
after connection setup it will be set to NULL, but after the first
varlink_call() it will be set to the most recent response, pinning it
into memory.
2023-04-12 15:14:21 +02:00
Lennart Poettering
a3861b4726 varlink: add some comments explaining what by various errors are defined 2023-04-12 15:14:21 +02:00
Daan De Meyer
88eec29d18 core: Send ERRNO= via notify socket on exit 2023-04-12 15:03:45 +02:00
Daan De Meyer
3a89cb84a6 core: Propagate exit status via notify socket when running in VM
When running in a container, we can propagate the exit status of
pid1 as usual via the process exit status. This is not possible
when running in a VM. Instead, let's send EXIT_STATUS=%i via the
notify socket if one is configured. The user running the VM can then
pick up the exit status from the notify socket after the VM has shut
down.
2023-04-12 15:03:43 +02:00
Daan De Meyer
623a00020f notify: Add EXIT_STATUS field
Whenever one of our tools or daemons exits, let's send the exit status
via sd-notify in the EXIT_STATUS field.
2023-04-12 15:02:34 +02:00
Lennart Poettering
4f25844a4b sysext: define a default image dissection policy for confext images 2023-04-12 14:54:44 +02:00
Lennart Poettering
b151e69671 discover-image: bring discover path list up-to-date.
While merge 3af48a86d9 was for a working
PR it was based on an older version of git main. Let's catch up with the
search path changes from de862276ed.
2023-04-12 14:41:32 +02:00
Daan De Meyer
14cb10b737 Fix compilation error 2023-04-12 14:36:14 +02:00
Thierry Martin
2f091b1b49 nspawn: container network interface naming
systemd-nspawn now optionally supports colon-separated pair of
host interface name and container interface name for --network-macvlan, --network-ipvlan and --network-interface options.
Also supported in .nspawn configuration files (i.e Interface=, MACVLAN=, IPVLAN= parameters).

man page changed for ntwk interface naming
2023-04-12 14:28:43 +02:00
Lennart Poettering
3af48a86d9
Merge pull request #25608 from poettering/dissect-moar
dissect: add dissection policies
2023-04-12 13:46:08 +02:00
Luca Boccassi
068943453f
Merge pull request #27165 from poettering/fdstore-envvar
service: tell service processes that the fdstore is available via an e…
2023-04-12 12:13:43 +01:00
Yu Watanabe
d2d969bb45 boot-entry: introduce boot_entry_token_ensure_at() 2023-04-12 19:47:34 +09:00
Yu Watanabe
e61ab091b7
Merge pull request #27223 from dtardon/install-changes
Simplify use of bus_deserialize_and_dump_unit_file_changes()
2023-04-12 19:30:51 +09:00
Daan De Meyer
ea24ed79f6
Merge pull request #27220 from yuwata/sd-device-follow-ups-for-devlink
sd-device: several follow-ups about devlink creation
2023-04-12 11:49:08 +02:00
Lennart Poettering
1412ad9a81 man: rebreak all of sd_notify(3)
No change of contents, just some rebreaking of the full file to match
our current line break settings.
2023-04-12 10:34:37 +02:00
Lennart Poettering
75b29fda71 service: tell service processes that the fdstore is available via an env var 2023-04-12 10:34:31 +02:00
David Tardon
234d964c2e systemctl: reduce variable scope 2023-04-12 09:53:55 +02:00
David Tardon
5e891cbb5c tree-wide: drop unneeded output params
Neither of the callers of bus_deserialize_and_dump_unit_file_changes()
touches the changes array, so let's simplify things and keep it internal
to the function.
2023-04-12 09:53:55 +02:00
Yu Watanabe
f643ca1767
Merge pull request #27033 from dtardon/array-cleanup
Use CLEANUP_ARRAY more
2023-04-12 16:43:39 +09:00
Yu Watanabe
fda18ce2b6 boot-entry: use chase_and_fopen_unlocked() to open /etc/kernel/entry-token
Otherwise, when 'root' is specified, the file may be a symlink to a host
file, and we may read wrong entry.
2023-04-12 16:23:03 +09:00
Yu Watanabe
7e430500d2 udev-test: add more testcases for SYMLINK 2023-04-12 10:52:14 +09:00
Frantisek Sumsal
82929336c7 test: drop binary stripping stuff
Stripping the binaries in the test images makes potential stack straces
quite useless, so let's drop the stripping stuff to make test fails a bit
more developer friendly.

Related: https://github.com/systemd/systemd-centos-ci/pull/616
2023-04-12 10:33:32 +09:00
Yu Watanabe
70e4510805 sd-device: absolute devlink must start with /dev/
This also makes device node path is handled with the same logic.

Addresses https://github.com/systemd/systemd/pull/27169#discussion_r1162739511.

Follow-up for 2c5f119c3c.
2023-04-12 09:20:11 +09:00
Yu Watanabe
3b5fc5fb1b boot-entry: prioritize machine ID only when it is not randomly generated
Preparation for later commits. The parameter will be used in
kernel-install later.
2023-04-12 08:31:50 +09:00
Daan De Meyer
965b481d9b
Merge pull request #27214 from DaanDeMeyer/firstboot
firstboot: Use root directory file descriptor for everything
2023-04-11 22:30:09 +02:00
Tanishka
fd7623193d Modified to use STRV_MAKE() in strv_env_name_is_valid() function listed in env-util.c 2023-04-11 21:05:22 +02:00
Zbigniew Jędrzejewski-Szmek
f843f8be9c
Merge pull request #27209 from jamacku/patch-1
Don't run release workflow on `systemd-security` & drop checkout action
2023-04-11 20:44:48 +02:00
Mike Yuan
8a826a979a systemctl: suppress error for try-* if unit is masked
Closes #16521
2023-04-11 17:54:02 +01:00
Jan Janssen
b87d6da447 boot: Fix alignment of long long inside structs on x86
On x86 EFI follows the windows ABI, which expects 8-byte aligned long
long. The x86 sysv ELF ABI expects them to be 8-byte aligned when used
alone, but 4-byte aligned when they appear inside of structs:

    struct S {
        int i;
        long long ll;
    };

    // _Static_assert(sizeof(struct S) == 12, "x86 sysv ABI");
    _Static_assert(sizeof(struct S) == 16, "EFI/MS ABI");

To get the behavior we need when building with sysv ELF ABI we need to
pass '-malign-double' to the compiler as done by EDK2.

This in turn will make ubsan unhappy as the stack may not be properly
aligned on entry, so we have to tell the compiler explicitly to re-align
the stack on entry to efi_main.

This fixes loading EFI drivers on x86 that were previously always
rejected as the EFI_LOADED_IMAGE_PROTOCOL had a wrong memory layout.

See also: https://github.com/rhboot/shim/pull/516
2023-04-11 17:09:18 +01:00
Jan Macku
19cdda7c3a ci: drop checkout from release workflow
It's not required as per comment - https://github.com/systemd/systemd/pull/27110#issuecomment-1499653913
2023-04-11 16:59:18 +02:00
Jan Macku
9718afd194 ci: don't run release wf on systemd-security 2023-04-11 16:59:18 +02:00
David Tardon
f86a41291b portabled-image-bus: use CLEANUP_ARRAY 2023-04-11 16:32:48 +02:00
David Tardon
a5290effe8 portabled-image-bus: use CLEANUP_ARRAY 2023-04-11 16:32:47 +02:00
David Tardon
2b4b01b00a portabled-image-bus: use CLEANUP_ARRAY 2023-04-11 16:32:46 +02:00