]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udevadm-hwdb.c
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / src / udev / udevadm-hwdb.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <getopt.h>
4
5 #include "hwdb-util.h"
6 #include "udevadm.h"
7
8 static const char *arg_test = NULL;
9 static const char *arg_root = NULL;
10 static const char *arg_hwdb_bin_dir = NULL;
11 static bool arg_update = false;
12 static bool arg_strict = false;
13
14 static int help(void) {
15 printf("%s hwdb [OPTIONS]\n\n"
16 " -h --help Print this message\n"
17 " -V --version Print version of the program\n"
18 " -u --update Update the hardware database\n"
19 " -s --strict When updating, return non-zero exit value on any parsing error\n"
20 " --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
21 " -t --test=MODALIAS Query database and print result\n"
22 " -r --root=PATH Alternative root path in the filesystem\n\n"
23 "NOTE:\n"
24 "The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
25 "Please use systemd-hwdb instead.\n",
26 program_invocation_short_name);
27
28 return 0;
29 }
30
31 static int parse_argv(int argc, char *argv[]) {
32 enum {
33 ARG_USR = 0x100,
34 };
35
36 static const struct option options[] = {
37 { "update", no_argument, NULL, 'u' },
38 { "usr", no_argument, NULL, ARG_USR },
39 { "strict", no_argument, NULL, 's' },
40 { "test", required_argument, NULL, 't' },
41 { "root", required_argument, NULL, 'r' },
42 { "version", no_argument, NULL, 'V' },
43 { "help", no_argument, NULL, 'h' },
44 {}
45 };
46
47 int c;
48
49 while ((c = getopt_long(argc, argv, "ust:r:Vh", options, NULL)) >= 0)
50 switch (c) {
51 case 'u':
52 arg_update = true;
53 break;
54 case ARG_USR:
55 arg_hwdb_bin_dir = UDEVLIBEXECDIR;
56 break;
57 case 's':
58 arg_strict = true;
59 break;
60 case 't':
61 arg_test = optarg;
62 break;
63 case 'r':
64 arg_root = optarg;
65 break;
66 case 'V':
67 return print_version();
68 case 'h':
69 return help();
70 case '?':
71 return -EINVAL;
72 default:
73 assert_not_reached();
74 }
75
76 return 1;
77 }
78
79 int hwdb_main(int argc, char *argv[], void *userdata) {
80 int r;
81
82 r = parse_argv(argc, argv);
83 if (r <= 0)
84 return r;
85
86 if (!arg_update && !arg_test)
87 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
88 "Either --update or --test must be used.");
89
90 log_notice("udevadm hwdb is deprecated. Use systemd-hwdb instead.");
91
92 if (arg_update && !hwdb_bypass()) {
93 r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true);
94 if (r < 0)
95 return r;
96 }
97
98 if (arg_test)
99 return hwdb_query(arg_test, NULL);
100
101 return 0;
102 }