Systemd/src/udev/udevadm-hwdb.c

102 lines
3.3 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: LGPL-2.1-or-later */
2012-10-22 18:23:08 +02:00
#include <getopt.h>
2014-12-15 19:48:21 +01:00
#include "hwdb-util.h"
#include "udevadm.h"
#include "util.h"
2012-10-22 18:23:08 +02:00
2018-08-21 04:28:26 +02:00
static const char *arg_test = NULL;
static const char *arg_root = NULL;
static const char *arg_hwdb_bin_dir = NULL;
2018-08-21 04:28:26 +02:00
static bool arg_update = false;
static bool arg_strict = false;
static int help(void) {
printf("%s hwdb [OPTIONS]\n\n"
" -h --help Print this message\n"
" -V --version Print version of the program\n"
" -u --update Update the hardware database\n"
" -s --strict When updating, return non-zero exit value on any parsing error\n"
" --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
" -t --test=MODALIAS Query database and print result\n"
" -r --root=PATH Alternative root path in the filesystem\n\n"
"NOTE:\n"
"The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
"Please use systemd-hwdb instead.\n"
, program_invocation_short_name);
2018-08-21 04:28:26 +02:00
return 0;
2012-10-22 18:23:08 +02:00
}
2018-08-21 04:28:26 +02:00
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_USR = 0x100,
};
2012-10-22 18:23:08 +02:00
static const struct option options[] = {
{ "update", no_argument, NULL, 'u' },
{ "usr", no_argument, NULL, ARG_USR },
{ "strict", no_argument, NULL, 's' },
{ "test", required_argument, NULL, 't' },
{ "root", required_argument, NULL, 'r' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
2012-10-22 18:23:08 +02:00
{}
};
2018-08-21 04:28:26 +02:00
int c;
2012-10-22 18:23:08 +02:00
while ((c = getopt_long(argc, argv, "ust:r:Vh", options, NULL)) >= 0)
switch(c) {
2012-10-22 18:23:08 +02:00
case 'u':
2018-08-21 04:28:26 +02:00
arg_update = true;
2012-10-22 18:23:08 +02:00
break;
case ARG_USR:
2018-08-21 04:28:26 +02:00
arg_hwdb_bin_dir = UDEVLIBEXECDIR;
break;
case 's':
2018-08-21 04:28:26 +02:00
arg_strict = true;
break;
case 't':
2018-08-21 04:28:26 +02:00
arg_test = optarg;
break;
case 'r':
2018-08-21 04:28:26 +02:00
arg_root = optarg;
break;
case 'V':
return print_version();
2012-10-22 18:23:08 +02:00
case 'h':
2018-08-21 04:28:26 +02:00
return help();
case '?':
2018-08-21 04:28:26 +02:00
return -EINVAL;
default:
assert_not_reached("Unknown option");
2012-10-22 18:23:08 +02:00
}
2018-08-21 04:28:26 +02:00
return 1;
}
2018-08-21 04:28:26 +02:00
int hwdb_main(int argc, char *argv[], void *userdata) {
int r;
2018-08-21 04:28:26 +02:00
r = parse_argv(argc, argv);
if (r <= 0)
2018-08-21 04:28:26 +02:00
return r;
if (!arg_update && !arg_test)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Either --update or --test must be used.");
2018-08-21 04:28:26 +02:00
if (arg_update) {
r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true);
2018-08-21 04:28:26 +02:00
if (r < 0)
return r;
}
2018-08-21 04:28:26 +02:00
if (arg_test)
return hwdb_query(arg_test);
2018-08-21 04:28:26 +02:00
return 0;
2012-10-22 18:23:08 +02:00
}