diff --git a/src/home/homed.c b/src/home/homed.c index bb319925d0..9aaabd5c19 100644 --- a/src/home/homed.c +++ b/src/home/homed.c @@ -25,6 +25,7 @@ static int run(int argc, char *argv[]) { "A service to create, remove, change or inspect home areas.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 06fb3f2878..9ba3d312bd 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -1988,6 +1988,7 @@ static int run(int argc, char *argv[]) { "Manage the system hostname and related metadata.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/import/importd.c b/src/import/importd.c index f2715691ab..8603069047 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -2019,6 +2019,7 @@ static int run(int argc, char *argv[]) { "VM and container image import and export service.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/locale/localed.c b/src/locale/localed.c index 11d9130bbc..041ba29cd8 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -635,6 +635,7 @@ static int run(int argc, char *argv[]) { "Manage system locale settings and key mappings.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/login/logind.c b/src/login/logind.c index 9427bae815..e1219fe73a 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1340,6 +1340,7 @@ static int run(int argc, char *argv[]) { "Manager for user logins and devices and privileged operations.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/machine/machined.c b/src/machine/machined.c index 46395d7df4..ea83f97ad9 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -324,6 +324,7 @@ static int run(int argc, char *argv[]) { "Manage registrations of local VMs and containers.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/network/networkd.c b/src/network/networkd.c index 2ce32fe4f3..7e09629ddb 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -29,6 +29,7 @@ static int run(int argc, char *argv[]) { r = service_parse_argv("systemd-networkd.service", "Manage and configure network devices, create virtual network devices", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/portable/portabled.c b/src/portable/portabled.c index 65ceaf40b6..4059de01ed 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -133,6 +133,7 @@ static int run(int argc, char *argv[]) { "Manage registrations of portable images.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c index ea3e6a689c..aa165927a4 100644 --- a/src/resolve/resolved.c +++ b/src/resolve/resolved.c @@ -30,6 +30,7 @@ static int run(int argc, char *argv[]) { "Provide name resolution with caching using DNS, mDNS, LLMNR.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/shared/service-util.c b/src/shared/service-util.c index 2645fe2c40..70d59af6c5 100644 --- a/src/shared/service-util.c +++ b/src/shared/service-util.c @@ -8,9 +8,19 @@ #include "bus-object.h" #include "log.h" #include "pretty-print.h" +#include "runtime-scope.h" #include "service-util.h" -static int help(const char *program_path, const char *service, const char *description, bool bus_introspect) { +typedef enum HelpFlags { + HELP_WITH_BUS_INTROSPECT = 1 << 0, + HELP_WITH_RUNTIME_SCOPE = 1 << 1, +} HelpFlags; + +static int help(const char *program_path, + const char *service, + const char *description, + HelpFlags flags) { + _cleanup_free_ char *link = NULL; int r; @@ -25,6 +35,7 @@ static int help(const char *program_path, const char *service, const char *descr " -h --help Show this help\n" " --version Show package version\n" "%8$s" + "%9$s" "\nSee the %2$s for details.\n", program_path, link, @@ -33,7 +44,9 @@ static int help(const char *program_path, const char *service, const char *descr ansi_highlight(), ansi_normal(), description, - bus_introspect ? " --bus-introspect=PATH Write D-Bus XML introspection data\n" : ""); + FLAGS_SET(flags, HELP_WITH_BUS_INTROSPECT) ? " --bus-introspect=PATH Write D-Bus XML introspection data\n" : "", + FLAGS_SET(flags, HELP_WITH_RUNTIME_SCOPE) ? " --system Start service in system mode\n" + " --user Start service in user mode\n" : ""); return 0; /* No further action */ } @@ -42,17 +55,22 @@ int service_parse_argv( const char *service, const char *description, const BusObjectImplementation* const* bus_objects, + RuntimeScope *runtime_scope, int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_BUS_INTROSPECT, + ARG_SYSTEM, + ARG_USER, }; static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, { "bus-introspect", required_argument, NULL, ARG_BUS_INTROSPECT }, + { "system", no_argument, NULL, ARG_SYSTEM }, + { "user", no_argument, NULL, ARG_USER }, {} }; @@ -65,7 +83,11 @@ int service_parse_argv( switch (c) { case 'h': - return help(argv[0], service, description, bus_objects); + return help(argv[0], + service, + description, + (bus_objects ? HELP_WITH_BUS_INTROSPECT : 0) | + (runtime_scope ? HELP_WITH_RUNTIME_SCOPE : 0)); case ARG_VERSION: return version(); @@ -76,6 +98,14 @@ int service_parse_argv( optarg, bus_objects); + case ARG_SYSTEM: + case ARG_USER: + if (!runtime_scope) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This service cannot be run in --system or --user mode, refusing."); + + *runtime_scope = c == ARG_SYSTEM ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER; + break; + case '?': return -EINVAL; diff --git a/src/shared/service-util.h b/src/shared/service-util.h index af36354e80..462ba2b3fa 100644 --- a/src/shared/service-util.h +++ b/src/shared/service-util.h @@ -7,4 +7,5 @@ int service_parse_argv( const char *service, const char *description, const BusObjectImplementation* const* bus_objects, + RuntimeScope *runtime_scope, int argc, char *argv[]); diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index b1438ff825..1ade24b374 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -2079,6 +2079,7 @@ static int run(int argc, char *argv[]) { "System update management service.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 662cc29ac5..6e21d1a73a 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -1164,6 +1164,7 @@ static int run(int argc, char *argv[]) { "Manage the system clock and timezone and NTP enablement.", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r; diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 40305c046b..96d0dd5c2b 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -151,6 +151,7 @@ static int run(int argc, char *argv[]) { r = service_parse_argv("systemd-timesyncd.service", "Network time synchronization", BUS_IMPLEMENTATIONS(&manager_object, &log_control_object), + /* runtime_scope= */ NULL, argc, argv); if (r <= 0) return r;