1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include "alloc-util.h"
8 #include "label-util.h"
10 #include "main-func.h"
11 #include "pretty-print.h"
14 static const char *arg_hwdb_bin_dir
= NULL
;
15 static const char *arg_root
= NULL
;
16 static bool arg_strict
= false;
18 static int verb_query(int argc
, char *argv
[], void *userdata
) {
19 return hwdb_query(argv
[1], arg_root
);
22 static int verb_update(int argc
, char *argv
[], void *userdata
) {
26 return hwdb_update(arg_root
, arg_hwdb_bin_dir
, arg_strict
, false);
29 static int help(void) {
30 _cleanup_free_
char *link
= NULL
;
33 r
= terminal_urlify_man("systemd-hwdb", "8", &link
);
37 printf("%s [OPTIONS...] COMMAND ...\n\n"
38 "%sUpdate or query the hardware database.%s\n"
40 " update Update the hwdb database\n"
41 " query MODALIAS Query database and print result\n"
43 " -h --help Show this help\n"
44 " --version Show package version\n"
45 " -s --strict When updating, return non-zero exit value on any parsing error\n"
46 " --usr Generate in " UDEVLIBEXECDIR
" instead of /etc/udev\n"
47 " -r --root=PATH Alternative root path in the filesystem\n"
48 "\nSee the %s for details.\n",
49 program_invocation_short_name
,
57 static int parse_argv(int argc
, char *argv
[]) {
63 static const struct option options
[] = {
64 { "help", no_argument
, NULL
, 'h' },
65 { "version", no_argument
, NULL
, ARG_VERSION
},
66 { "usr", no_argument
, NULL
, ARG_USR
},
67 { "strict", no_argument
, NULL
, 's' },
68 { "root", required_argument
, NULL
, 'r' },
77 while ((c
= getopt_long(argc
, argv
, "sr:h", options
, NULL
)) >= 0)
87 arg_hwdb_bin_dir
= UDEVLIBEXECDIR
;
102 assert_not_reached();
108 static int hwdb_main(int argc
, char *argv
[]) {
109 static const Verb verbs
[] = {
110 { "update", 1, 1, 0, verb_update
},
111 { "query", 2, 2, 0, verb_query
},
115 return dispatch_verb(argc
, argv
, verbs
, NULL
);
118 static int run(int argc
, char *argv
[]) {
123 r
= parse_argv(argc
, argv
);
131 return hwdb_main(argc
, argv
);
134 DEFINE_MAIN_FUNCTION(run
);