[netcf-devel] [PATCH 3/7] Add strlower, update dutil_linux.c:aug_match_mac
David Lutterkort
lutter at redhat.com
Wed Jul 29 16:33:11 UTC 2009
On Wed, 2009-07-29 at 10:55 +0000, David Lutterkort wrote:
> On Thu, 2009-07-23 at 14:37 +0200, Jonas Eriksson wrote:
> > dutil.{c,h}:
> > - Added strllower
> >
> > dutil_linux.{c,h}:
> > - Made use of strllower and aug_fmt_match in aug_match_mac
>
> Heh, I just broke that with the patch I committed. I'll rebase this and
> the following patches so that the patch series still applies.
As we discussed on IRC, here's a remodeled patch; since I already
addressed all-lower case MAC addresses, I removed strllower from your
patch.
Ok to commit ?
David
>From 269f944fb52aa77731657c7d7c97cd107cb09ab4 Mon Sep 17 00:00:00 2001
From: Jonas Eriksson <jonas.j.eriksson at ericsson.com>
Date: Thu, 23 Jul 2009 14:37:04 +0200
Subject: [PATCH] Several minor cleanup changes
* src/dutil_linux.c (aug_match_mac): use aug_fmt_match; fix a typo in the
comment above the function head and prototype
* src/drv_initscruots.c (drv_list_interfaces); reformat header
* src/drv_initscruots.c (drv_lookup_by_mac_string): use ERR_BAIL
to handle error from aug_match_mac
---
src/drv_initscripts.c | 5 +++--
src/dutil_linux.c | 19 +++++--------------
src/dutil_linux.h | 2 +-
3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 0c69071..550df65 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -344,7 +344,8 @@ static int list_interface_ids(struct netcf *ncf,
return -1;
}
-int drv_list_interfaces(struct netcf *ncf, int maxnames, char **names, unsigned int flags) {
+int drv_list_interfaces(struct netcf *ncf, int maxnames, char **names,
+ unsigned int flags) {
return list_interface_ids(ncf, maxnames, names, flags, "DEVICE");
}
@@ -677,7 +678,7 @@ int drv_lookup_by_mac_string(struct netcf *ncf, const char *mac,
ERR_BAIL(ncf);
nmatches = aug_match_mac(ncf, mac, &matches);
- ERR_THROW(nmatches < 0, ncf, EOTHER, "looking up %s failed", mac);
+ ERR_BAIL(ncf);
if (nmatches == 0) {
result = 0;
goto done;
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index cdb5915..864bced 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -40,29 +40,20 @@
#include "dutil.h"
#include "dutil_linux.h"
-/* Returns a list of all interfaces with MAC address INTF */
+/* Returns a list of all interfaces with MAC address MAC */
int aug_match_mac(struct netcf *ncf, const char *mac, char ***matches) {
- int r, nmatches;
- char *path, *mac_lower;
- struct augeas *aug = get_augeas(ncf);
+ int nmatches;
+ char *path = NULL, *mac_lower = NULL;
mac_lower = strdup(mac);
ERR_COND_BAIL(mac_lower == NULL, ncf, ENOMEM);
for (char *s = mac_lower; *s != '\0'; s++)
*s = c_tolower(*s);
- r = xasprintf(&path,
+ nmatches = aug_fmt_match(ncf, matches,
"/files/sys/class/net/*[address/content = '%s']", mac_lower);
- FREE(mac_lower);
- ERR_COND_BAIL(r < 0, ncf, ENOMEM);
-
- r = aug_match(aug, path, matches);
- /* Messages for a aug_match-fail are handled outside this function */
- if (r < 0)
- goto error;
+ ERR_BAIL(ncf);
- nmatches = r;
- r = -1;
for (int i = 0; i < nmatches; i++) {
char *n = strrchr((*matches)[i], '/');
ERR_THROW(n == NULL, ncf, EINTERNAL, "missing / in sysfs path");
diff --git a/src/dutil_linux.h b/src/dutil_linux.h
index 0351b8b..085c2f9 100644
--- a/src/dutil_linux.h
+++ b/src/dutil_linux.h
@@ -23,7 +23,7 @@
#ifndef DUTIL_LINUX_H_
#define DUTIL_LINUX_H_
-/* Returns a list of all interfaces with MAC address INTF */
+/* Returns a list of all interfaces with MAC address MAC */
int aug_match_mac(struct netcf *ncf, const char *mac, char ***matches);
/* Get the MAC address of the interface INTF */
--
1.6.0.6
More information about the netcf-devel
mailing list