[libvirt] [PATCH v2 1/2] virhostuptime: Introduce virHostBootTimeInit()

Michal Privoznik mprivozn at redhat.com
Thu Dec 19 11:25:00 UTC 2019


The idea is to offer callers an init function that they can call
independently to ensure that the global variables get
initialized.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virhostuptime.c | 13 ++++++++++++-
 src/util/virhostuptime.h |  3 +++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a7b1ef23bc..257ce00615 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2194,6 +2194,7 @@ virHostMemSetParameters;
 
 
 # util/virhostuptime.h
+virHostBootTimeInit;
 virHostGetBootTime;
 
 
diff --git a/src/util/virhostuptime.c b/src/util/virhostuptime.c
index 8c49c3d40e..6c251c0d2d 100644
--- a/src/util/virhostuptime.c
+++ b/src/util/virhostuptime.c
@@ -126,7 +126,8 @@ virHostGetBootTimeOnceInit(void)
 int
 virHostGetBootTime(unsigned long long *when)
 {
-    if (virOnce(&virHostGetBootTimeOnce, virHostGetBootTimeOnceInit) < 0)
+    if (bootTime == 0 &&
+        virHostBootTimeInit() < 0)
         return -1;
 
     if (bootTimeErrno) {
@@ -137,3 +138,13 @@ virHostGetBootTime(unsigned long long *when)
     *when = bootTime;
     return 0;
 }
+
+
+int
+virHostBootTimeInit(void)
+{
+    if (virOnce(&virHostGetBootTimeOnce, virHostGetBootTimeOnceInit) < 0)
+        return -1;
+
+    return 0;
+}
diff --git a/src/util/virhostuptime.h b/src/util/virhostuptime.h
index 7e2c4c0c81..1ac638fd6e 100644
--- a/src/util/virhostuptime.h
+++ b/src/util/virhostuptime.h
@@ -25,3 +25,6 @@
 int
 virHostGetBootTime(unsigned long long *when)
     G_GNUC_NO_INLINE;
+
+int
+virHostBootTimeInit(void);
-- 
2.24.1




More information about the libvir-list mailing list