1 /* SPDX-License-Identifier: GPL-2.0+ */
8 #include "alloc-util.h"
10 #include "pretty-print.h"
11 #include "selinux-util.h"
12 #include "string-util.h"
15 #include "udev-util.h"
19 static int help(void) {
20 static const char *const short_descriptions
[][2] = {
21 { "info", "Query sysfs or the udev database" },
22 { "trigger", "Request events from the kernel" },
23 { "settle", "Wait for pending udev events" },
24 { "control", "Control the udev daemon" },
25 { "monitor", "Listen to kernel and udev events" },
26 { "test", "Test an event run" },
27 { "test-builtin", "Test a built-in command" },
30 _cleanup_free_
char *link
= NULL
;
34 r
= terminal_urlify_man("udevadm", "8", &link
);
38 printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
39 "Send control commands or test the device manager.\n\n"
41 , program_invocation_short_name
);
43 for (i
= 0; i
< ELEMENTSOF(short_descriptions
); i
++)
44 printf(" %-12s %s\n", short_descriptions
[i
][0], short_descriptions
[i
][1]);
46 printf("\nSee the %s for details.\n", link
);
50 static int parse_argv(int argc
, char *argv
[]) {
51 static const struct option options
[] = {
52 { "debug", no_argument
, NULL
, 'd' },
53 { "help", no_argument
, NULL
, 'h' },
54 { "version", no_argument
, NULL
, 'V' },
62 while ((c
= getopt_long(argc
, argv
, "+dhV", options
, NULL
)) >= 0)
66 log_set_max_level(LOG_DEBUG
);
73 return print_version();
79 assert_not_reached("Unhandled option");
82 return 1; /* work to do */
85 static int version_main(int argc
, char *argv
[], void *userdata
) {
86 return print_version();
89 static int help_main(int argc
, char *argv
[], void *userdata
) {
93 static int udevadm_main(int argc
, char *argv
[]) {
94 static const Verb verbs
[] = {
95 { "info", VERB_ANY
, VERB_ANY
, 0, info_main
},
96 { "trigger", VERB_ANY
, VERB_ANY
, 0, trigger_main
},
97 { "settle", VERB_ANY
, VERB_ANY
, 0, settle_main
},
98 { "control", VERB_ANY
, VERB_ANY
, 0, control_main
},
99 { "monitor", VERB_ANY
, VERB_ANY
, 0, monitor_main
},
100 { "hwdb", VERB_ANY
, VERB_ANY
, 0, hwdb_main
},
101 { "test", VERB_ANY
, VERB_ANY
, 0, test_main
},
102 { "test-builtin", VERB_ANY
, VERB_ANY
, 0, builtin_main
},
103 { "version", VERB_ANY
, VERB_ANY
, 0, version_main
},
104 { "help", VERB_ANY
, VERB_ANY
, 0, help_main
},
108 return dispatch_verb(argc
, argv
, verbs
, NULL
);
111 static int run(int argc
, char *argv
[]) {
114 if (strstr(program_invocation_short_name
, "udevd"))
115 return run_udevd(argc
, argv
);
118 log_parse_environment();
121 r
= parse_argv(argc
, argv
);
125 log_set_max_level_realm(LOG_REALM_SYSTEMD
, log_get_max_level());
127 r
= mac_selinux_init();
131 return udevadm_main(argc
, argv
);
134 DEFINE_MAIN_FUNCTION(run
);