[libvirt] [PATCH 09/16] util: Unify behaviour of the functions in sysfs.c

Martin Kletzander mkletzan at redhat.com
Thu Mar 30 14:03:41 UTC 2017


Make virSysfsGet*ValueString() functions use virSysfsGetValueString()
then we have one more allocation, but the code is cleaner and it's
easier to make sure the behaviour (e.g. return -2 on missing file)
isn't changed by mistake.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 src/util/virsysfs.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c
index 8d3665377e8c..a8550bbfbc26 100644
--- a/src/util/virsysfs.c
+++ b/src/util/virsysfs.c
@@ -178,19 +178,11 @@ virSysfsGetCpuValueString(unsigned int cpu,
     char *path = NULL;
     int ret = -1;

-    if (virAsprintf(&path, "%s/cpu/cpu%u/%s", sysfs_system_path, cpu, file) < 0)
+    if (virAsprintf(&path, "cpu/cpu%u/%s", cpu, file) < 0)
         return -1;

-    if (!virFileExists(path)) {
-        ret = -2;
-        goto cleanup;
-    }
+    ret = virSysfsGetValueString(path, value);

-    if (virFileReadAll(path, VIR_SYSFS_VALUE_MAXLEN, value) < 0)
-        goto cleanup;
-
-    ret = 0;
- cleanup:
     VIR_FREE(path);
     return ret;
 }
-- 
2.12.2




More information about the libvir-list mailing list