1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
10 #include "pretty-print.h"
11 #include "selinux-util.h"
15 static const char *arg_hwdb_bin_dir
= NULL
;
16 static const char *arg_root
= NULL
;
17 static bool arg_strict
= false;
19 static int verb_query(int argc
, char *argv
[], void *userdata
) {
20 return hwdb_query(argv
[1]);
23 static int verb_update(int argc
, char *argv
[], void *userdata
) {
24 return hwdb_update(arg_root
, arg_hwdb_bin_dir
, arg_strict
, false);
27 static int help(void) {
28 _cleanup_free_
char *link
= NULL
;
31 r
= terminal_urlify_man("systemd-hwdb", "8", &link
);
35 printf("%s OPTIONS COMMAND\n\n"
36 "Update or query the hardware database.\n\n"
37 " -h --help Show this help\n"
38 " --version Show package version\n"
39 " -s --strict When updating, return non-zero exit value on any parsing error\n"
40 " --usr Generate in " UDEVLIBEXECDIR
" instead of /etc/udev\n"
41 " -r --root=PATH Alternative root path in the filesystem\n\n"
43 " update Update the hwdb database\n"
44 " query MODALIAS Query database and print result\n"
45 "\nSee the %s for details.\n"
46 , program_invocation_short_name
53 static int parse_argv(int argc
, char *argv
[]) {
59 static const struct option options
[] = {
60 { "help", no_argument
, NULL
, 'h' },
61 { "version", no_argument
, NULL
, ARG_VERSION
},
62 { "usr", no_argument
, NULL
, ARG_USR
},
63 { "strict", no_argument
, NULL
, 's' },
64 { "root", required_argument
, NULL
, 'r' },
73 while ((c
= getopt_long(argc
, argv
, "ust:r:h", options
, NULL
)) >= 0)
83 arg_hwdb_bin_dir
= UDEVLIBEXECDIR
;
98 assert_not_reached("Unknown option");
104 static int hwdb_main(int argc
, char *argv
[]) {
105 static const Verb verbs
[] = {
106 { "update", 1, 1, 0, verb_update
},
107 { "query", 2, 2, 0, verb_query
},
111 return dispatch_verb(argc
, argv
, verbs
, NULL
);
114 static int run(int argc
, char *argv
[]) {
117 log_parse_environment();
120 r
= parse_argv(argc
, argv
);
126 return hwdb_main(argc
, argv
);
129 DEFINE_MAIN_FUNCTION(run
);