]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/udevadm.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / udev / udevadm.c
CommitLineData
e7145211 1/* SPDX-License-Identifier: GPL-2.0+ */
225cb03b 2
225cb03b
KS
3#include <errno.h>
4#include <getopt.h>
07630cea
LP
5#include <stddef.h>
6#include <stdio.h>
225cb03b 7
3d05193e 8#include "alloc-util.h"
138715dc 9#include "main-func.h"
294bf0c3 10#include "pretty-print.h"
d7b8eec7 11#include "selinux-util.h"
07630cea 12#include "string-util.h"
3d05193e 13#include "udevadm.h"
b237a168 14#include "udev-util.h"
3d05193e
YW
15#include "verbs.h"
16#include "util.h"
17
18static int help(void) {
19 static const char * short_descriptions[][2] = {
20 { "info", "Query sysfs or the udev database" },
21 { "trigger", "Request events from the kernel" },
22 { "settle", "Wait for pending udev events" },
23 { "control", "Control the udev daemon" },
24 { "monitor", "Listen to kernel and udev events" },
25 { "test", "Test an event run" },
26 { "test-builtin", "Test a built-in command" },
27 };
baa30fbc 28
37ec0fdd
LP
29 _cleanup_free_ char *link = NULL;
30 size_t i;
31 int r;
32
33 r = terminal_urlify_man("udevadm", "8", &link);
34 if (r < 0)
35 return log_oom();
912541b0 36
5ac0162c
LP
37 printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
38 "Send control commands or test the device manager.\n\n"
39 "Commands:\n"
40 , program_invocation_short_name);
41
3d05193e
YW
42 for (i = 0; i < ELEMENTSOF(short_descriptions); i++)
43 printf(" %-12s %s\n", short_descriptions[i][0], short_descriptions[i][1]);
37ec0fdd
LP
44
45 printf("\nSee the %s for details.\n", link);
912541b0 46 return 0;
225cb03b
KS
47}
48
3d05193e 49static int parse_argv(int argc, char *argv[]) {
912541b0 50 static const struct option options[] = {
3d05193e
YW
51 { "debug", no_argument, NULL, 'd' },
52 { "help", no_argument, NULL, 'h' },
912541b0
KS
53 { "version", no_argument, NULL, 'V' },
54 {}
55 };
3d05193e 56 int c;
b237a168 57
3d05193e
YW
58 assert(argc >= 0);
59 assert(argv);
912541b0 60
601185b4
ZJS
61 while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
62 switch (c) {
912541b0 63
912541b0 64 case 'd':
baa30fbc 65 log_set_max_level(LOG_DEBUG);
912541b0 66 break;
601185b4 67
912541b0 68 case 'h':
3d05193e 69 return help();
601185b4 70
912541b0 71 case 'V':
51b006e1 72 return print_version();
3d05193e
YW
73
74 case '?':
75 return -EINVAL;
601185b4 76
912541b0 77 default:
3d05193e 78 assert_not_reached("Unhandled option");
912541b0 79 }
601185b4 80
3d05193e
YW
81 return 1; /* work to do */
82}
83
84static int version_main(int argc, char *argv[], void *userdata) {
51b006e1 85 return print_version();
3d05193e
YW
86}
87
88static int help_main(int argc, char *argv[], void *userdata) {
89 return help();
90}
91
92static int udevadm_main(int argc, char *argv[]) {
93 static const Verb verbs[] = {
94 { "info", VERB_ANY, VERB_ANY, 0, info_main },
95 { "trigger", VERB_ANY, VERB_ANY, 0, trigger_main },
96 { "settle", VERB_ANY, VERB_ANY, 0, settle_main },
97 { "control", VERB_ANY, VERB_ANY, 0, control_main },
98 { "monitor", VERB_ANY, VERB_ANY, 0, monitor_main },
99 { "hwdb", VERB_ANY, VERB_ANY, 0, hwdb_main },
100 { "test", VERB_ANY, VERB_ANY, 0, test_main },
101 { "test-builtin", VERB_ANY, VERB_ANY, 0, builtin_main },
102 { "version", VERB_ANY, VERB_ANY, 0, version_main },
103 { "help", VERB_ANY, VERB_ANY, 0, help_main },
104 {}
105 };
106
107 return dispatch_verb(argc, argv, verbs, NULL);
108}
109
138715dc 110static int run(int argc, char *argv[]) {
3d05193e
YW
111 int r;
112
113 udev_parse_config();
114 log_parse_environment();
115 log_open();
3d05193e
YW
116
117 r = parse_argv(argc, argv);
118 if (r <= 0)
138715dc 119 return r;
3d05193e 120
b1d1cb5b
YW
121 log_set_max_level_realm(LOG_REALM_SYSTEMD, log_get_max_level());
122
138715dc
ZJS
123 mac_selinux_init();
124 return udevadm_main(argc, argv);
225cb03b 125}
138715dc
ZJS
126
127DEFINE_MAIN_FUNCTION(run);