2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2014-12-16 00:48:24 +01:00
|
|
|
|
|
|
|
#include <getopt.h>
|
2018-09-18 15:57:45 +02:00
|
|
|
|
|
|
|
#include "sd-hwdb.h"
|
2014-12-16 00:48:24 +01:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2014-12-16 00:48:24 +01:00
|
|
|
#include "hwdb-util.h"
|
2018-11-19 20:26:37 +01:00
|
|
|
#include "main-func.h"
|
2018-11-20 15:42:57 +01:00
|
|
|
#include "pretty-print.h"
|
2016-06-07 19:47:41 +02:00
|
|
|
#include "selinux-util.h"
|
2019-11-15 18:38:44 +01:00
|
|
|
#include "terminal-util.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "util.h"
|
|
|
|
#include "verbs.h"
|
2014-12-16 00:48:24 +01:00
|
|
|
|
2018-09-18 15:57:45 +02:00
|
|
|
static const char *arg_hwdb_bin_dir = NULL;
|
|
|
|
static const char *arg_root = NULL;
|
|
|
|
static bool arg_strict = false;
|
2014-12-16 00:48:24 +01:00
|
|
|
|
2018-09-18 15:57:45 +02:00
|
|
|
static int verb_query(int argc, char *argv[], void *userdata) {
|
2018-09-18 16:14:18 +02:00
|
|
|
return hwdb_query(argv[1]);
|
2014-12-16 00:48:24 +01:00
|
|
|
}
|
|
|
|
|
2018-09-18 15:57:45 +02:00
|
|
|
static int verb_update(int argc, char *argv[], void *userdata) {
|
|
|
|
return hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, false);
|
2014-12-16 00:48:24 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 10:32:31 +02:00
|
|
|
static int help(void) {
|
|
|
|
_cleanup_free_ char *link = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = terminal_urlify_man("systemd-hwdb", "8", &link);
|
|
|
|
if (r < 0)
|
|
|
|
return log_oom();
|
|
|
|
|
2019-11-15 18:38:44 +01:00
|
|
|
printf("%s [OPTIONS...] COMMAND ...\n\n"
|
|
|
|
"%sUpdate or query the hardware database.%s\n"
|
|
|
|
"\nCommands:\n"
|
|
|
|
" update Update the hwdb database\n"
|
|
|
|
" query MODALIAS Query database and print result\n"
|
|
|
|
"\nOptions:\n"
|
2018-04-24 12:11:10 +02:00
|
|
|
" -h --help Show this help\n"
|
|
|
|
" --version Show package version\n"
|
|
|
|
" -s --strict When updating, return non-zero exit value on any parsing error\n"
|
|
|
|
" --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
|
|
|
|
" -r --root=PATH Alternative root path in the filesystem\n\n"
|
2018-08-09 10:32:31 +02:00
|
|
|
"\nSee the %s for details.\n"
|
|
|
|
, program_invocation_short_name
|
2019-11-15 18:38:44 +01:00
|
|
|
, ansi_highlight()
|
|
|
|
, ansi_normal()
|
2018-08-09 10:32:31 +02:00
|
|
|
, link
|
|
|
|
);
|
|
|
|
|
|
|
|
return 0;
|
2014-12-16 00:48:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_argv(int argc, char *argv[]) {
|
|
|
|
enum {
|
2015-02-12 13:17:08 +01:00
|
|
|
ARG_VERSION = 0x100,
|
|
|
|
ARG_USR,
|
2014-12-16 00:48:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
2015-02-12 13:17:08 +01:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, ARG_VERSION },
|
|
|
|
{ "usr", no_argument, NULL, ARG_USR },
|
2018-03-27 05:24:01 +02:00
|
|
|
{ "strict", no_argument, NULL, 's' },
|
2015-02-12 13:17:08 +01:00
|
|
|
{ "root", required_argument, NULL, 'r' },
|
2014-12-16 00:48:24 +01:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
assert(argc >= 0);
|
|
|
|
assert(argv);
|
|
|
|
|
2018-09-18 15:57:45 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "ust:r:h", options, NULL)) >= 0)
|
2014-12-16 00:48:24 +01:00
|
|
|
switch(c) {
|
2015-02-12 13:17:08 +01:00
|
|
|
|
|
|
|
case 'h':
|
2018-08-09 10:32:31 +02:00
|
|
|
return help();
|
2015-02-12 13:17:08 +01:00
|
|
|
|
|
|
|
case ARG_VERSION:
|
2015-09-23 03:01:06 +02:00
|
|
|
return version();
|
2015-02-12 13:17:08 +01:00
|
|
|
|
2014-12-16 00:48:24 +01:00
|
|
|
case ARG_USR:
|
|
|
|
arg_hwdb_bin_dir = UDEVLIBEXECDIR;
|
|
|
|
break;
|
2015-02-12 13:17:08 +01:00
|
|
|
|
2018-03-27 05:24:01 +02:00
|
|
|
case 's':
|
|
|
|
arg_strict = true;
|
|
|
|
break;
|
|
|
|
|
2014-12-16 00:48:24 +01:00
|
|
|
case 'r':
|
|
|
|
arg_root = optarg;
|
|
|
|
break;
|
2015-02-12 13:17:08 +01:00
|
|
|
|
2014-12-16 00:48:24 +01:00
|
|
|
case '?':
|
|
|
|
return -EINVAL;
|
2015-02-12 13:17:08 +01:00
|
|
|
|
2014-12-16 00:48:24 +01:00
|
|
|
default:
|
|
|
|
assert_not_reached("Unknown option");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwdb_main(int argc, char *argv[]) {
|
2018-03-12 06:05:08 +01:00
|
|
|
static const Verb verbs[] = {
|
2018-09-18 15:57:45 +02:00
|
|
|
{ "update", 1, 1, 0, verb_update },
|
|
|
|
{ "query", 2, 2, 0, verb_query },
|
2014-12-19 03:01:27 +01:00
|
|
|
{},
|
2014-12-16 00:48:24 +01:00
|
|
|
};
|
|
|
|
|
2014-12-19 03:01:27 +01:00
|
|
|
return dispatch_verb(argc, argv, verbs, NULL);
|
2014-12-16 00:48:24 +01:00
|
|
|
}
|
|
|
|
|
2018-11-16 12:13:28 +01:00
|
|
|
static int run(int argc, char *argv[]) {
|
2014-12-16 00:48:24 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
log_parse_environment();
|
|
|
|
log_open();
|
|
|
|
|
|
|
|
r = parse_argv(argc, argv);
|
|
|
|
if (r <= 0)
|
2018-11-16 12:13:28 +01:00
|
|
|
return r;
|
2014-12-16 00:48:24 +01:00
|
|
|
|
2020-06-19 19:29:24 +02:00
|
|
|
r = mac_selinux_init();
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2016-06-07 19:47:41 +02:00
|
|
|
|
2018-11-16 12:13:28 +01:00
|
|
|
return hwdb_main(argc, argv);
|
2014-12-16 00:48:24 +01:00
|
|
|
}
|
2018-11-16 12:13:28 +01:00
|
|
|
|
|
|
|
DEFINE_MAIN_FUNCTION(run);
|