]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/service-util.c
core: Record ExecMainStartTimestamp before forking
[thirdparty/systemd.git] / src / shared / service-util.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
53f7f7fc
ZJS
2
3#include <getopt.h>
4#include <stdio.h>
5
6#include "alloc-util.h"
d6b4d1c7 7#include "build.h"
53f7f7fc
ZJS
8#include "pretty-print.h"
9#include "service-util.h"
10#include "terminal-util.h"
53f7f7fc 11
d4cc0edf 12static int help(const char *program_path, const char *service, const char *description, bool bus_introspect) {
53f7f7fc
ZJS
13 _cleanup_free_ char *link = NULL;
14 int r;
15
16 r = terminal_urlify_man(service, "8", &link);
17 if (r < 0)
18 return log_oom();
19
4313b991
AAF
20 printf("%1$s [OPTIONS...]\n"
21 "\n%5$s%7$s%6$s\n"
22 "\nThis program takes no positional arguments.\n"
23 "\n%3$sOptions:%4$s\n"
53f7f7fc
ZJS
24 " -h --help Show this help\n"
25 " --version Show package version\n"
4313b991
AAF
26 "%8$s"
27 "\nSee the %2$s for details.\n",
65064e2f 28 program_path,
4313b991 29 link,
65064e2f
AAF
30 ansi_underline(),
31 ansi_normal(),
4313b991
AAF
32 ansi_highlight(),
33 ansi_normal(),
34 description,
35 bus_introspect ? " --bus-introspect=PATH Write D-Bus XML introspection data\n" : "");
53f7f7fc
ZJS
36
37 return 0; /* No further action */
38}
39
40int service_parse_argv(
41 const char *service,
42 const char *description,
d4cc0edf 43 const BusObjectImplementation* const* bus_objects,
53f7f7fc
ZJS
44 int argc, char *argv[]) {
45
46 enum {
47 ARG_VERSION = 0x100,
d4cc0edf 48 ARG_BUS_INTROSPECT,
53f7f7fc
ZJS
49 };
50
51 static const struct option options[] = {
52 { "help", no_argument, NULL, 'h' },
53 { "version", no_argument, NULL, ARG_VERSION },
d4cc0edf 54 { "bus-introspect", required_argument, NULL, ARG_BUS_INTROSPECT },
53f7f7fc
ZJS
55 {}
56 };
57
58 int c;
59
60 assert(argc >= 0);
61 assert(argv);
62
63 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
79893116 64 switch (c) {
53f7f7fc
ZJS
65
66 case 'h':
d4cc0edf 67 return help(argv[0], service, description, bus_objects);
53f7f7fc
ZJS
68
69 case ARG_VERSION:
70 return version();
71
d4cc0edf
ZJS
72 case ARG_BUS_INTROSPECT:
73 return bus_introspect_implementations(
74 stdout,
75 optarg,
76 bus_objects);
77
53f7f7fc
ZJS
78 case '?':
79 return -EINVAL;
80
81 default:
04499a70 82 assert_not_reached();
53f7f7fc
ZJS
83 }
84
85 if (optind < argc)
86 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
87 "This program takes no arguments.");
88
89 return 1; /* Further action */
90}