Commit Graph
678 Commits
Author SHA1 Message Date
Lennart Poettering 2c74a91cb8 sd-json: when parsing optionally insist top-level variant is object or array
Typically, the top-level JSON object has to be an object, in any json
document we parse, hence let's add a simple way to enforce that.

Make use of this in various places.

(Note, various other JSON parsers insist on this logic right from the
beginning, but I actually thinking making this insisting optional like
this patch does it is the cleaner approach)
2026-03-20 15:34:56 +01:00
Zbigniew Jędrzejewski-Szmek 31ddd87da0 tree-wide: extend verbs functions with extra per-verb data parameter
We often have a pattern where the same verb function is used for
multiple actions. This leads to an antipattern where we figure out what
action needs to be taken from argv[0] multiple times: often once in
parse_argv() to figure out what options are allowed, then once again
implicitly in dispatch_verb(), and then again in the action verb itself.
Let's allow passing a parameter into the verb to simplify this.

This matches a pattern we have in conf-parser.h, where we have both
void *userdata (more global) and void *data (per-config item). Here,
I opted for uintptr_t userdata. It seems that most of the time we'll
want to just pass an enum value. This works OK with no casts. I also
tried a void* and union. In both cases, much more boilerplate is needed:
either a cast or a macro to help avoid compiler warnings. uintptr_t
seems generic enough to cover foreseeable usecases with no fuss.

This is a noop refactoring. See next commit for an example.
2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek 5eccdf20ac pull: call all verb functions verb_* 2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek 095368238a import-fs: call all verb functions verb_* 2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek b2a55d2fb2 import: call all verb functions verb_* 2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek 8fb107aa99 export: call all verb functions verb_* 2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek 82ac3a24ee importctl: call all verb functions verb_* 2026-03-18 10:28:47 +00:00
Zbigniew Jędrzejewski-Szmek 4f0989d42d test-tar-extract: rename and add support for creating archives
This makes it much easier to test importd code without the
surrounding machinery.
2026-03-13 17:43:51 +00:00
Zbigniew Jędrzejewski-Szmek aa8cf865b9 test-tar-extract: fix error value in messages 2026-03-13 17:43:51 +00:00
Frantisek Sumsal 90f5d2a202 tree-wide: various fixlets suggested by Coccinelle 2026-03-05 10:27:58 +01:00
Frantisek Sumsal a8335fb91f tree-wide: use typed SD_JSON_BUILD_PAIR_* macros more 2026-03-05 10:27:58 +01:00
Mike Yuan 085f92730a tree-wide: use ALPHANUMERICAL where appropriate
Prompted by 43116c5662
2026-03-04 07:36:10 +09:00
Frantisek Sumsal 864c08f575 import,nspawn: fix a couple of typos in mountfsd 2026-03-03 00:03:19 +01:00
Weixie Cui 4980bd05b1 fix: check error with -ENOMEDIUM not ENOMEDIUM
Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
2026-03-01 10:24:45 +00:00
Antonio Alvarez Feijoo 8ea1ae25ab import/pull-oci: fix several OOM checks
Follow-up for a9f6ba0496
2026-02-24 17:34:09 +01:00
Yu Watanabe 298fc56641 import: fix NULL pointer dereference
Follow-up for a9f6ba0496.
Fixes CID#1645106.
2026-02-20 16:12:36 +09:00
Yu Watanabe 5d01b27ffc import: fix typo
Follow-up for a9f6ba0496.
2026-02-20 01:13:02 +09:00
Lennart Poettering 68ed4f3c66 mountfsd,nsresource: allow recycling mountfsd/nsresourced client connections
So far we opened a new Varlink connection for every mountfsd/nsresourced
method call. Given each tool only does a very small number of calls
(usually 1…5) on them and the connections are cheap this is not too
wasteful. Nonetheless, let's do something about it, and allow reusing
the connection for multiple calls.

This not only makes things a bit more efficient, but has one more
important benefit: Varlink connections pin the security context of the
client when connecting. This means that varlink method calls done with a
connection established while some code was privileged will still operate
as privieged once privs are dropped, until the connection is closed.
This pinning effect is really nice, as it gives us behaviour in a
"capability system" like scheme. Later code is going to use that to
continue doing certain priv userns ops even after unsharing userns and
becoming fully unpriv.
2026-02-19 15:08:19 +01:00
Lennart Poettering fbaf05bfeb importctl: add 'pull-oci' client API 2026-02-19 15:05:15 +01:00
Lennart Poettering 9628a5ced4 importd: add bus/varlink api for downloading OCIs 2026-02-19 15:05:15 +01:00
Lennart Poettering 116394f7ce tree-wide: move logging from varlink clients in nsresource.c/dissect-image.c into callers
These calls are "library-like", hence better should only debug log on
their own, not more.
2026-02-19 15:05:15 +01:00
Lennart Poettering a9f6ba0496 pull: add OCI support 2026-02-19 15:05:15 +01:00
Lennart Poettering d66e3cc79a pull-job: make sure pull_job_restart() can be used to fetch the same resource again, just with new headers
Let's flush out all response state from the job, but let's keep the
request data previously configured, in particular the headers set. This
is useful to re-request a resource, just with a slightly modified or
identical URL.
2026-02-19 15:05:15 +01:00
Lennart Poettering 93915ec17a pull-job: add helpers to detect requests for authentication, and accept bearer tokens 2026-02-19 15:05:14 +01:00
Lennart Poettering 1f593d2b5e pull-job: add 'description' field to PullJob
This is shown in the output in place of the URL if non-NULL. This is
useful for OCI's hash-based URLs, which alone are very opaque to read.
2026-02-19 15:05:14 +01:00
Lennart Poettering 98b714e0cb pull-job: optionally free userdata when we destroy a PullJob 2026-02-19 15:05:14 +01:00
Lennart Poettering 4a886d9ab4 pull-job: add interface for controlling Accept: header sent to http server 2026-02-19 15:05:14 +01:00
Lennart Poettering 41b0c68760 pull-job: keep track of content type reported by server 2026-02-19 15:05:14 +01:00
Mike Yuan 09388a6b9e tree-wide: drop redundant check for SD_VARLINK_METHOD_MORE flag
If the IDL declares the method requires 'more' yet the call doesn't
have it set, varlink_idl_validate_method_call() should have rejected
it and the callback shouldn't be reached.
2026-02-16 09:44:54 +01:00
Yu Watanabe da86da21e9 Fixes for option parsing (#40641)
Preparatory work split out of #40624.
2026-02-14 04:58:50 +09:00
DaanDeMeyer ba37ed9634 dissect: Introduce --copy-ownership= to configure chown behavior
Currently, if we're copying a file, we won't copy the owner UID/GID
from the source. If we're copying a directory, we will copy the owner
UID/GID from the source. Let's give users a bit more control over this
behavior by introducing --copy-ownership= which will default to the
current behavior but allows users to explicitly enable/disable copying
of ownership.
2026-02-12 09:45:13 +01:00
Daan De Meyer 4f5d44ef53 tree-wide: Migrate to varlink_set_sentinel() 2026-02-11 14:25:36 +01:00
Zbigniew Jędrzejewski-Szmek 84f6967558 importctl: fix confusion in --help
See parent commit for explanation.
2026-02-11 11:46:38 +01:00
Antonio Alvarez Feijoo 2f76b10b94 import-generator: fix sysext/confext ordering in initrd
In the initrd, order the generated `systemd-import@.service` units before the
initrd-specific sysext/confext units.
2026-02-03 08:18:41 +09:00
Daan De Meyer ec1ab07605 dissect-image: Generalize foreign tree logic from import 2026-01-21 12:03:07 +01:00
Yu Watanabe 776c3d7f90 import: update comment: implementor -> implementer
Both implementor and implementer are correct, but we use implementer at
other places.
2026-01-06 08:43:05 +09:00
Daan De Meyer ce2c72daa1 tree-wide: Migrate to pidref_safe_fork() (#40170) 2026-01-02 21:12:31 +01:00
Daan De Meyer 52ecf376fa tree-wide: Migrate to pidref_safe_fork()
Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
2026-01-02 20:08:41 +01:00
Daan De Meyer e6703a9aa4 process-util: Use ret as output parameter name
There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.
2026-01-02 19:44:18 +01:00
DaanDeMeyer 8b4278d12e pull-tar: Insist on foreign UID when copying
If we're doing foreign UID range copying, we're going to be joining
a private user namespace before doing the copy. copy_tree() insists
on keeping all UIDs/GIDs the same when copying. Hence, all the
UIDs/GIDs of the files we're copying should be in the private UID
range, which means they need to be owned by the foreign UID range
and we always need to call mountfsd_mount_directory_fd(). So there's
no point in having a fallback path if the source directory is not
foreign UID range owned, we'd simply fail to copy it later. Hence,
insist on the source directory being foreign UID range owned.
2026-01-02 15:21:53 +01:00
Daan De Meyer aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Lennart Poettering b7d1d17b9c dissect-image: teach mountfsd_make_directory() the new access mode parameter 2025-12-21 07:04:42 +01:00
Daan De Meyer 29d1df4b03 tree-wide: Remove unnecessary SIGCHLD blocking
Now that sd-event doesn't insist on blocking
SIGCHLD anymore when watching for process exit,
let's stop blocking SIGCHLD tree-wide where not
required anymore.
2025-12-20 15:50:47 +01:00
Daan De Meyer fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Zbigniew Jędrzejewski-Szmek 9e104bd3aa meson: put src/import source lists directly in templates
The indirection through variables doesn't seem that useful here:
OTOH, the lists are short, and OTOH, there is a bunch of different
programs with similar names. Overall, it's all easier to follow if
the lists are inline.
2025-12-19 13:12:35 +01:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De Meyer 1075316a4b machine: Fix hardcoded /var/lib/machines paths 2025-12-08 14:56:39 +01:00
q66 c39238bdc8 import: include unistd.h for pipe2
This is needed for e.g. pipe2 and unlinkat and a build failure
is reproducible when libarchive support is disabled.
2025-12-08 08:33:56 +09:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Yu Watanabe caf7cb2737 SD_JSON_BUILD_PAIR() conversions with coccinelle script (#39858) 2025-11-26 16:35:35 +09:00