]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove manual one-shot global initializers
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 11 Jul 2012 13:35:42 +0000 (14:35 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 2 Aug 2012 10:50:46 +0000 (11:50 +0100)
Remove the use of a manually run virLogStartup and
virNodeSuspendInitialize methods. Instead make sure they
are automatically run using VIR_ONCE_GLOBAL_INIT

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
daemon/libvirtd.c
src/libvirt.c
src/libvirt_private.syms
src/util/logging.c
src/util/logging.h
src/util/virnodesuspend.c
src/util/virnodesuspend.h

index ffbe067b18620c0acfae6dae43141c5a3c1c86fa..ba0cc1f290faee5a129a387974349f56291aecf4 100644 (file)
@@ -1349,7 +1349,6 @@ cleanup:
     VIR_FREE(run_dir);
 
     daemonConfigFree(config);
-    virLogShutdown();
 
     return ret;
 }
index 37046331027f59a5c6956dacfcffeaa7a0ffc206..3c4bf8ca0c8cae76ee4c3472b45ee9c9e1f4abd7 100644 (file)
@@ -53,7 +53,6 @@
 #include "conf.h"
 #include "rpc/virnettlscontext.h"
 #include "command.h"
-#include "virnodesuspend.h"
 #include "virrandom.h"
 #include "viruri.h"
 
@@ -410,8 +409,7 @@ virInitialize(void)
 
     if (virThreadInitialize() < 0 ||
         virErrorInitialize() < 0 ||
-        virRandomInitialize(time(NULL) ^ getpid()) ||
-        virNodeSuspendInit() < 0)
+        virRandomInitialize(time(NULL) ^ getpid()))
         return -1;
 
     gcry_control(GCRYCTL_SET_THREAD_CBS, &virTLSThreadImpl);
index bb8849b4d5348678353210db72a20102270a25bb..0b026b811e39cb3b5c585fa5622e850d04b589f2 100644 (file)
@@ -762,8 +762,6 @@ virLogReset;
 virLogSetBufferSize;
 virLogSetDefaultPriority;
 virLogSetFromEnv;
-virLogShutdown;
-virLogStartup;
 virLogUnlock;
 
 
@@ -1609,7 +1607,6 @@ virNetTLSSessionWrite;
 
 # virnodesuspend.h
 nodeSuspendForDuration;
-virNodeSuspendInit;
 virNodeSuspendGetTargetMask;
 
 
index 73e7eb6cd4fbaf2f697617ccb93b53bc29850920..a7f6b653ae3bea285f01406aba13cebe277071f2 100644 (file)
@@ -147,25 +147,14 @@ static const char *virLogPriorityString(virLogPriority lvl) {
     return "unknown";
 }
 
-static int virLogInitialized = 0;
 
-/**
- * virLogStartup:
- *
- * Initialize the logging module
- *
- * Returns 0 if successful, and -1 in case or error
- */
-int virLogStartup(void) {
+static int virLogOnceInit(void)
+{
     const char *pbm = NULL;
 
-    if (virLogInitialized)
-        return -1;
-
     if (virMutexInit(&virLogMutex) < 0)
         return -1;
 
-    virLogInitialized = 1;
     virLogLock();
     if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
         /*
@@ -191,6 +180,8 @@ int virLogStartup(void) {
     return 0;
 }
 
+VIR_ONCE_GLOBAL_INIT(virLog)
+
 /**
  * virLogSetBufferSize:
  * @size: size of the buffer in kilobytes or <= 0 to deactivate
@@ -211,7 +202,10 @@ virLogSetBufferSize(int size) {
     if (size < 0)
         size = 0;
 
-    if ((virLogInitialized == 0) || (size * 1024 == virLogSize))
+    if (virLogInitialize() < 0)
+        return -1;
+
+    if (size * 1024 == virLogSize)
         return ret;
 
     virLogLock();
@@ -253,8 +247,8 @@ error:
  * Returns 0 if successful, and -1 in case or error
  */
 int virLogReset(void) {
-    if (!virLogInitialized)
-        return virLogStartup();
+    if (virLogInitialize() < 0)
+        return -1;
 
     virLogLock();
     virLogResetFilters();
@@ -266,25 +260,6 @@ int virLogReset(void) {
     virLogUnlock();
     return 0;
 }
-/**
- * virLogShutdown:
- *
- * Shutdown the logging module
- */
-void virLogShutdown(void) {
-    if (!virLogInitialized)
-        return;
-    virLogLock();
-    virLogResetFilters();
-    virLogResetOutputs();
-    virLogLen = 0;
-    virLogStart = 0;
-    virLogEnd = 0;
-    VIR_FREE(virLogBuffer);
-    virLogUnlock();
-    virMutexDestroy(&virLogMutex);
-    virLogInitialized = 0;
-}
 
 /*
  * Store a string in the ring buffer
@@ -450,8 +425,9 @@ int virLogSetDefaultPriority(int priority) {
         VIR_WARN("Ignoring invalid log level setting.");
         return -1;
     }
-    if (!virLogInitialized)
-        virLogStartup();
+    if (virLogInitialize() < 0)
+        return -1;
+
     virLogDefaultPriority = priority;
     return 0;
 }
@@ -723,8 +699,8 @@ void virLogVMessage(const char *category, int priority, const char *funcname,
     int emit = 1;
     unsigned int filterflags = 0;
 
-    if (!virLogInitialized)
-        virLogStartup();
+    if (virLogInitialize() < 0)
+        return;
 
     if (fmt == NULL)
         goto cleanup;
index d2bedcf85f6c703f2b9bf912d7507e519b906dcc..137bad2b5634d40bda38ccf17a2d74eb434df1e1 100644 (file)
@@ -135,9 +135,7 @@ extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data,
 
 extern void virLogLock(void);
 extern void virLogUnlock(void);
-extern int virLogStartup(void);
 extern int virLogReset(void);
-extern void virLogShutdown(void);
 extern int virLogParseDefaultPriority(const char *priority);
 extern int virLogParseFilters(const char *filters);
 extern int virLogParseOutputs(const char *output);
index 91dfdf6355d0b188da034c599ea3b58e4980a4d0..914ce56af06a7c297a546b516bffb8434aa4e9b0 100644 (file)
@@ -59,24 +59,19 @@ static void virNodeSuspendUnlock(void)
 }
 
 
-/**
- * virNodeSuspendInit:
- *
- * Get the system-wide sleep states supported by the host, such as
- * Suspend-to-RAM, Suspend-to-Disk, or Hybrid-Suspend, so that a request
- * to suspend/hibernate the host can be handled appropriately based on
- * this information.
- *
- * Returns 0 if successful, and -1 in case of error.
- */
-int virNodeSuspendInit(void)
+static int virNodeSuspendOnceInit(void)
 {
-    if (virMutexInit(&virNodeSuspendMutex) < 0)
+    if (virMutexInit(&virNodeSuspendMutex) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to initialize mutex"));
         return -1;
+    }
 
     return 0;
 }
 
+VIR_ONCE_GLOBAL_INIT(virNodeSuspend)
+
 
 /**
  * virNodeSuspendSetNodeWakeup:
@@ -182,6 +177,9 @@ int nodeSuspendForDuration(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     virCheckFlags(0, -1);
 
+    if (virNodeSuspendInitialize() < 0)
+        return -1;
+
     if (virNodeSuspendGetTargetMask(&supported) < 0)
         return -1;
 
@@ -268,6 +266,9 @@ virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
     int status;
     int ret = -1;
 
+    if (virNodeSuspendInitialize() < 0)
+        return -1;
+
     *supported = false;
 
     switch (target) {
index a6927acf132f73669a91d3ffa2f441e9d3979e18..76497d8e69b99b12e994deb037f2770e49972e50 100644 (file)
@@ -30,7 +30,6 @@ int nodeSuspendForDuration(virConnectPtr conn,
                            unsigned long long duration,
                            unsigned int flags);
 
-int virNodeSuspendInit(void);
 int virNodeSuspendGetTargetMask(unsigned int *bitmask);
 
 #endif /* __VIR_NODE_SUSPEND_H__ */