hwdb,udevadm: also unify hwdb_query() and hwdb_test()
This commit is contained in:
parent
e3b9fd0a27
commit
d6609f8280
|
@ -7,7 +7,6 @@
|
|||
#include "alloc-util.h"
|
||||
#include "hwdb-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
#include "verbs.h"
|
||||
|
@ -17,24 +16,7 @@ static const char *arg_root = NULL;
|
|||
static bool arg_strict = false;
|
||||
|
||||
static int verb_query(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
const char *key, *value;
|
||||
const char *modalias;
|
||||
int r;
|
||||
|
||||
assert(argc >= 2);
|
||||
assert(argv);
|
||||
|
||||
modalias = argv[1];
|
||||
|
||||
r = sd_hwdb_new(&hwdb);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
SD_HWDB_FOREACH_PROPERTY(hwdb, modalias, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
|
||||
return 0;
|
||||
return hwdb_query(argv[1]);
|
||||
}
|
||||
|
||||
static int verb_update(int argc, char *argv[], void *userdata) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "conf-files.h"
|
||||
|
@ -659,3 +660,20 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
int hwdb_query(const char *modalias) {
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
const char *key, *value;
|
||||
int r;
|
||||
|
||||
assert(modalias);
|
||||
|
||||
r = sd_hwdb_new(&hwdb);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
SD_HWDB_FOREACH_PROPERTY(hwdb, modalias, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
|
||||
bool hwdb_validate(sd_hwdb *hwdb);
|
||||
int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool compat);
|
||||
int hwdb_query(const char *modalias);
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "sd-hwdb.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "hwdb-util.h"
|
||||
#include "string-util.h"
|
||||
#include "udevadm.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -16,21 +12,6 @@ static const char *arg_hwdb_bin_dir = NULL;
|
|||
static bool arg_update = false;
|
||||
static bool arg_strict = false;
|
||||
|
||||
static int hwdb_test(void) {
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
const char *key, *value;
|
||||
int r;
|
||||
|
||||
r = sd_hwdb_new(&hwdb);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
SD_HWDB_FOREACH_PROPERTY(hwdb, arg_test, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int help(void) {
|
||||
printf("%s hwdb [OPTIONS]\n\n"
|
||||
" -h --help Print this message\n"
|
||||
|
@ -117,7 +98,7 @@ int hwdb_main(int argc, char *argv[], void *userdata) {
|
|||
}
|
||||
|
||||
if (arg_test)
|
||||
return hwdb_test();
|
||||
return hwdb_query(arg_test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue