1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00
Commit Graph

63955 Commits

Author SHA1 Message Date
Frantisek Sumsal
3a8b7e8b5f test: stop the test unit when it's not needed anymore
Otherwise it keeps printing stuff to the journal/console, adding
unnecessary noise.
2023-04-14 21:13:14 +02:00
Frantisek Sumsal
e51d13d61d test: check the colored --version output 2023-04-14 21:07:51 +02:00
Luca Boccassi
3e5b771755
Merge pull request #27269 from poettering/statx-dont-sync
mountpoint-util: don't go to the network when doing statx() to detect mountpoints/mnt_id
2023-04-14 16:23:51 +01:00
Lennart Poettering
d791013ff5 string-util: add strstrafter()
strstrafter() is like strstr() but returns a pointer to the first
character *after* the found substring, not on the substring itself.
Quite often this is what we actually want.

Inspired by #27267 I think it makes sense to add a helper for this,
to avoid the potentially fragile manual pointer increment afterwards.
2023-04-14 16:56:15 +02:00
Daan De Meyer
bb7b1da8fe
Merge pull request #27252 from yuwata/chase-mkdir
chase: refuse CHASE_MKDIR_0755 without CHASE_NONEXISTENT or CHASE_PARENT
2023-04-14 15:19:57 +02:00
Luca Boccassi
4d67245472
Merge pull request #27266 from dtardon/take-struct
Use TAKE_STRUCT() to copy and reset structs
2023-04-14 14:15:35 +01:00
Luca Boccassi
465529125a
Merge pull request #27265 from dtardon/memleak
Fix memory leak if GREEDY_REALLOC() fails
2023-04-14 14:14:15 +01:00
Lennart Poettering
d230d4770d mountpoint-util: use memcmp_nn() where appropriate 2023-04-14 13:15:39 +02:00
Lennart Poettering
524ea5852a mountpoint-util: fix hosed overflow check
The overflow check was hosed in two ways: overflows in C are undefined,
hence gcc was free to just optimize the whole thing away. We need to
catch overflows before we run into them, not after.

It checked for an overflow against size_t, but the field we need to
write this in is unsigned. i.e. typically 32bit rather than 64bit. Hence
check for the right maximum.

(The whole check is paranoia anyway, the kernel really shouldn't return
values that would induce an overflow, but you never know, the syscall
turned out to be problematic in so many other ways, hence let's stick to
this.)
2023-04-14 13:15:39 +02:00
Lennart Poettering
92851defbd mountpoint-util: pass AT_STATX_DONT_SYNC to statx() when looking for mnt_id/mountpoints
The concept of a "mount" is a local one, hence there's no point in going
to the network to retrieve mnt_id or STATX_ATTR_MOUNT_ROOT. Hence set
AT_STATX_DONT_SYNC so that the call will not go to the network ever, and
risk deadlocking on that.

Just some extra safety.
2023-04-14 13:15:35 +02:00
David Tardon
f52477d611 install: use FOREACH_ARRAY 2023-04-14 10:24:07 +02:00
David Tardon
05cdf6a701 tree-wide: rename cleanup function
... with accordance to the current coding style.
2023-04-14 10:24:07 +02:00
David Tardon
52c788e6e0 install: fix memory leak if GREEDY_REALLOC() fails 2023-04-14 10:23:15 +02:00
David Tardon
cfc28ee232 tree-wide: add some asserts 2023-04-14 10:16:01 +02:00
David Tardon
088d71f8ed tree-wide: use TAKE_STRUCT 2023-04-14 10:15:44 +02:00
Yu Watanabe
4ea0bcb922 chase: CHASE_MKDIR_0755 requires CHASE_NONEXISTENT and/or CHASE_PARENT
When CHASE_MKDIR_0755 is specified without CHASE_NONEXISTENT and
CHASE_PARENT, then chase() succeeds only when the file specified by
the path already exists, and in that case, chase() does not create
any parent directories, and CHASE_MKDIR_0755 is meaningless.

Let's mention that CHASE_MKDIR_0755 needs to be specified with
CHASE_NONEXISTENT or CHASE_PARENT, and adds a assertion about that.
2023-04-14 16:36:13 +09:00
Yu Watanabe
5a2f674a00 chase: use FLAGS_SET() macro 2023-04-14 16:28:54 +09:00
Yu Watanabe
13524b29a2
Merge pull request #27254 from poettering/cmsg-align-check
socket-util: tighten CMSG_TYPED_DATA() alignment checks
2023-04-14 13:49:04 +09:00
Luca Boccassi
2cba2fcd25
Merge pull request #27144 from enr0n/fix-scope-timer-on-coldplug
scope: do not disable timer event source when state is SCOPE_RUNNING
2023-04-14 00:25:06 +01:00
Luca Boccassi
6ef721cbc7 user units: implicitly enable PrivateUsers= when sandboxing options are set
Enabling these options when not running as root requires a user
namespace, so implicitly enable PrivateUsers=.
This has a side effect as it changes which users are visible to the unit.
However until now these options did not work at all for user units, and
in practice just a handful of user units in Fedora, Debian and Ubuntu
mistakenly used them (and they have been all fixed since).

This fixes the long-standing confusing issue that the user and system
units take the same options but the behaviour is wildly (and sometimes
silently) different depending on which is which, with user units
requiring manually specifiying PrivateUsers= in order for sandboxing
options to actually work and not be silently ignored.
2023-04-13 21:33:48 +01:00
Luca Boccassi
ce963a747f
Merge pull request #27244 from bluca/uphold_retry
Uphold/StopWhenUnneeded/BindsTo: add retry timer on rate limit
2023-04-13 21:33:06 +01:00
ZjYwMj
dd9f909ea8
Synposis and description of networkctl man page reflecting only part of its functionality (#27264)
* Fix inaccurate synposis, and description

Before the fix, they reflected only part of networkctl functionality.
2023-04-13 21:30:42 +01:00
Mike Yuan
6b7f150bbf core/main: fix a typo for --log-target
Follow-up for d2ebd50d7f

Fixes #27105
2023-04-13 21:29:35 +01:00
Nick Rosbrook
af4688398f test: add some tests for RuntimeMaxSec
Make sure the RuntimeMaxSec is applied correctly to service and scope
units when they are started, and also on coldplug.
2023-04-13 15:43:30 -04:00
Nick Rosbrook
e1f85b49b0 scope: do not disable timer event source when state is SCOPE_RUNNING
In scope_set_state(), the timer event source may be disabled depending
on the state. Currently, it will be disabled when the state is
SCOPE_RUNNING. This has the effect of new RuntimeMaxSec values being
ignored on coldplug.

Note that this issue is not currently present when scopes are started
because when scope_start() is called, scope_arm_timer() is called after
scope_set_state().
2023-04-13 14:34:41 -04:00
Luca Boccassi
0607a9f9da systemd-confext: mount confexts as noexec and nosuid
Confexts should not contain code, so mount confexts with noexec.
We cannot mount invidial extensions as noexec, as the overlay ignores
it and bypasses it, we need to use the flag on the whole overlay for
it to be effective.
But given there are legacy scripts still shipped in /etc, allow to
override it with --noexec=false.
2023-04-14 01:21:48 +08:00
Daan De Meyer
fde55f3a32 mkosi: Update to latest
The Bootable= option was removed and mkosi installs less packages
by default now, so let's adapt our configs to those changes.
2023-04-13 13:49:30 +01:00
Luca Boccassi
4c7a0fc8d0 Uphold/StopWhenUnneeded/BindsTo: requeue when job finishes
When a unit is upheld and fails, and there are no state changes in
the upholder, it will not be retried, which is against what the
documentation suggests.

Requeue when the job finishes. Same for the other two queues.
2023-04-13 13:28:25 +01:00
OMOJOLA JOSHUA DAMILOLA
96ead603b8 systemd-cryptenroll: add string aliases for tpm2 PCRs
Fixes #26697. RFE.
2023-04-13 12:08:32 +01:00
Yu Watanabe
85ba4ca8f6 test: add several assertions
Follow-up for 7947dbe322.

Fixes CID#1508781 and CID#1508783.
2023-04-13 11:57:29 +01:00
Lennart Poettering
796da645a0
Merge pull request #18789 from gportay/veritysetup-add-options-for-parity-with-cryptsetup-verity-utility
veritysetup: Add options for parity support with the cryptsetup's verity utility
2023-04-13 11:32:57 +02:00
Yu Watanabe
06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
84be0c710d (r1060130312),
84be0c710d (r1067927293), and
84be0c710d (r1067926416).

Follow-up for 84be0c710d.
2023-04-13 11:17:28 +02:00
Sjoerd Simons
771805eb44 repart: Discard from/to first/last usable lba
Repart considers the start and end of the usable space to the first multiple
of grainsz (at least 4096 bytes). However the first usable LBA of a GPT
partition is at sector 34 (512 bytes sectors) which is not a multiple of 4096.
The backup GPT label at the end also takes up 33 sectors, meaning the last
usable LBA is at 34 sectors from the end, unlikely to be a 4096 multiple as
well.

This meant that the very first and last sectors were never discarded. However
more problematically if an existing partition started before the first
usable grainsz multiple its start didn't get taken into account as a valid
starting point and got its data discarded.

Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
2023-04-13 11:12:52 +02:00
Lennart Poettering
ca918f63b7 udev,sd-device: use CMSG_FIND_DATA() more 2023-04-13 10:49:23 +02:00
Lennart Poettering
b1d0219136 tree-wide: port more code over to CMSG_TYPED_DATA() 2023-04-13 10:49:23 +02:00
Lennart Poettering
79dec6f5cc socket-util: tighten aignment check for CMSG_TYPED_DATA()
Apparently CMSG_DATA() alignment is very much undefined. Which is quite
an ABI fuck-up, but we need to deal with this. CMSG_TYPED_DATA() already
checks alignment of the specified pointer. Let's also check matching
alignment of the underlying structures, which we already can do at
compile-time.

See: #27241

(This does not fix #27241, but should catch such errors already at
compile-time instead of runtime)
2023-04-13 10:21:31 +02:00
Lennart Poettering
39857544ee
Merge pull request #27027 from dtardon/unit-file-list-cleanup
Use _cleanup_ for UnitFileList hash
2023-04-13 09:10:17 +02:00
Yu Watanabe
37734dc677 repart: always take BSD lock when whole block device is opened
Fixes #27236.
2023-04-13 09:07:00 +02:00
Lennart Poettering
5d0fd36495
Merge pull request #27135 from poettering/pin-fdstore
Allow the per-service fdstore to be "pinned", i.e. preserved as long as the unit info remains in memory
2023-04-13 07:16:24 +02:00
Lennart Poettering
3540ce8587 test: validate that fdstore pinning works 2023-04-13 06:44:27 +02:00
Lennart Poettering
e8783d7620 pid1: add some debug logging when stashing ds into the fdstore 2023-04-13 06:44:27 +02:00
Lennart Poettering
81a1d6d679 service: rename service_close_socket_fd() → service_release_socket_fd()
Just to match service_release_stdio_fd() and service_release_fd_store()
in the name, since they do similar things.

This follows the concept that we "release" resources, and this is all
generically wrapped in "service_release_resources()".
2023-04-13 06:44:27 +02:00
Lennart Poettering
1ba84fef3c core: move runtime directory removal into release_resource handler
We already clear the various fds we keep from the release_resources()
handler, let's also destroy the runtime dir from there if this
preservation mode is selected.

This makes a minor semantic change: previously we'd keep a runtime
directory around if RuntimeDirectoryPreserve=restart is selected and at
least one JOB_START job was around. With this logic we'll keep it around
a tiny bit longer: as long as any job for the unit is around.
2023-04-13 06:44:27 +02:00
Lennart Poettering
99620f457e service: close fdstore asynchronously
The file descriptors we keep in the fdstore might be basically anything,
let's clean it up with our asynchronous closing feature, to not
deadlock on close().

(Let's also do the same for stdin/stdout/stderr fds, since they might
point to network services these days.)
2023-04-13 06:44:27 +02:00
Lennart Poettering
4fb8f1e883 service: allow freeing the fdstore via cleaning
Now that we have a potentially pinned fdstore let's add a concept for
cleaning it explicitly on user requested. Let's expose this via
"systemctl clean", i.e. the same way as user directories are cleaned.
2023-04-13 06:44:27 +02:00
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
Gaël PORTAY
21c60c76e1 veritysetup: add support for fec options
The verity fec_* parameters allows to use Forward Error Correction to
recover from corruption if hash verification fails.

This adds the options fec_device, fec_offset and fec_roots (sixth
argument) which are the equivalent of the options --fec-device,
--fec-offset and --fec-roots in the veritysetup world.
 - fec-device=FILE
 - fec-offset=BYTES
 - fec-roots=UINT64

See `veritysetup(8)` for more details.
2023-04-13 05:39:49 +02:00