[netcf-devel] [PATCH] Don't return error if /sys/class/net/$dev/operstate isn't found
Laine Stump
laine at laine.org
Tue Jan 27 17:48:35 UTC 2015
This can happen for alias "interfaces", e.g: "eth0:1" (which aren't
really an interface, but are a deprecated method of adding multiple IP
addresses to a single interface). Since only the base interface
("eth0") is really a device, only it has an entry in /sys/class/net.
It's not important that such interfaces have truly meaningful
information in their <link> element (as we don't really have any truly
meaningful state, and haven't historically provided other status for
alias interfaces (e.g. IP address). What *is* important is that we
don't return an error, as this breaks applications that rely on being
able to get back a successful (if empty) status for any interface
listed.
This resolves the regression with virt-manager described here:
https://bugzilla.redhat.com/show_bug.cgi?id=1185850
---
src/dutil_linux.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 19e36ca..00c378f 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -1081,8 +1081,14 @@ static void add_link_info(struct netcf *ncf,
xasprintf(&path, "/sys/class/net/%s/operstate", ifname);
ERR_NOMEM(!path, ncf);
state = read_file(path, &length);
- ERR_THROW_STRERROR(!state, ncf, EFILE, "Failed to read %s : %s",
- path, errbuf);
+ if (!state) {
+ /* missing operstate is *not* an error. It could be due to an
+ * alias interface, which has not entry in /sys/class/net at
+ * all, for example.
+ */
+ state = strdup("");
+ ERR_NOMEM(!state, ncf);
+ }
if ((nl = strchr(state, '\n')))
*nl = 0;
prop = xmlSetProp(link_node, BAD_CAST "state", BAD_CAST state);
--
1.9.3
More information about the netcf-devel
mailing list