Blob Blame History Raw
From 2e2fabd1acc704b938f7a0df1b091efd68d58072 Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@laine.org>
Date: Mon, 26 Jan 2015 16:22:35 -0500
Subject: [PATCH 1/2] Better messages on failure reading
 /sys/class/net/$dev/(operstate|speed)

add_link_info() sets an error message when it fails to read
/sys/class/net/$dev/operstate, but unfortunately frees the path string
just prior to setting the error message, so the error string has
"(null)" instead (thanks to glibc's asprintf noticing the null
pointer).

Additionally, the macro used to create the log message,
ERR_THROW_STRERROR() already turns errno into a string in the locally
defined errbuf, but we aren't including it in the format string, so it
doesn't get printed.

This patch makes sure the path isn't freed until it is really no
longer needed, and adds errbuf to the log message.

This will hopefully help to find the root cause of

  https://bugzilla.redhat.com/show_bug.cgi?id=1185850

(cherry picked from commit 60772fefee8eb6ef5d34ba8f0bc36d4ea7a6fc01)
---
 src/dutil_linux.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index d2bbef4..52a7299 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -1,7 +1,7 @@
 /*
  * dutil_linux.c: Linux utility functions for driver backends.
  *
- * Copyright (C) 2009-2012, 2014 Red Hat Inc.
+ * Copyright (C) 2009-2012, 2014-2015 Red Hat Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1040,14 +1040,15 @@ 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);
-    FREE(path);
-    ERR_THROW_STRERROR(!state, ncf, EFILE, "Failed to read %s", path);
+    ERR_THROW_STRERROR(!state, ncf, EFILE, "Failed to read %s : %s",
+                       path, errbuf);
     if ((nl = strchr(state, '\n')))
         *nl = 0;
     prop = xmlSetProp(link_node, BAD_CAST "state", BAD_CAST state);
     ERR_NOMEM(!prop, ncf);
 
     if (!strcmp(state, "up")) {
+        FREE(path);
         xasprintf(&path, "/sys/class/net/%s/speed", ifname);
         ERR_NOMEM(path == NULL, ncf);
         speed = read_file(path, &length);
@@ -1059,7 +1060,8 @@ static void add_link_info(struct netcf *ncf,
             speed = strdup("0");
             ERR_NOMEM(!speed, ncf);
         }
-        ERR_THROW_STRERROR(!speed, ncf, EFILE, "Failed to read %s", path);
+        ERR_THROW_STRERROR(!speed, ncf, EFILE, "Failed to read %s : %s",
+                           path, errbuf);
         if ((nl = strchr(speed, '\n')))
             *nl = 0;
     } else {
-- 
1.8.3.1