]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Inline a sysconf call for linuxCPUStatsToBuf
authorJohn Ferlan <jferlan@redhat.com>
Thu, 27 Sep 2018 22:46:36 +0000 (18:46 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 1 Oct 2018 18:27:25 +0000 (14:27 -0400)
While unlikely, sysconf(_SC_CLK_TCK) could fail leading to
indeterminate results for the subsequent division. So let's
just remove the # define and inline the same change.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
tests/virhostcputest.c

index 8cbc302caeaf9d6dcb5e35c39200cdf3b5bf82e2..1df4bb8ee68490b4a35731d28591fc9439d8d25c 100644 (file)
@@ -72,7 +72,6 @@ linuxTestCompareFiles(const char *cpuinfofile,
     return ret;
 }
 
-# define TICK_TO_NSEC (1000ull * 1000ull * 1000ull / sysconf(_SC_CLK_TCK))
 
 static int
 linuxCPUStatsToBuf(virBufferPtr buf,
@@ -81,6 +80,15 @@ linuxCPUStatsToBuf(virBufferPtr buf,
                    size_t nparams)
 {
     size_t i = 0;
+    unsigned long long tick_to_nsec;
+    long long sc_clk_tck;
+
+    if ((sc_clk_tck = sysconf(_SC_CLK_TCK)) < 0) {
+        fprintf(stderr, "sysconf(_SC_CLK_TCK) fails : %s\n",
+                strerror(errno));
+        return -1;
+    }
+    tick_to_nsec = (1000ull * 1000ull * 1000ull) / sc_clk_tck;
 
     if (cpu < 0)
         virBufferAddLit(buf, "cpu:\n");
@@ -89,7 +97,7 @@ linuxCPUStatsToBuf(virBufferPtr buf,
 
     for (i = 0; i < nparams; i++)
         virBufferAsprintf(buf, "%s: %llu\n", param[i].field,
-                          param[i].value / TICK_TO_NSEC);
+                          param[i].value / tick_to_nsec);
 
     virBufferAddChar(buf, '\n');
     return 0;