]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/verbs.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include "process-util.h"
13 #include "string-util.h"
17 /* Wraps running_in_chroot() which is used in various places, but also adds an environment variable check so external
18 * processes can reliably force this on.
20 bool running_in_chroot_or_offline(void) {
23 /* Added to support use cases like rpm-ostree, where from %post scripts we only want to execute "preset", but
24 * not "start"/"restart" for example.
26 * See docs/ENVIRONMENT.md for docs.
28 r
= getenv_bool("SYSTEMD_OFFLINE");
29 if (r
< 0 && r
!= -ENXIO
)
30 log_debug_errno(r
, "Failed to parse $SYSTEMD_OFFLINE: %m");
34 /* We've had this condition check for a long time which basically checks for legacy chroot case like Fedora's
35 * "mock", which is used for package builds. We don't want to try to start systemd services there, since
36 * without --new-chroot we don't even have systemd running, and even if we did, adding a concept of background
37 * daemons to builds would be an enormous change, requiring considering things like how the journal output is
38 * handled, etc. And there's really not a use case today for a build talking to a service.
40 * Note this call itself also looks for a different variable SYSTEMD_IGNORE_CHROOT=1.
42 r
= running_in_chroot();
44 log_debug_errno(r
, "running_in_chroot(): %m");
49 int dispatch_verb(int argc
, char *argv
[], const Verb verbs
[], void *userdata
) {
56 assert(verbs
[0].dispatch
);
59 assert(argc
>= optind
);
69 /* At the end of the list? */
70 if (!verbs
[i
].dispatch
) {
72 log_error("Unknown operation %s.", name
);
74 log_error("Requires operation parameter.");
79 found
= streq(name
, verbs
[i
].verb
);
81 found
= verbs
[i
].flags
& VERB_DEFAULT
;
94 if (verb
->min_args
!= VERB_ANY
&&
95 (unsigned) left
< verb
->min_args
)
96 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
97 "Too few arguments.");
99 if (verb
->max_args
!= VERB_ANY
&&
100 (unsigned) left
> verb
->max_args
)
101 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
102 "Too many arguments.");
104 if ((verb
->flags
& VERB_ONLINE_ONLY
) && running_in_chroot_or_offline()) {
106 log_info("Running in chroot, ignoring request: %s", name
);
108 log_info("Running in chroot, ignoring request.");
112 if (verb
->flags
& VERB_MUST_BE_ROOT
) {
119 return verb
->dispatch(left
, argv
, userdata
);
126 return verb
->dispatch(1, fake
, userdata
);