initialized = 1;
if (virThreadInitialize() < 0 ||
- virErrorInitialize() < 0 ||
- virRandomInitialize(time(NULL) ^ getpid()))
+ virErrorInitialize() < 0)
return -1;
gcry_control(GCRYCTL_SET_THREAD_CBS, &virTLSThreadImpl);
# virrandom.h
virRandomBits;
virRandomGenerateWWN;
-virRandomInitialize;
# virsocketaddr.h
/*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright IBM Corp. 2008
*
* lxc_controller.c: linux container process controller
if (setlocale(LC_ALL, "") == NULL ||
bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
- virRandomInitialize(time(NULL) ^ getpid())) {
+ textdomain(PACKAGE) == NULL) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
}
memset(ctl, 0, sizeof(vahControl));
- if (virRandomInitialize(time(NULL) ^ getpid()) < 0)
- vah_error(ctl, 1, _("could not initialize random generator"));
-
if (vahParseArgv(ctl, argc, argv) != 0)
vah_error(ctl, 1, _("could not parse arguments"));
/*
* iohelper.c: Helper program to perform I/O operations on files
*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
}
if (virThreadInitialize() < 0 ||
- virErrorInitialize() < 0 ||
- virRandomInitialize(time(NULL) ^ getpid())) {
+ virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), program_name);
exit(EXIT_FAILURE);
}
#include "count-one-bits.h"
#include "util.h"
#include "virterror_internal.h"
+#include "logging.h"
#define VIR_FROM_THIS VIR_FROM_NONE
static virMutex randomLock;
-int virRandomInitialize(uint32_t seed)
+static int
+virRandomOnceInit(void)
{
+ unsigned int seed = time(NULL) ^ getpid();
+
+#if 0
+ /* Normally we want a decent seed. But if reproducible debugging
+ * of a fixed pseudo-random sequence is ever required, uncomment
+ * this block to let an environment variable force the seed. */
+ const char *debug = getenv("VIR_DEBUG_RANDOM_SEED");
+
+ if (debug && virStrToLong_ui(debug, NULL, 0, &seed) < 0)
+ return -1;
+#endif
+
if (virMutexInit(&randomLock) < 0)
return -1;
return 0;
}
+VIR_ONCE_GLOBAL_INIT(virRandom)
+
/* The algorithm of virRandomBits requires that RAND_MAX == 2^n-1 for
* some n; gnulib's random_r meets this property. */
verify(((RAND_MAX + 1U) & RAND_MAX) == 0);
uint64_t ret = 0;
int32_t bits;
+ if (virRandomInitialize() < 0) {
+ /* You're already hosed, so this particular non-random value
+ * isn't any worse. */
+ VIR_WARN("random number generation is broken");
+ return 0;
+ }
+
virMutexLock(&randomLock);
while (nbits > bits_per_iter) {
# include "internal.h"
# include <stdint.h>
-int virRandomInitialize(uint32_t seed) ATTRIBUTE_RETURN_CHECK;
uint64_t virRandomBits(int nbits);
int virRandomGenerateWWN(char **wwn, const char *virt_type);
virSecurityManagerPtr mgr;
const char *doi, *model;
- if (virThreadInitialize() < 0 ||
- virRandomInitialize(time(NULL) ^ getpid()))
+ if (virThreadInitialize() < 0)
exit(EXIT_FAILURE);
mgr = virSecurityManagerNew(NULL, "QEMU", false, true, false);
fprintf(stderr, "TEST: %s\n", progname);
if (virThreadInitialize() < 0 ||
- virErrorInitialize() < 0 ||
- virRandomInitialize(time(NULL) ^ getpid()))
+ virErrorInitialize() < 0)
return 1;
virLogSetFromEnv();
{
int ret = 0;
- if (virRandomInitialize(time(NULL)) < 0)
- return -1;
if (virThreadInitialize() < 0)
return -1;