1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 static const char *arg_test
= NULL
;
10 static const char *arg_root
= NULL
;
11 static const char *arg_hwdb_bin_dir
= NULL
;
12 static bool arg_update
= false;
13 static bool arg_strict
= false;
15 static int help(void) {
16 printf("%s hwdb [OPTIONS]\n\n"
17 " -h --help Print this message\n"
18 " -V --version Print version of the program\n"
19 " -u --update Update the hardware database\n"
20 " -s --strict When updating, return non-zero exit value on any parsing error\n"
21 " --usr Generate in " UDEVLIBEXECDIR
" instead of /etc/udev\n"
22 " -t --test=MODALIAS Query database and print result\n"
23 " -r --root=PATH Alternative root path in the filesystem\n\n"
25 "The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
26 "Please use systemd-hwdb instead.\n",
27 program_invocation_short_name
);
32 static int parse_argv(int argc
, char *argv
[]) {
37 static const struct option options
[] = {
38 { "update", no_argument
, NULL
, 'u' },
39 { "usr", no_argument
, NULL
, ARG_USR
},
40 { "strict", no_argument
, NULL
, 's' },
41 { "test", required_argument
, NULL
, 't' },
42 { "root", required_argument
, NULL
, 'r' },
43 { "version", no_argument
, NULL
, 'V' },
44 { "help", no_argument
, NULL
, 'h' },
50 while ((c
= getopt_long(argc
, argv
, "ust:r:Vh", options
, NULL
)) >= 0)
56 arg_hwdb_bin_dir
= UDEVLIBEXECDIR
;
68 return print_version();
80 int hwdb_main(int argc
, char *argv
[], void *userdata
) {
83 r
= parse_argv(argc
, argv
);
87 if (!arg_update
&& !arg_test
)
88 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
89 "Either --update or --test must be used.");
92 r
= hwdb_update(arg_root
, arg_hwdb_bin_dir
, arg_strict
, true);
98 return hwdb_query(arg_test
, NULL
);