#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;
" -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,
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 */
}
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 },
{}
};
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();
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;