mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
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:
parent
0fe384f38e
commit
39871fce1a
@ -122,22 +122,22 @@ VIR_LOG_INIT("libvirt");
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static virHypervisorDriverPtr virHypervisorDriverTab[MAX_DRIVERS];
|
static virHypervisorDriverPtr virHypervisorDriverTab[MAX_DRIVERS];
|
||||||
static int virHypervisorDriverTabCount = 0;
|
static int virHypervisorDriverTabCount;
|
||||||
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
||||||
static int virNetworkDriverTabCount = 0;
|
static int virNetworkDriverTabCount;
|
||||||
static virInterfaceDriverPtr virInterfaceDriverTab[MAX_DRIVERS];
|
static virInterfaceDriverPtr virInterfaceDriverTab[MAX_DRIVERS];
|
||||||
static int virInterfaceDriverTabCount = 0;
|
static int virInterfaceDriverTabCount;
|
||||||
static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
|
static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
|
||||||
static int virStorageDriverTabCount = 0;
|
static int virStorageDriverTabCount;
|
||||||
static virNodeDeviceDriverPtr virNodeDeviceDriverTab[MAX_DRIVERS];
|
static virNodeDeviceDriverPtr virNodeDeviceDriverTab[MAX_DRIVERS];
|
||||||
static int virNodeDeviceDriverTabCount = 0;
|
static int virNodeDeviceDriverTabCount;
|
||||||
static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS];
|
static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS];
|
||||||
static int virSecretDriverTabCount = 0;
|
static int virSecretDriverTabCount;
|
||||||
static virNWFilterDriverPtr virNWFilterDriverTab[MAX_DRIVERS];
|
static virNWFilterDriverPtr virNWFilterDriverTab[MAX_DRIVERS];
|
||||||
static int virNWFilterDriverTabCount = 0;
|
static int virNWFilterDriverTabCount;
|
||||||
#ifdef WITH_LIBVIRTD
|
#ifdef WITH_LIBVIRTD
|
||||||
static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
|
static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
|
||||||
static int virStateDriverTabCount = 0;
|
static int virStateDriverTabCount;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
|
|||||||
#endif /* WITH_GNUTLS_GCRYPT */
|
#endif /* WITH_GNUTLS_GCRYPT */
|
||||||
|
|
||||||
|
|
||||||
static bool virGlobalError = false;
|
static bool virGlobalError;
|
||||||
static virOnceControl virGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
|
static virOnceControl virGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
VIR_LOG_INIT("util.alloc");
|
VIR_LOG_INIT("util.alloc");
|
||||||
|
|
||||||
#if TEST_OOM
|
#if TEST_OOM
|
||||||
static int testMallocNext = 0;
|
static int testMallocNext;
|
||||||
static int testMallocFailFirst = 0;
|
static int testMallocFailFirst;
|
||||||
static int testMallocFailLast = 0;
|
static int testMallocFailLast;
|
||||||
static void (*testMallocHook)(int, void*) = NULL;
|
static void (*testMallocHook)(int, void*);
|
||||||
static void *testMallocHookData = NULL;
|
static void *testMallocHookData;
|
||||||
|
|
||||||
void virAllocTestInit(void)
|
void virAllocTestInit(void)
|
||||||
{
|
{
|
||||||
|
@ -35,8 +35,8 @@ VIR_LOG_INIT("util.dbus");
|
|||||||
#ifdef WITH_DBUS
|
#ifdef WITH_DBUS
|
||||||
|
|
||||||
static bool sharedBus = true;
|
static bool sharedBus = true;
|
||||||
static DBusConnection *systembus = NULL;
|
static DBusConnection *systembus;
|
||||||
static DBusConnection *sessionbus = NULL;
|
static DBusConnection *sessionbus;
|
||||||
static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
|
static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
|
||||||
static virOnceControl sessiononce = VIR_ONCE_CONTROL_INITIALIZER;
|
static virOnceControl sessiononce = VIR_ONCE_CONTROL_INITIALIZER;
|
||||||
static DBusError systemdbuserr;
|
static DBusError systemdbuserr;
|
||||||
|
@ -32,12 +32,12 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("util.event");
|
VIR_LOG_INIT("util.event");
|
||||||
|
|
||||||
static virEventAddHandleFunc addHandleImpl = NULL;
|
static virEventAddHandleFunc addHandleImpl;
|
||||||
static virEventUpdateHandleFunc updateHandleImpl = NULL;
|
static virEventUpdateHandleFunc updateHandleImpl;
|
||||||
static virEventRemoveHandleFunc removeHandleImpl = NULL;
|
static virEventRemoveHandleFunc removeHandleImpl;
|
||||||
static virEventAddTimeoutFunc addTimeoutImpl = NULL;
|
static virEventAddTimeoutFunc addTimeoutImpl;
|
||||||
static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
|
static virEventUpdateTimeoutFunc updateTimeoutImpl;
|
||||||
static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
|
static virEventRemoveTimeoutFunc removeTimeoutImpl;
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
@ -291,7 +291,7 @@ int virEventRegisterDefaultImpl(void)
|
|||||||
* function, as it will block forever if there are no
|
* function, as it will block forever if there are no
|
||||||
* registered events.
|
* registered events.
|
||||||
*
|
*
|
||||||
* static bool quit = false;
|
* static bool quit;
|
||||||
*
|
*
|
||||||
* while (!quit) {
|
* while (!quit) {
|
||||||
* if (virEventRunDefaultImpl() < 0)
|
* if (virEventRunDefaultImpl() < 0)
|
||||||
|
@ -1054,7 +1054,7 @@ safezero(int fd, off_t offset, off_t len)
|
|||||||
char *buf;
|
char *buf;
|
||||||
unsigned long long remain, bytes;
|
unsigned long long remain, bytes;
|
||||||
# ifdef HAVE_MMAP
|
# ifdef HAVE_MMAP
|
||||||
static long pagemask = 0;
|
static long pagemask;
|
||||||
off_t map_skip;
|
off_t map_skip;
|
||||||
|
|
||||||
/* align offset and length, rounding offset down and length up */
|
/* align offset and length, rounding offset down and length up */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virlog.c: internal logging and debugging
|
* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("util.log");
|
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}"
|
#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;
|
typedef virLogFilter *virLogFilterPtr;
|
||||||
|
|
||||||
static int virLogFiltersSerial = 1;
|
static int virLogFiltersSerial = 1;
|
||||||
static virLogFilterPtr virLogFilters = NULL;
|
static virLogFilterPtr virLogFilters;
|
||||||
static int virLogNbFilters = 0;
|
static int virLogNbFilters;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Outputs are used to emit the messages retained
|
* Outputs are used to emit the messages retained
|
||||||
@ -105,8 +105,8 @@ struct _virLogOutput {
|
|||||||
typedef struct _virLogOutput virLogOutput;
|
typedef struct _virLogOutput virLogOutput;
|
||||||
typedef virLogOutput *virLogOutputPtr;
|
typedef virLogOutput *virLogOutputPtr;
|
||||||
|
|
||||||
static virLogOutputPtr virLogOutputs = NULL;
|
static virLogOutputPtr virLogOutputs;
|
||||||
static int virLogNbOutputs = 0;
|
static int virLogNbOutputs;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default priorities
|
* Default priorities
|
||||||
@ -645,7 +645,7 @@ virLogStackTraceToFd(int fd)
|
|||||||
{
|
{
|
||||||
void *array[100];
|
void *array[100];
|
||||||
int size;
|
int size;
|
||||||
static bool doneWarning = false;
|
static bool doneWarning;
|
||||||
const char *msg = "Stack trace not available on this platform\n";
|
const char *msg = "Stack trace not available on this platform\n";
|
||||||
|
|
||||||
#define STRIP_DEPTH 3
|
#define STRIP_DEPTH 3
|
||||||
@ -782,7 +782,7 @@ virLogOutputToSyslog(virLogSourcePtr source ATTRIBUTE_UNUSED,
|
|||||||
syslog(virLogPrioritySyslog(priority), "%s", str);
|
syslog(virLogPrioritySyslog(priority), "%s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *current_ident = NULL;
|
static char *current_ident;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -103,7 +103,7 @@ static int nextWatch = 1;
|
|||||||
/* Linux kernel supports up to MAX_LINKS (32 at the time) individual
|
/* Linux kernel supports up to MAX_LINKS (32 at the time) individual
|
||||||
* netlink protocols. */
|
* netlink protocols. */
|
||||||
static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] = {NULL};
|
static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] = {NULL};
|
||||||
static virNetlinkHandle *placeholder_nlhandle = NULL;
|
static virNetlinkHandle *placeholder_nlhandle;
|
||||||
|
|
||||||
/* Function definitions */
|
/* Function definitions */
|
||||||
|
|
||||||
|
@ -916,11 +916,10 @@ int virProcessGetStartTime(pid_t pid,
|
|||||||
int virProcessGetStartTime(pid_t pid,
|
int virProcessGetStartTime(pid_t pid,
|
||||||
unsigned long long *timestamp)
|
unsigned long long *timestamp)
|
||||||
{
|
{
|
||||||
static int warned = 0;
|
static int warned;
|
||||||
if (virAtomicIntInc(&warned) == 1) {
|
if (virAtomicIntInc(&warned) == 1) {
|
||||||
VIR_WARN("Process start time of pid %llu not available on this platform",
|
VIR_WARN("Process start time of pid %llu not available on this platform",
|
||||||
(unsigned long long)pid);
|
(unsigned long long)pid);
|
||||||
warned = true;
|
|
||||||
}
|
}
|
||||||
*timestamp = 0;
|
*timestamp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virthread.h: basic thread synchronization primitives
|
* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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) \
|
# define VIR_ONCE_GLOBAL_INIT(classname) \
|
||||||
static virOnceControl classname ## OnceControl = VIR_ONCE_CONTROL_INITIALIZER; \
|
static virOnceControl classname ## OnceControl = VIR_ONCE_CONTROL_INITIALIZER; \
|
||||||
static virErrorPtr classname ## OnceError = NULL; \
|
static virErrorPtr classname ## OnceError; \
|
||||||
\
|
\
|
||||||
static void classname ## Once(void) \
|
static void classname ## Once(void) \
|
||||||
{ \
|
{ \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user