1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-01 09:47:35 +03:00

302 Commits

Author SHA1 Message Date
Lennart Poettering
2f82562bad alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhere
Let's define two helpers strdupa_safe() + strndupa_safe() which do the
same as their non-safe counterparts, except that they abort if called
with allocations larger than ALLOCA_MAX.

This should ensure that all our alloca() based allocations are subject
to this limit.

afaics glibc offers three alloca() based APIs: alloca() itself,
strndupa() + strdupa(). With this we have now replacements for all of
them, that take the limit into account.
2021-10-14 15:57:52 +02:00
Lennart Poettering
f435195925 basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch] 2021-10-05 16:14:37 +02:00
Zbigniew Jędrzejewski-Szmek
3c9fbb993b variuos: add missing includes 2021-09-22 12:58:46 +02:00
Luca Boccassi
409f4cf1f2 portable: copy SELinux label when extracting units from images
Units are copied out via sendmsg datafd from images, but that means
the SELinux labels get lost in transit. Extract them and copy them over.

Given recvmsg cannot use multiple IOV transparently when the sizes are
variable, use a '\0' as a separator between the filename and the label.
2021-09-20 14:23:55 +01:00
Luca Boccassi
447d46879c portable: use send_one_fd_iov/receive_one_fd_iov instead of custom helpers
Will be useful for the next commit switching to multiple IOVs
2021-09-20 14:23:55 +01:00
Luca Boccassi
9ff61565be portabled: refactor extraction/validation into a common helper 2021-09-06 13:20:01 +01:00
Luca Boccassi
239ac0c7f7 portabled: validate SYSEXT_LEVEL when attaching
When attaching a portable service with extensions, immediately validate
that the os-release and extension-release metadata values match, rather
than letting it fail when the units are started
2021-09-06 12:14:50 +01:00
Luca Boccassi
7bf5ec4538 portabled: error out if there are no units only after parsing all images
It's ok if the OS image doesn't have matching units, if we find them
in the extensions. Tidies up the parsing logic a bit.
2021-09-06 12:13:53 +01:00
Luca Boccassi
9ccb531a5f dissect-image: add extension-specific validation flag
Allows callers to specify which image type they are looking for
2021-09-06 12:13:53 +01:00
Luca Boccassi
1f08acf406
Merge pull request #20257 from bluca/seqno
Use new diskseq block device property
2021-08-31 09:06:33 +01:00
Zbigniew Jędrzejewski-Szmek
04499a70fb Drop the text argument from assert_not_reached()
In general we almost never hit those asserts in production code, so users see
them very rarely, if ever. But either way, we just need something that users
can pass to the developers.

We have quite a few of those asserts, and some have fairly nice messages, but
many are like "WTF?" or "???" or "unexpected something". The error that is
printed includes the file location, and function name. In almost all functions
there's at most one assert, so the function name alone is enough to identify
the failure for a developer. So we don't get much extra from the message, and
we might just as well drop them.

Dropping them makes our code a tiny bit smaller, and most importantly, improves
development experience by making it easy to insert such an assert in the code
without thinking how to phrase the argument.
2021-08-03 10:05:10 +02:00
Luca Boccassi
a36429971a dissect: use DISKSEQ when waiting for block devices
DISKSEQ is a reliable way to find out if we missed a uevent or not, as
it's monotonically increasing. If we parse an event with a smaller or
no sequence number, we know we need to wait longer. If we parse an
event with a greater sequence number, we know we missed it and the
device was reused.
2021-07-28 20:07:01 +01:00
Zbigniew Jędrzejewski-Szmek
fce9abb227 meson: use a/b instead of join_paths(a,b)
It is nicer and shorter.
2021-07-27 19:32:35 +02:00
Frantisek Sumsal
2f0927626a tree-wide: coccinelle fixes
Yet another batch of Coccinelle fixes.
2021-07-09 20:54:22 +01:00
Zbigniew Jędrzejewski-Szmek
280e4b368e
Merge pull request #20004 from yuwata/readdir-ensure-type
dirent-util: introduce readdir_ensure_type()
2021-06-24 15:11:06 +02:00
Zbigniew Jędrzejewski-Szmek
6a818c3cb4 basic: move acquire_data_fd() and fd_duplicate_data_fd() to new data-fd-util.c
fd_duplicate_data_fd() is renamed to copy_data_fd(). This makes
the two functions have nicely similar names.

Now fd-util.[ch] is again about low-level file descriptor manipulations.
copy_data_fd() is a complex function that internally wraps the other
functions in copy.c. I want to move copy.c and the whole cluster of
related code from basic/ to shared/ later on, and this is a preparatory
step for that.
2021-06-24 10:05:22 +02:00
Yu Watanabe
f565b8676f dirent-util: use readdir_ensure_type() in readdir_no_dot() and FOREACH_DIRENT() 2021-06-24 04:29:40 +09:00
Yu Watanabe
4ff361cc86 tree-wide: always drop unnecessary dot in path 2021-05-28 13:44:38 +09:00
Lennart Poettering
319a4f4bc4 alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()
We recently started making more use of malloc_usable_size() and rely on
it (see the string_erase() story). Given that we don't really support
sytems where malloc_usable_size() cannot be trusted beyond statistics
anyway, let's go fully in and rework GREEDY_REALLOC() on top of it:
instead of passing around and maintaining the currenly allocated size
everywhere, let's just derive it automatically from
malloc_usable_size().

I am mostly after this for the simplicity this brings. It also brings
minor efficiency improvements I guess, but things become so much nicer
to look at if we can avoid these allocation size variables everywhere.

Note that the malloc_usable_size() man page says relying on it wasn't
"good programming practice", but I think it does this for reasons that
don't apply here: the greedy realloc logic specifically doesn't rely on
the returned extra size, beyond the fact that it is equal or larger than
what was requested.

(This commit was supposed to be a quick patch btw, but apparently we use
the greedy realloc stuff quite a bit across the codebase, so this ends
up touching *a*lot* of code.)
2021-05-19 16:42:37 +02:00
Lennart Poettering
21b61b1dd2 dissect-image: add support for optionally mounting images with idmapping on 2021-05-07 22:44:05 +02:00
Zbigniew Jędrzejewski-Szmek
7b87fe4c30 various: print the image path when setting up of the loopback device fails 2021-04-23 15:11:38 +02:00
Lennart Poettering
4a62257d68 dissect: ignore udev database entries from before the loopback attachment
This tries to shorten the race of device reuse a bit more: let's ignore
udev database entries that are older than the time where we started to
use a loopback device.

This doesn't fix the whole loopback device raciness mess, but it makes
the race window a bit shorter.
2021-04-20 17:20:38 +02:00
Lennart Poettering
75dc190d39 dissect: ignore old uevents when waiting for loopback partition scan
Let's drop all monitor uevent that were enqueued before we actually
started setting up the device.

This doesn't fix the race, but it makes the race window smaller: since
we cannot determine the uevent seqnum and the loopback attachment
atomically, there's a tiny window where uevents might be generated by
the device which we mistake for being associated with out use of the
loopback device.
2021-04-20 17:14:10 +02:00
Luca Boccassi
c2b2df604b tree-wide: avoid uninitialized warning on _cleanup_ variables
With some versions of the compiler, the _cleanup_ attr makes it think
the variable might be freed/closed when uninitialized, even though it
cannot happen. The added cost is small enough to be worth the benefit,
and optimized builds will help reduce it even further.
2021-04-14 12:25:06 +01:00
Zbigniew Jędrzejewski-Szmek
1b09b81cf4 tree-wide: sd_bus_error_setf → set_bus_error_set
strdup() is more efficient than asprintf().
2021-04-07 16:04:52 +02:00
Luca Boccassi
907952bbc9 portabled: add --extension parameter for layered images support
Add an --extension parameter to portablectl, and new DBUS methods
to attach/detach/reattach/inspect.
Allows to append separate images on top of the root directory (os-release
will be searched in there) and mount the images using an overlay-like
setup (unit files will be searched in there) using the new ExtensionImages
service option.
2021-03-31 09:56:44 +01:00
Lennart Poettering
4b5de5dd6c dissect-image: split DISSECT_IMAGE_REQUIRE_ROOT in two
Previously, the flag did two things at once: enable support for using
generic partitions as root fs if there were only one/allow use of
partition-table-less images as root fs. And secondly, insist that there
was a rootfs, and fail if not. Let's split these two in two separate
options so that they can be used independently of each other.

There are cases where one wants to use one without the other (i.e. when
inspecting things with systemd-dissect tool it should be OK to do so
even if image has no root fs), and it's cleaner anyway.
2021-03-16 14:57:40 +01:00
Lennart Poettering
d04faa4e19 tree-wide: make use of DISSECT_IMAGE_USR_NO_ROOT in various tools
Let's make use of the new dissection in all tools where this makes
sense, which are all tools that dissect images, except for those which
inherently operate on state/configuraiton and thus where an image
without state nor configuration is useless (e.g.
systemd-tmpfiles/systemd-firstboot/… --image= switch).
2021-03-16 14:57:27 +01:00
Yu Watanabe
f5fbe71d95 tree-wide: use UINT64_MAX or friends 2021-03-05 07:10:13 +09:00
Yu Watanabe
ef1e0b9a46 table: drop last SIZE_MAX from table_set_sort() and table_set_display() 2021-03-05 07:10:13 +09:00
Zbigniew Jędrzejewski-Szmek
6ef06723b1 Move os-util.[ch] to basic/
parse_os_release() will be used basic/hostname-util.c later on.
2021-02-22 20:10:55 +01:00
Lennart Poettering
ba5b6c5925 portable: make PortableChangeType enum anonymous
Same reasons as previous commit.
2021-02-17 19:29:24 +01:00
Benjamin Robin
3de56f4712 portable: use -EINVAL for _PORTABLE_CHANGE_TYPE_INVALID
Follow-up of #11484
2021-02-16 23:40:30 +01:00
Luca Boccassi
598f938e3b portabled: use SD_BUS_METHOD_WITH_ARGS 2021-02-15 21:30:01 +00:00
Luca Boccassi
3b91bae3ce portabled: use service_parse_argv/bus_add_implementation
Remove some boilerplate and allow introspection
2021-02-15 21:20:14 +00:00
Luca Boccassi
e26fe5f911 portable: add 'reattach' verb and DBUS interface
Add 'reattach' verb to portablectl, and corresponding DBUS interface
to systemd-portabled.
Takes the same parameters as 'attach', but it will do a 'detach' (and
it will refuse to proceed if it cannot be done) first, matching on
the unversioned prefix of the new image. Eg:

portablectl reattach /tmp/foo_2.raw

will cause foo_1.raw to be detached, and foo_2.raw to be attached.

The key difference with a manual 'detach old' plus 'attach new' is that
the running units are not disturbed until after the attach completed,
and if --now is passed they are then restarted.
A 'detach' is not allowed normally if the units are running.

By using a restart-after-deploy method, 'reattach' allows for minimal
interruption of service and also for features that only work on restart
(eg: file descriptor store) to work as intended.

The DBUS interface returns two lists: first the removals from the detach
that were not immediately re-added in the attach, so that the caller
can stop the relevant units, and then the list of additions that are
either new or updates, so that the caller can restart/enable the
relevant units. portablectl already implements this with the existing
--now/--enable switches.
2021-02-10 19:07:36 +00:00
Luca Boccassi
9e4079d411 portable: allow Detach to match images with different version suffixes 2021-02-10 19:07:27 +00:00
Zbigniew Jędrzejewski-Szmek
2d93c20e5f tree-wide: use -EINVAL for enum invalid values
As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617.

This does not touch anything exposed in src/systemd. Changing the defines there
would be a compatibility break.

Note that tests are broken after this commit. They will be fixed in the next one.
2021-02-10 14:46:59 +01:00
Zbigniew Jędrzejewski-Szmek
ad22e7cf5c
Merge pull request #18375 from yuwata/cli-tools-also-read-kernel-command-line
tree-wide: make CLI tools also read kernel command line when run as service
2021-02-08 11:45:42 +01:00
Lennart Poettering
57f1b61b76 shared: rename machine-image.[ch] → discover-image.[ch]
The old name originates when this was used to discover "machine" images,
as managed by machined/machinectl. But nowadays this is also used by
portable services and system extensions, hence let's use a more generic
name for this API. Taking inspiration from "dissect-image.[ch]", let's call
this "discover-image.[ch]".

This is pure renaming, no other changes.
2021-02-03 23:12:57 +01:00
Yu Watanabe
d2acb93dc5 tree-wide: enable colorized logging for daemons when run in console
It may be useful when debugging daemons.
2021-02-01 01:13:44 +09:00
Daan De Meyer
bc556335b1 tree-wide: Drop custom formatting for print() help messages
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by https://github.com/systemd/systemd/pull/18355#discussion_r567241580
2021-01-31 13:14:02 +09:00
Lennart Poettering
8dd294c5a9 portabled: add BindPaths=/run back into "trusted" policy
This partly reverts fe239c7d7d6227209234100f4e0a36dd952a5587, where I
accidentally dropped only line for /run that was unlike the others.
Oops.

@bluca, thanks for noticing:

https://github.com/systemd/systemd/pull/18329#pullrequestreview-573343549
2021-01-21 19:15:08 +00:00
Lennart Poettering
fe239c7d7d portabled: update profiles to current semantics
MountAPIVFS= implicitly mounts /run as tmpfs now, no need to do this
explicitly.

The notification socket is now implicitly mounted too, if NotifyAccess=
and RootImage=/RootDirectory= are used together.
2021-01-20 22:39:53 +01:00
Lennart Poettering
d577d4a432 machine-image: properly support searching for images below some --root= path
systemd-sysext supports --root= for everything but the image discovery.
Fix that.
2021-01-19 13:41:42 +01:00
Lennart Poettering
c2bc710b24 string-util: imply NULL termination of strextend() argument list
The trailing NULL in the argument list is now implied (similar to
what we already have in place in strjoin()).
2021-01-06 17:24:46 +01:00
Yu Watanabe
db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek
ab4a88eb92 sd-bus: add custom return code when $XDG_RUNTIME_DIR is not set
We would return ENOENT, which is extremely confusing. Strace is not helpful because
no *file* is actually missing. So let's add some logs at debug level and also use
a custom return code. Let all user-facing utilities print a custom error message
in that case.
2020-10-14 18:28:30 +02:00
Frantisek Sumsal
d7a0f1f4f9 tree-wide: assorted coccinelle fixes 2020-10-09 15:02:23 +02:00
Lennart Poettering
89e62e0bd3 dissect: wrap verity settings in new VeritySettings structure
Just some refactoring: let's place the various verity related parameters
in a common structure, and pass that around instead of the individual
parameters.

Also, let's load the PKCS#7 signature data when finding metadata
right-away, instead of delaying this until we need it. In all cases we
call this there's not much time difference between the metdata finding
and the loading, hence this simplifies things and makes sure root hash
data and its signature is now always acquired together.
2020-09-17 20:36:23 +09:00