[systemd-commits] 3 commits - src/libudev src/network src/shared src/udev
Tom Gundersen
tomegun at kemper.freedesktop.org
Mon Dec 15 11:40:40 PST 2014
src/libudev/libudev-hwdb.c | 7 -----
src/libudev/libudev-private.h | 3 --
src/network/networkctl.c | 52 +++++++++++++++++++++++-------------------
src/shared/udev-util.h | 2 -
src/udev/udev-builtin-hwdb.c | 38 ++++++++++++++++--------------
src/udev/udevadm-hwdb.c | 14 ++++++-----
6 files changed, 57 insertions(+), 59 deletions(-)
New commits:
commit c532d8a00cacacc6775effb7aadca680b1d39ccd
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Dec 15 19:58:25 2014 +0100
udev: builtin-hwdb - port to sd-hwdb
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c
index 2e198f2..98951fb 100644
--- a/src/libudev/libudev-hwdb.c
+++ b/src/libudev/libudev-hwdb.c
@@ -110,13 +110,6 @@ _public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) {
return NULL;
}
-bool udev_hwdb_validate(struct udev_hwdb *hwdb) {
- if (!hwdb)
- return false;
-
- return hwdb_validate(hwdb->hwdb);
-}
-
/**
* udev_hwdb_get_properties_list_entry:
* @hwdb: context
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
index 64f132f..d188bda 100644
--- a/src/libudev/libudev-private.h
+++ b/src/libudev/libudev-private.h
@@ -133,9 +133,6 @@ void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export);
int udev_queue_export_device_queued(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device);
int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device);
-/* libudev-hwdb.c */
-bool udev_hwdb_validate(struct udev_hwdb *hwdb);
-
/* libudev-util.c */
#define UTIL_PATH_SIZE 1024
#define UTIL_NAME_SIZE 512
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
index 5e0e1a9..5f09ce1 100644
--- a/src/shared/udev-util.h
+++ b/src/shared/udev-util.h
@@ -27,7 +27,6 @@
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_hwdb*, udev_hwdb_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_event*, udev_event_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_rules*, udev_rules_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl*, udev_ctrl_unref);
@@ -36,7 +35,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
#define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
#define _cleanup_udev_device_unref_ _cleanup_(udev_device_unrefp)
#define _cleanup_udev_enumerate_unref_ _cleanup_(udev_enumerate_unrefp)
-#define _cleanup_udev_hwdb_unref_ _cleanup_(udev_hwdb_unrefp)
#define _cleanup_udev_event_unref_ _cleanup_(udev_event_unrefp)
#define _cleanup_udev_rules_unref_ _cleanup_(udev_rules_unrefp)
#define _cleanup_udev_ctrl_unref_ _cleanup_(udev_ctrl_unrefp)
diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c
index 695a31a..e8301c6 100644
--- a/src/udev/udev-builtin-hwdb.c
+++ b/src/udev/udev-builtin-hwdb.c
@@ -27,36 +27,34 @@
#include <getopt.h>
#include "udev.h"
+#include "sd-hwdb.h"
-static struct udev_hwdb *hwdb;
+#include "hwdb-util.h"
+
+static sd_hwdb *hwdb;
int udev_builtin_hwdb_lookup(struct udev_device *dev,
const char *prefix, const char *modalias,
const char *filter, bool test) {
- struct udev_list_entry *list;
- struct udev_list_entry *entry;
+ _cleanup_free_ const char *lookup = NULL;
+ const char *key, *value;
int n = 0;
if (!hwdb)
return -ENOENT;
if (prefix) {
- _cleanup_free_ const char *lookup;
-
lookup = strjoin(prefix, modalias, NULL);
if (!lookup)
return -ENOMEM;
- list = udev_hwdb_get_properties_list_entry(hwdb, lookup, 0);
- } else
- list = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0);
+ modalias = lookup;
+ }
- udev_list_entry_foreach(entry, list) {
- if (filter && fnmatch(filter, udev_list_entry_get_name(entry), FNM_NOESCAPE) != 0)
+ SD_HWDB_FOREACH_PROPERTY(hwdb, modalias, key, value) {
+ if (filter && fnmatch(filter, key, FNM_NOESCAPE) != 0)
continue;
- if (udev_builtin_add_property(dev, test,
- udev_list_entry_get_name(entry),
- udev_list_entry_get_value(entry)) < 0)
+ if (udev_builtin_add_property(dev, test, key, value) < 0)
return -ENOMEM;
n++;
}
@@ -190,22 +188,26 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te
/* called at udev startup and reload */
static int builtin_hwdb_init(struct udev *udev) {
+ int r;
+
if (hwdb)
return 0;
- hwdb = udev_hwdb_new(udev);
- if (!hwdb)
- return -ENOMEM;
+
+ r = sd_hwdb_new(&hwdb);
+ if (r < 0)
+ return r;
+
return 0;
}
/* called on udev shutdown and reload request */
static void builtin_hwdb_exit(struct udev *udev) {
- hwdb = udev_hwdb_unref(hwdb);
+ hwdb = sd_hwdb_unref(hwdb);
}
/* called every couple of seconds during event activity; 'true' if config has changed */
static bool builtin_hwdb_validate(struct udev *udev) {
- return udev_hwdb_validate(hwdb);
+ return hwdb_validate(hwdb);
}
const struct udev_builtin udev_builtin_hwdb = {
commit d640c07d97eb19003226257b703eaa6cf1cbb4cf
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Dec 15 19:48:21 2014 +0100
udevadm: port to sd-hwdb
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index afd9f5a..eb300ff 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -29,6 +29,7 @@
#include "udev.h"
#include "hwdb-internal.h"
+#include "hwdb-util.h"
/*
* Generic udev properties, key/value database based on modalias strings.
@@ -662,14 +663,15 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
}
if (test) {
- struct udev_hwdb *hwdb = udev_hwdb_new(udev);
+ _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
+ int r;
- if (hwdb) {
- struct udev_list_entry *entry;
+ r = sd_hwdb_new(&hwdb);
+ if (r >= 0) {
+ const char *key, *value;
- udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, test, 0))
- printf("%s=%s\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
- udev_hwdb_unref(hwdb);
+ SD_HWDB_FOREACH_PROPERTY(hwdb, test, key, value)
+ printf("%s=%s\n", key, value);
}
}
out:
commit 81fd1dd3a2cf4cc90a6898d562c9bb0fb238cbd7
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Dec 15 20:07:34 2014 +0100
networkctl: port from libudev to sd-hwdb
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index b56a728..f42bc62 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -25,13 +25,16 @@
#include "sd-network.h"
#include "sd-rtnl.h"
+#include "sd-hwdb.h"
#include "libudev.h"
+#include "strv.h"
#include "build.h"
#include "util.h"
#include "pager.h"
#include "rtnl-util.h"
#include "udev-util.h"
+#include "hwdb-util.h"
#include "arphrd-list.h"
#include "local-addresses.h"
#include "socket-util.h"
@@ -250,41 +253,45 @@ static int list_links(char **args, unsigned n) {
}
/* IEEE Organizationally Unique Identifier vendor string */
-static int ieee_oui(struct udev_hwdb *hwdb, struct ether_addr *mac, char **ret) {
- struct udev_list_entry *entry;
- char *description;
- char str[strlen("OUI:XXYYXXYYXXYY") + 1];
+static int ieee_oui(sd_hwdb *hwdb, struct ether_addr *mac, char **ret) {
+ const char *description;
+ char modalias[strlen("OUI:XXYYXXYYXXYY") + 1], *desc;
+ int r;
+
+ assert(ret);
if (!hwdb)
return -EINVAL;
+ if (!mac)
+ return -EINVAL;
+
/* skip commonly misused 00:00:00 (Xerox) prefix */
if (memcmp(mac, "\0\0\0", 3) == 0)
return -EINVAL;
- snprintf(str, sizeof(str), "OUI:" ETHER_ADDR_FORMAT_STR, ETHER_ADDR_FORMAT_VAL(*mac));
+ snprintf(modalias, sizeof(modalias), "OUI:" ETHER_ADDR_FORMAT_STR, ETHER_ADDR_FORMAT_VAL(*mac));
- udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, str, 0))
- if (strcmp(udev_list_entry_get_name(entry), "ID_OUI_FROM_DATABASE") == 0) {
- description = strdup(udev_list_entry_get_value(entry));
- if (!description)
- return -ENOMEM;
+ r = sd_hwdb_get(hwdb, modalias, "ID_OUI_FROM_DATABASE", &description);
+ if (r < 0)
+ return r;
- *ret = description;
- return 0;
- }
+ desc = strdup(description);
+ if (!desc)
+ return -ENOMEM;
- return -ENODATA;
+ *ret = desc;
+
+ return 0;
}
static int get_gateway_description(
sd_rtnl *rtnl,
- struct udev_hwdb *hwdb,
+ sd_hwdb *hwdb,
int ifindex,
int family,
union in_addr_union *gateway,
char **gateway_description) {
-
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
sd_rtnl_message *m;
int r;
@@ -386,10 +393,9 @@ static int get_gateway_description(
static int dump_gateways(
sd_rtnl *rtnl,
- struct udev_hwdb *hwdb,
+ sd_hwdb *hwdb,
const char *prefix,
int ifindex) {
-
_cleanup_free_ struct local_address *local = NULL;
int r, n, i;
@@ -488,7 +494,7 @@ static void dump_list(const char *prefix, char **l) {
static int link_status_one(
sd_rtnl *rtnl,
struct udev *udev,
- struct udev_hwdb *hwdb,
+ sd_hwdb *hwdb,
const char *name) {
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL;
@@ -648,7 +654,7 @@ static int link_status_one(
}
static int link_status(char **args, unsigned n) {
- _cleanup_udev_hwdb_unref_ struct udev_hwdb *hwdb = NULL;
+ _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
_cleanup_udev_unref_ struct udev *udev = NULL;
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
char **name;
@@ -662,9 +668,9 @@ static int link_status(char **args, unsigned n) {
if (!udev)
return log_error_errno(errno, "Failed to connect to udev: %m");
- hwdb = udev_hwdb_new(udev);
- if (!hwdb)
- log_debug_errno(errno, "Failed to open hardware database: %m");
+ r = sd_hwdb_new(&hwdb);
+ if (r < 0)
+ log_debug_errno(r, "Failed to open hardware database: %m");
if (n <= 1 && !arg_all) {
_cleanup_free_ char *operational_state = NULL;
More information about the systemd-commits
mailing list