1 /* SPDX-License-Identifier: GPL-2.0+ */
8 #include "selinux-util.h"
9 #include "string-util.h"
10 #include "terminal-util.h"
11 #include "udev-util.h"
14 static int adm_version(struct udev
*udev
, int argc
, char *argv
[]) {
15 printf("%s\n", PACKAGE_VERSION
);
19 static const struct udevadm_cmd udevadm_version
= {
24 static int adm_help(struct udev
*udev
, int argc
, char *argv
[]);
26 static const struct udevadm_cmd udevadm_help
= {
31 static const struct udevadm_cmd
*udevadm_cmds
[] = {
39 &udevadm_test_builtin
,
44 static int adm_help(struct udev
*udev
, int argc
, char *argv
[]) {
45 _cleanup_free_
char *link
= NULL
;
49 r
= terminal_urlify_man("udevadm", "8", &link
);
53 printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
54 "Send control commands or test the device manager.\n\n"
56 , program_invocation_short_name
);
58 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++)
59 if (udevadm_cmds
[i
]->help
!= NULL
)
60 printf(" %-12s %s\n", udevadm_cmds
[i
]->name
, udevadm_cmds
[i
]->help
);
62 printf("\nSee the %s for details.\n", link
);
66 static int run_command(struct udev
*udev
, const struct udevadm_cmd
*cmd
, int argc
, char *argv
[]) {
68 log_set_max_level(LOG_DEBUG
);
69 log_debug("calling: %s", cmd
->name
);
70 return cmd
->cmd(udev
, argc
, argv
);
73 int main(int argc
, char *argv
[]) {
75 static const struct option options
[] = {
76 { "debug", no_argument
, NULL
, 'd' },
77 { "help", no_argument
, NULL
, 'h' },
78 { "version", no_argument
, NULL
, 'V' },
86 log_parse_environment();
95 while ((c
= getopt_long(argc
, argv
, "+dhV", options
, NULL
)) >= 0)
99 log_set_max_level(LOG_DEBUG
);
103 rc
= adm_help(udev
, argc
, argv
);
107 rc
= adm_version(udev
, argc
, argv
);
114 command
= argv
[optind
];
117 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++)
118 if (streq(udevadm_cmds
[i
]->name
, command
)) {
121 /* we need '0' here to reset the internal state */
123 rc
= run_command(udev
, udevadm_cmds
[i
], argc
, argv
);
127 fprintf(stderr
, "%s: missing or unknown command\n", program_invocation_short_name
);
130 mac_selinux_finish();