Commit graph

497 commits

Author SHA1 Message Date
Lennart Poettering 3b2e99ed8c importd: unify setup of bus connectivity in one place 2024-06-15 12:16:36 +01:00
Lennart Poettering 309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Yu Watanabe a07c903a38
Merge pull request #33071 from keszybz/sd_event_source-cleanup
Clean up calls to sd_event_source_set_enabled()
2024-06-12 18:42:14 +09:00
Lennart Poettering ec8bbd8adb tree-wide: never consider service idle if polkit authentication is still pending
Let's be correct on this.
2024-06-11 23:17:38 +01:00
Daan De Meyer af21385e76 importctl: Fix 0 flags argument in sd_bus_message_append() 2024-06-03 15:18:13 +09:00
Zbigniew Jędrzejewski-Szmek a3ada90a37 various: remove unnecessary check before sd_event_source_set_enabled()
sd_event_source_set_enabled() does the same check internally.
2024-05-30 12:11:58 +02:00
Lennart Poettering c5ecf09494 curl-glue: catch libcurl attempting to change timeout handler when we destroy a curl context on exit
If we destroy both an event loop and a curl contect object at the same
time, then we get into this weird situation where curl wants us to
reconfigure a timout event source right before destruction, which
sd-event will refuse however, since it is already being shutdown.

Hence, catch that and simply don't bother adjusting the timeout, since
we cannot get back from there anyway.
2024-05-14 05:29:15 +09:00
Antonio Alvarez Feijoo fb17510ede importctl: fix flag checking against wrong variable
Fixes 67c7ee11af
2024-05-02 13:58:20 +02:00
Frantisek Sumsal 6a68270c97 import: skip the whole subdir when building with -Dimportd=false
Resolves: #32501
2024-04-26 17:14:07 +02:00
Luca Boccassi 8707c9b244 gcrypt: dlopenify for libsystemd
gcrypt is used only for journal sealing operations in libsystemd, so it
can be made into a dlopen dependency that is used only on demand. This
allows to reduce the footprint of libsystemd in the most common cases.

Keep systemd-pull and systemd-resolved with normal linking, as they are
executables, and usually built with OpenSSL support anyway.
2024-04-03 11:50:25 +01:00
Lennart Poettering 9f65355b85 fd-util: beef up fd_verify_safe_flags() features
Let's make fd_verify_safe_flags() even more useful:

1. let's return the cleaned up flags (i.e. just the access mode) after
   validation, hiding all the noise, such as O_NOFOLLOW, O_LARGEFILE and
   similar.

2. let's add a "full" version of the call that allows passing additional
   flags that are OK to be set.
2024-03-11 14:49:51 +01:00
Lennart Poettering 5b7bfe0637 importd: add command to list downloaded images
It's a bit weird we allow importing/pulling/exporting images, but we
have no scheme for showing what#s already downloaded. Hence let's add
this, it's easy to add after all.
2024-03-01 22:25:42 +01:00
Lennart Poettering 5a985dd05a importd: pass log level to invoked child 2024-03-01 22:25:42 +01:00
Lennart Poettering ed459ec0c0 import: mention explicitly which image directory we operate on
Also, let's move the similar message about sync() mode to more common
code.
2024-03-01 22:25:42 +01:00
Lennart Poettering d304686ca3 import: downgrade HTTP error code log message levels
Let's downgrade log levels a bit on HTTP error codes. After all we
gracefully handle many of them, and we do generated an extra message for
the ones which are fatal anyway, hence there's no point in emphasizing
the HTTP erro message levels as we currently do.
2024-03-01 22:25:42 +01:00
Lennart Poettering 71cb203a6e importctl: draw a pretty progress bar while downloading
Everybody loves pretty terminal progress bar.
2024-03-01 22:25:42 +01:00
Lennart Poettering 1a176d5bb7 importd: log the import callout that is going to be called 2024-03-01 22:25:42 +01:00
Lennart Poettering b146afc449 importd: make keeping pristine copy of downloaded images optional
Previously, when downloading an image, importd would first download them
into one image which it would then consider immutable (named after the
originating URL/etag), and then immediately make a copy of it (named
after the client chosen name).

This makes some sense in VM/container cases where the images are
typically mutable, and thus the original downloaded copy is of some
value.

For sysexts/confexts/portable this doesn't make much sense though, as
they are typically immutable. Hence make the concept optional.

This adds --keep-download=yes/no as a new option that controls the
above. Moreover it disables the behaviour for all image classes but
"machine". The behaviour remains enabled for "machine", for compat.
2024-03-01 22:25:42 +01:00
Lennart Poettering 8f20b498bd importd: validate local image names with the right helper
A while back we introduced image_name_is_valid() for validating image
file names. It's more liberal than hostname_is_valid() in many ways (and
allows version suffixes and such). Since importd deals in offline images
(as opposed to machined otherwise which deals in running machines),
let's hence use the right helper to validate the identifiers.
2024-03-01 22:25:42 +01:00
Lennart Poettering 420b8ce798 importlisttransfersxclient 2024-03-01 22:25:42 +01:00
Lennart Poettering 67c7ee11af importctl: add support for selecting image class to download 2024-03-01 22:25:42 +01:00
Lennart Poettering c3c892b41f importd: tighten checks in fds passed to us 2024-03-01 22:25:42 +01:00
Lennart Poettering 7af5785d77 importd: add support for downloading sysext/confext/portable images too
This adds "Ex" versions of all bus calls import implements, that make
two changes:

1. A "class" parameter is added that allows choosing between
   machine/sysext/confext/portable images to download. Depending on the
   chose class the target directory is selected differently (i.e. not
   just /var/lib/machines/, but alternatively /var/lib/portables/,
   /var/lib/extensions/, /var/lib/confexts/.

2. The boolean flags are replaced by a 64bit flags parameter.
2024-03-01 22:25:42 +01:00
Lennart Poettering 83d7411209 import: merge PullFlags enum into ImportFlags
The two enums are mostly the same, the former is just an extension of
the latter. Let's merge them, to simplify things. This is particularly
useful as we then can reuse this systematically as D-Bus method call
flags too, in a generic fashion that works for both imports and pulls
the same.

Pretty much just renaming of flags.
2024-03-01 22:25:42 +01:00
Lennart Poettering 8229e226fe importctl: port tabular output for format-table.h APIs 2024-03-01 22:25:42 +01:00
Lennart Poettering 663a15e7cc importctl: modernize signal handling 2024-03-01 22:25:42 +01:00
Lennart Poettering 1db33ce50b importctl: add standalone client to importd
This is pretty much a 1:1 copy of the importd specific part of
machinectl.

We turn this into a separate tool, so that we can eventually make the
tool generic to also download other DDIs, not just machine images.
2024-03-01 22:25:42 +01:00
Lennart Poettering 423bba9926 importd: modernize signal handling a bit 2024-03-01 22:25:42 +01:00
Lennart Poettering b37ec1e7ca importd: trivial modernizations 2024-03-01 22:25:42 +01:00
Lennart Poettering 09232207b1 importd: switch to pidref 2024-03-01 22:25:42 +01:00
Lennart Poettering 8bd4d506a4 curl-util: fix downloads from file:// URLs
if we try to open file:// URLs that don't exist, we'll not get IO/timer
events about it, hence it is not sufficient to check for completion in
these events. Let's add a defer event, to deal with that.

Also, curl_multi_info_read() is a queue, make sure to handle all events
that might be queued.
2024-03-01 22:25:42 +01:00
Lennart Poettering db7136ec73 signal-util: imply sentinel -1 in sigprocmask_many() + sigset_add_many() args list 2024-02-23 09:35:12 -08:00
Lennart Poettering a0afd4e733 importd: port importd over to new invoke_callout_binary() API 2024-02-21 09:25:46 +01:00
Mike Yuan 2d70878162
tree-wide: replace FOREACH_POINTER with FOREACH_ARGUMENT
The latter is more generic and while being compatible with
the former.
2024-01-24 21:29:11 +08:00
Mike Yuan deb869970d
importd: use Type=notify 2024-01-09 21:57:45 +08:00
Mike Yuan bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Lennart Poettering 2a1ffd3e3a bus-polkit: port polkit_registry to use value destructors in hash_ops 2024-01-03 11:53:52 +01:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Lennart Poettering 7b36fb9f96 polkit: simplify bus_verify_polkit_async() + drop auth-by-cap dbus feature
This simplifies bus_verify_polkit_async() and related calls quite a bit:

1. This removes any support for authentication-by-Linux-capability. This
   is ultimately a kdbus leftover: with classic AF_UNIX transports we
   cannot authenticate by capabilities securely (because we cannot
   acquire it from the peer without races), hence we never actually did.
   Since the necessary kernel work didn't materialize in the last 10y,
   and is unlikely to be added, let's just kill this context. We cannot
   quite remove the caps stuff from sd-bus for API compat, but for our
   polkit logic let's kill it.

2. The "good_uid" and "interactive" params are only necessary in very
   few cases, hence let's move them to a new call
   bus_verify_polkit_async_full() and make bus_verify_polkit_async() a
   wrapper around it without those two parameters.

This also fixes a bunch of wrong uses of the "interactive" bool. The
bool makes no sense today as the ALLOW_INTERACTIVE_AUTHORIZATION field
in the D-Bus message header replaces it fully. We only need it to
implement method calls we introduced prior to that header field becoming
available in D-Bus. And it should only be used on such old method calls,
and otherwise always be set to false.

This does not change behaviour in any way. Just simplifies stuff.

Fixes: #21586
2023-12-22 05:27:36 +09:00
Frantisek Sumsal a986de6899 import: append % to X_IMPORT_PROGRESS=
Since we parse it on the other side via parse_percent() which requires
that, otherwise we get an error:

[    8.133131] testsuite-13.sh[649]: + machinectl import-raw /tmp/container.raw container-raw
[    8.175035] machinectl[1143]: Enqueued transfer job 1. Press C-c to continue download in background.
[    8.182130] machinectl[1143]: Importing '/tmp/container.raw', saving as 'container-raw'.
[    8.182377] systemd-importd[1144]: Got invalid percent value '0', ignoring.
[    8.182451] machinectl[1143]: Imported 0%.
[    8.282669] systemd-importd[1144]: Got invalid percent value '40', ignoring.
[    8.282746] machinectl[1143]: Imported 40%.
[    8.366448] machinectl[1143]: Wrote 64.0M.
[    8.366519] machinectl[1143]: Operation completed successfully.
[    8.366617] machinectl[1143]: Exiting.
2023-11-25 20:42:13 +01:00
Yu Watanabe 965040d811 test: always call test_setup_logging() 2023-11-18 03:04:27 +09:00
Lennart Poettering e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Yu Watanabe 86cbbc6d05 tree-wide: check if return value of lseek() and friends is negative
We usually check return value of syscalls or glibc functions by it is
negative or not, something like that `if (stat(path, &st) < 0)`.
Let's also use the same style for lseek() and friends even the type of
their return value is off_t.

Note, fseeko() returns int, instead of off_t.
2023-10-19 18:31:44 +09:00
Zbigniew Jędrzejewski-Szmek 4f9791a36c export: use highlighting in --help 2023-09-14 22:32:20 +02:00
Mike Yuan e22c60a9d5
io-util: introduce loop_write_full that takes a timeout
Also drop do_poll as the use case is covered
by timeout.
2023-09-07 20:30:44 +08:00
Daan De Meyer ad6fae7ffc copy: Add support for creating subvolumes to copy_tree_at()
The subvolumes set is a set of source inodes similar to how the
denylist hashmap contains source inodes as keys. It indicates
directories in the source tree that should become subvolumes in
the target tree.
2023-08-14 18:46:08 +02:00
Daan De Meyer e54c79ccc2 btrfs-util: Move subvolume creation to basic/btrfs.h
Also make btrfs_subvol_make() an openat style function.
2023-08-14 18:46:08 +02:00
Yu Watanabe 130c87b16a meson: merge declarations of normal and test executables 2023-08-03 20:37:16 +09:00
Yu Watanabe 19361deaea meson: move declarations of machined and friends 2023-08-01 15:54:45 +09:00