maint: avoid static zero init in core files

C guarantees that static variables are zero-initialized.  Some older
compilers (and also gcc -fno-zero-initialized-in-bss) create larger
binaries if you explicitly zero-initialize a static variable.

* src/libvirt.c: Fix initialization.
* src/util/viralloc.c: Likewise.
* src/util/virdbus.c: Likewise.
* src/util/virevent.c: Likewise.
* src/util/virfile.c (safezero): Likewise.
* src/util/virlog.c: Likewise.
* src/util/virnetlink.c: Likewise.
* src/util/virthread.h (VIR_ONCE_GLOBAL_INIT): Likewise.
* src/util/virprocess.c (virProcessGetStartTime): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2014-10-28 12:38:04 -06:00
parent 0fe384f38e
commit 39871fce1a
9 changed files with 36 additions and 37 deletions

View File

@ -122,22 +122,22 @@ VIR_LOG_INIT("libvirt");
} while (0)
static virHypervisorDriverPtr virHypervisorDriverTab[MAX_DRIVERS];
static int virHypervisorDriverTabCount = 0;
static int virHypervisorDriverTabCount;
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
static int virNetworkDriverTabCount = 0;
static int virNetworkDriverTabCount;
static virInterfaceDriverPtr virInterfaceDriverTab[MAX_DRIVERS];
static int virInterfaceDriverTabCount = 0;
static int virInterfaceDriverTabCount;
static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
static int virStorageDriverTabCount = 0;
static int virStorageDriverTabCount;
static virNodeDeviceDriverPtr virNodeDeviceDriverTab[MAX_DRIVERS];
static int virNodeDeviceDriverTabCount = 0;
static int virNodeDeviceDriverTabCount;
static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS];
static int virSecretDriverTabCount = 0;
static int virSecretDriverTabCount;
static virNWFilterDriverPtr virNWFilterDriverTab[MAX_DRIVERS];
static int virNWFilterDriverTabCount = 0;
static int virNWFilterDriverTabCount;
#ifdef WITH_LIBVIRTD
static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
static int virStateDriverTabCount = 0;
static int virStateDriverTabCount;
#endif
@ -354,7 +354,7 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
#endif /* WITH_GNUTLS_GCRYPT */
static bool virGlobalError = false;
static bool virGlobalError;
static virOnceControl virGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
static void

View File

@ -32,11 +32,11 @@
VIR_LOG_INIT("util.alloc");
#if TEST_OOM
static int testMallocNext = 0;
static int testMallocFailFirst = 0;
static int testMallocFailLast = 0;
static void (*testMallocHook)(int, void*) = NULL;
static void *testMallocHookData = NULL;
static int testMallocNext;
static int testMallocFailFirst;
static int testMallocFailLast;
static void (*testMallocHook)(int, void*);
static void *testMallocHookData;
void virAllocTestInit(void)
{

View File

@ -35,8 +35,8 @@ VIR_LOG_INIT("util.dbus");
#ifdef WITH_DBUS
static bool sharedBus = true;
static DBusConnection *systembus = NULL;
static DBusConnection *sessionbus = NULL;
static DBusConnection *systembus;
static DBusConnection *sessionbus;
static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
static virOnceControl sessiononce = VIR_ONCE_CONTROL_INITIALIZER;
static DBusError systemdbuserr;

View File

@ -32,12 +32,12 @@
VIR_LOG_INIT("util.event");
static virEventAddHandleFunc addHandleImpl = NULL;
static virEventUpdateHandleFunc updateHandleImpl = NULL;
static virEventRemoveHandleFunc removeHandleImpl = NULL;
static virEventAddTimeoutFunc addTimeoutImpl = NULL;
static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
static virEventAddHandleFunc addHandleImpl;
static virEventUpdateHandleFunc updateHandleImpl;
static virEventRemoveHandleFunc removeHandleImpl;
static virEventAddTimeoutFunc addTimeoutImpl;
static virEventUpdateTimeoutFunc updateTimeoutImpl;
static virEventRemoveTimeoutFunc removeTimeoutImpl;
/*****************************************************
@ -291,7 +291,7 @@ int virEventRegisterDefaultImpl(void)
* function, as it will block forever if there are no
* registered events.
*
* static bool quit = false;
* static bool quit;
*
* while (!quit) {
* if (virEventRunDefaultImpl() < 0)

View File

@ -1054,7 +1054,7 @@ safezero(int fd, off_t offset, off_t len)
char *buf;
unsigned long long remain, bytes;
# ifdef HAVE_MMAP
static long pagemask = 0;
static long pagemask;
off_t map_skip;
/* align offset and length, rounding offset down and length up */

View File

@ -1,7 +1,7 @@
/*
* virlog.c: internal logging and debugging
*
* Copyright (C) 2008, 2010-2013 Red Hat, Inc.
* Copyright (C) 2008, 2010-2014 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
@ -61,7 +61,7 @@
VIR_LOG_INIT("util.log");
static regex_t *virLogRegex = NULL;
static regex_t *virLogRegex;
#define VIR_LOG_DATE_REGEX "[0-9]{4}-[0-9]{2}-[0-9]{2}"
@ -86,8 +86,8 @@ typedef struct _virLogFilter virLogFilter;
typedef virLogFilter *virLogFilterPtr;
static int virLogFiltersSerial = 1;
static virLogFilterPtr virLogFilters = NULL;
static int virLogNbFilters = 0;
static virLogFilterPtr virLogFilters;
static int virLogNbFilters;
/*
* Outputs are used to emit the messages retained
@ -105,8 +105,8 @@ struct _virLogOutput {
typedef struct _virLogOutput virLogOutput;
typedef virLogOutput *virLogOutputPtr;
static virLogOutputPtr virLogOutputs = NULL;
static int virLogNbOutputs = 0;
static virLogOutputPtr virLogOutputs;
static int virLogNbOutputs;
/*
* Default priorities
@ -645,7 +645,7 @@ virLogStackTraceToFd(int fd)
{
void *array[100];
int size;
static bool doneWarning = false;
static bool doneWarning;
const char *msg = "Stack trace not available on this platform\n";
#define STRIP_DEPTH 3
@ -782,7 +782,7 @@ virLogOutputToSyslog(virLogSourcePtr source ATTRIBUTE_UNUSED,
syslog(virLogPrioritySyslog(priority), "%s", str);
}
static char *current_ident = NULL;
static char *current_ident;
static void

View File

@ -103,7 +103,7 @@ static int nextWatch = 1;
/* Linux kernel supports up to MAX_LINKS (32 at the time) individual
* netlink protocols. */
static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] = {NULL};
static virNetlinkHandle *placeholder_nlhandle = NULL;
static virNetlinkHandle *placeholder_nlhandle;
/* Function definitions */

View File

@ -916,11 +916,10 @@ int virProcessGetStartTime(pid_t pid,
int virProcessGetStartTime(pid_t pid,
unsigned long long *timestamp)
{
static int warned = 0;
static int warned;
if (virAtomicIntInc(&warned) == 1) {
VIR_WARN("Process start time of pid %llu not available on this platform",
(unsigned long long)pid);
warned = true;
}
*timestamp = 0;
return 0;

View File

@ -1,7 +1,7 @@
/*
* virthread.h: basic thread synchronization primitives
*
* Copyright (C) 2009-2011, 2013 Red Hat, Inc.
* Copyright (C) 2009-2011, 2013-2014 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
@ -187,7 +187,7 @@ int virThreadLocalSet(virThreadLocalPtr l, void*) ATTRIBUTE_RETURN_CHECK;
*/
# define VIR_ONCE_GLOBAL_INIT(classname) \
static virOnceControl classname ## OnceControl = VIR_ONCE_CONTROL_INITIALIZER; \
static virErrorPtr classname ## OnceError = NULL; \
static virErrorPtr classname ## OnceError; \
\
static void classname ## Once(void) \
{ \