VIR_FREE(run_dir);
daemonConfigFree(config);
- virLogShutdown();
return ret;
}
#include "conf.h"
#include "rpc/virnettlscontext.h"
#include "command.h"
-#include "virnodesuspend.h"
#include "virrandom.h"
#include "viruri.h"
if (virThreadInitialize() < 0 ||
virErrorInitialize() < 0 ||
- virRandomInitialize(time(NULL) ^ getpid()) ||
- virNodeSuspendInit() < 0)
+ virRandomInitialize(time(NULL) ^ getpid()))
return -1;
gcry_control(GCRYCTL_SET_THREAD_CBS, &virTLSThreadImpl);
virLogSetBufferSize;
virLogSetDefaultPriority;
virLogSetFromEnv;
-virLogShutdown;
-virLogStartup;
virLogUnlock;
# virnodesuspend.h
nodeSuspendForDuration;
-virNodeSuspendInit;
virNodeSuspendGetTargetMask;
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) {
/*
return 0;
}
+VIR_ONCE_GLOBAL_INIT(virLog)
+
/**
* virLogSetBufferSize:
* @size: size of the buffer in kilobytes or <= 0 to deactivate
if (size < 0)
size = 0;
- if ((virLogInitialized == 0) || (size * 1024 == virLogSize))
+ if (virLogInitialize() < 0)
+ return -1;
+
+ if (size * 1024 == virLogSize)
return ret;
virLogLock();
* Returns 0 if successful, and -1 in case or error
*/
int virLogReset(void) {
- if (!virLogInitialized)
- return virLogStartup();
+ if (virLogInitialize() < 0)
+ return -1;
virLogLock();
virLogResetFilters();
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
VIR_WARN("Ignoring invalid log level setting.");
return -1;
}
- if (!virLogInitialized)
- virLogStartup();
+ if (virLogInitialize() < 0)
+ return -1;
+
virLogDefaultPriority = priority;
return 0;
}
int emit = 1;
unsigned int filterflags = 0;
- if (!virLogInitialized)
- virLogStartup();
+ if (virLogInitialize() < 0)
+ return;
if (fmt == NULL)
goto cleanup;
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);
}
-/**
- * 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:
virCheckFlags(0, -1);
+ if (virNodeSuspendInitialize() < 0)
+ return -1;
+
if (virNodeSuspendGetTargetMask(&supported) < 0)
return -1;
int status;
int ret = -1;
+ if (virNodeSuspendInitialize() < 0)
+ return -1;
+
*supported = false;
switch (target) {
unsigned long long duration,
unsigned int flags);
-int virNodeSuspendInit(void);
int virNodeSuspendGetTargetMask(unsigned int *bitmask);
#endif /* __VIR_NODE_SUSPEND_H__ */