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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux