1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "alloc-util.h"
10 #include "main-func.h"
11 #include "pretty-print.h"
12 #include "selinux-util.h"
13 #include "terminal-util.h"
16 static const char *arg_hwdb_bin_dir
= NULL
;
17 static const char *arg_root
= NULL
;
18 static bool arg_strict
= false;
20 static int verb_query(int argc
, char *argv
[], void *userdata
) {
21 return hwdb_query(argv
[1], arg_root
);
24 static int verb_update(int argc
, char *argv
[], void *userdata
) {
28 return hwdb_update(arg_root
, arg_hwdb_bin_dir
, arg_strict
, false);
31 static int help(void) {
32 _cleanup_free_
char *link
= NULL
;
35 r
= terminal_urlify_man("systemd-hwdb", "8", &link
);
39 printf("%s [OPTIONS...] COMMAND ...\n\n"
40 "%sUpdate or query the hardware database.%s\n"
42 " update Update the hwdb database\n"
43 " query MODALIAS Query database and print result\n"
45 " -h --help Show this help\n"
46 " --version Show package version\n"
47 " -s --strict When updating, return non-zero exit value on any parsing error\n"
48 " --usr Generate in " UDEVLIBEXECDIR
" instead of /etc/udev\n"
49 " -r --root=PATH Alternative root path in the filesystem\n"
50 "\nSee the %s for details.\n",
51 program_invocation_short_name
,
59 static int parse_argv(int argc
, char *argv
[]) {
65 static const struct option options
[] = {
66 { "help", no_argument
, NULL
, 'h' },
67 { "version", no_argument
, NULL
, ARG_VERSION
},
68 { "usr", no_argument
, NULL
, ARG_USR
},
69 { "strict", no_argument
, NULL
, 's' },
70 { "root", required_argument
, NULL
, 'r' },
79 while ((c
= getopt_long(argc
, argv
, "sr:h", options
, NULL
)) >= 0)
89 arg_hwdb_bin_dir
= UDEVLIBEXECDIR
;
104 assert_not_reached();
110 static int hwdb_main(int argc
, char *argv
[]) {
111 static const Verb verbs
[] = {
112 { "update", 1, 1, 0, verb_update
},
113 { "query", 2, 2, 0, verb_query
},
117 return dispatch_verb(argc
, argv
, verbs
, NULL
);
120 static int run(int argc
, char *argv
[]) {
123 log_parse_environment();
126 r
= parse_argv(argc
, argv
);
134 return hwdb_main(argc
, argv
);
137 DEFINE_MAIN_FUNCTION(run
);