1
0

Whitespace cleanup in logging files

General whitespace cleanup in the logging files

 - Move '{' to a new line after funtion declaration
 - Put each parameter on a new line to avoid long lines
 - Put return type on new line
 - Leave 2 blank lines between functions

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-09-27 14:14:01 +01:00
parent 4764a6c5a3
commit 96a1be95ef
2 changed files with 196 additions and 74 deletions

View File

@ -98,11 +98,14 @@ static virLogPriority virLogDefaultPriority = VIR_LOG_DEFAULT;
static int virLogResetFilters(void); static int virLogResetFilters(void);
static int virLogResetOutputs(void); static int virLogResetOutputs(void);
static void virLogOutputToFd(const char *category, virLogPriority priority, static void virLogOutputToFd(const char *category,
const char *funcname, int linenr, virLogPriority priority,
const char *funcname,
int linenr,
const char *timestamp, const char *timestamp,
unsigned int flags, unsigned int flags,
const char *rawstr, const char *str, const char *rawstr,
const char *str,
void *data); void *data);
/* /*
@ -110,16 +113,23 @@ static void virLogOutputToFd(const char *category, virLogPriority priority,
*/ */
virMutex virLogMutex; virMutex virLogMutex;
void virLogLock(void) void
virLogLock(void)
{ {
virMutexLock(&virLogMutex); virMutexLock(&virLogMutex);
} }
void virLogUnlock(void)
void
virLogUnlock(void)
{ {
virMutexUnlock(&virLogMutex); virMutexUnlock(&virLogMutex);
} }
static const char *virLogOutputString(virLogDestination ldest) {
static const char *
virLogOutputString(virLogDestination ldest)
{
switch (ldest) { switch (ldest) {
case VIR_LOG_TO_STDERR: case VIR_LOG_TO_STDERR:
return "stderr"; return "stderr";
@ -131,7 +141,10 @@ static const char *virLogOutputString(virLogDestination ldest) {
return "unknown"; return "unknown";
} }
static const char *virLogPriorityString(virLogPriority lvl) {
static const char *
virLogPriorityString(virLogPriority lvl)
{
switch (lvl) { switch (lvl) {
case VIR_LOG_DEBUG: case VIR_LOG_DEBUG:
return "debug"; return "debug";
@ -146,7 +159,8 @@ static const char *virLogPriorityString(virLogPriority lvl) {
} }
static int virLogOnceInit(void) static int
virLogOnceInit(void)
{ {
const char *pbm = NULL; const char *pbm = NULL;
@ -180,6 +194,7 @@ static int virLogOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virLog) VIR_ONCE_GLOBAL_INIT(virLog)
/** /**
* virLogSetBufferSize: * virLogSetBufferSize:
* @size: size of the buffer in kilobytes or <= 0 to deactivate * @size: size of the buffer in kilobytes or <= 0 to deactivate
@ -190,8 +205,9 @@ VIR_ONCE_GLOBAL_INIT(virLog)
* *
* Return -1 in case of failure or 0 in case of success * Return -1 in case of failure or 0 in case of success
*/ */
extern int int
virLogSetBufferSize(int size) { virLogSetBufferSize(int size)
{
int ret = 0; int ret = 0;
int oldsize; int oldsize;
char *oldLogBuffer; char *oldLogBuffer;
@ -237,6 +253,7 @@ error:
return ret; return ret;
} }
/** /**
* virLogReset: * virLogReset:
* *
@ -244,7 +261,9 @@ error:
* *
* Returns 0 if successful, and -1 in case or error * Returns 0 if successful, and -1 in case or error
*/ */
int virLogReset(void) { int
virLogReset(void)
{
if (virLogInitialize() < 0) if (virLogInitialize() < 0)
return -1; return -1;
@ -259,10 +278,12 @@ int virLogReset(void) {
return 0; return 0;
} }
/* /*
* Store a string in the ring buffer * Store a string in the ring buffer
*/ */
static void virLogStr(const char *str) static void
virLogStr(const char *str)
{ {
int tmp; int tmp;
int len; int len;
@ -299,7 +320,10 @@ static void virLogStr(const char *str)
} }
} }
static void virLogDumpAllFD(const char *msg, int len) {
static void
virLogDumpAllFD(const char *msg, int len)
{
int i, found = 0; int i, found = 0;
if (len <= 0) if (len <= 0)
@ -319,6 +343,7 @@ static void virLogDumpAllFD(const char *msg, int len) {
ignore_value (safewrite(STDERR_FILENO, msg, len)); ignore_value (safewrite(STDERR_FILENO, msg, len));
} }
/** /**
* virLogEmergencyDumpAll: * virLogEmergencyDumpAll:
* @signum: the signal number * @signum: the signal number
@ -329,7 +354,8 @@ static void virLogDumpAllFD(const char *msg, int len) {
* In case none is found it is emitted to standard error. * In case none is found it is emitted to standard error.
*/ */
void void
virLogEmergencyDumpAll(int signum) { virLogEmergencyDumpAll(int signum)
{
int len; int len;
int oldLogStart, oldLogLen; int oldLogStart, oldLogLen;
@ -408,6 +434,7 @@ virLogEmergencyDumpAll(int signum) {
virLogDumpAllFD("\n\n ====== end of log =====\n\n", -1); virLogDumpAllFD("\n\n ====== end of log =====\n\n", -1);
} }
/** /**
* virLogSetDefaultPriority: * virLogSetDefaultPriority:
* @priority: the default priority level * @priority: the default priority level
@ -418,7 +445,9 @@ virLogEmergencyDumpAll(int signum) {
* *
* Returns 0 if successful, -1 in case of error. * Returns 0 if successful, -1 in case of error.
*/ */
int virLogSetDefaultPriority(virLogPriority priority) { int
virLogSetDefaultPriority(virLogPriority priority)
{
if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) { if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) {
VIR_WARN("Ignoring invalid log level setting."); VIR_WARN("Ignoring invalid log level setting.");
return -1; return -1;
@ -430,6 +459,7 @@ int virLogSetDefaultPriority(virLogPriority priority) {
return 0; return 0;
} }
/** /**
* virLogResetFilters: * virLogResetFilters:
* *
@ -437,7 +467,9 @@ int virLogSetDefaultPriority(virLogPriority priority) {
* *
* Returns the number of filters removed * Returns the number of filters removed
*/ */
static int virLogResetFilters(void) { static int
virLogResetFilters(void)
{
int i; int i;
for (i = 0; i < virLogNbFilters;i++) for (i = 0; i < virLogNbFilters;i++)
@ -447,6 +479,7 @@ static int virLogResetFilters(void) {
return i; return i;
} }
/** /**
* virLogDefineFilter: * virLogDefineFilter:
* @match: the pattern to match * @match: the pattern to match
@ -460,8 +493,10 @@ static int virLogResetFilters(void) {
* *
* Returns -1 in case of failure or the filter number if successful * Returns -1 in case of failure or the filter number if successful
*/ */
int virLogDefineFilter(const char *match, virLogPriority priority, int
unsigned int flags) virLogDefineFilter(const char *match,
virLogPriority priority,
unsigned int flags)
{ {
int i; int i;
char *mdup = NULL; char *mdup = NULL;
@ -500,6 +535,7 @@ cleanup:
return i; return i;
} }
/** /**
* virLogFiltersCheck: * virLogFiltersCheck:
* @input: the input string * @input: the input string
@ -510,8 +546,10 @@ cleanup:
* *
* Returns 0 if not matched or the new priority if found. * Returns 0 if not matched or the new priority if found.
*/ */
static int virLogFiltersCheck(const char *input, static int
unsigned int *flags) { virLogFiltersCheck(const char *input,
unsigned int *flags)
{
int ret = 0; int ret = 0;
int i; int i;
@ -527,6 +565,7 @@ static int virLogFiltersCheck(const char *input,
return ret; return ret;
} }
/** /**
* virLogResetOutputs: * virLogResetOutputs:
* *
@ -534,7 +573,9 @@ static int virLogFiltersCheck(const char *input,
* *
* Returns the number of output removed * Returns the number of output removed
*/ */
static int virLogResetOutputs(void) { static int
virLogResetOutputs(void)
{
int i; int i;
for (i = 0;i < virLogNbOutputs;i++) { for (i = 0;i < virLogNbOutputs;i++) {
@ -548,6 +589,7 @@ static int virLogResetOutputs(void) {
return i; return i;
} }
/** /**
* virLogDefineOutput: * virLogDefineOutput:
* @f: the function to call to output a message * @f: the function to call to output a message
@ -563,9 +605,14 @@ static int virLogResetOutputs(void) {
* *
* Returns -1 in case of failure or the output number if successful * Returns -1 in case of failure or the output number if successful
*/ */
int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data, int
virLogPriority priority, virLogDestination dest, const char *name, virLogDefineOutput(virLogOutputFunc f,
unsigned int flags) virLogCloseFunc c,
void *data,
virLogPriority priority,
virLogDestination dest,
const char *name,
unsigned int flags)
{ {
int ret = -1; int ret = -1;
char *ndup = NULL; char *ndup = NULL;
@ -630,8 +677,10 @@ virLogFormatString(char **msg,
return ret; return ret;
} }
static int static int
virLogVersionString(const char **rawmsg, char **msg) virLogVersionString(const char **rawmsg,
char **msg)
{ {
#ifdef PACKAGER_VERSION #ifdef PACKAGER_VERSION
# ifdef PACKAGER # ifdef PACKAGER
@ -650,6 +699,7 @@ virLogVersionString(const char **rawmsg, char **msg)
return virLogFormatString(msg, NULL, 0, VIR_LOG_INFO, LOG_VERSION_STRING); return virLogFormatString(msg, NULL, 0, VIR_LOG_INFO, LOG_VERSION_STRING);
} }
/** /**
* virLogMessage: * virLogMessage:
* @category: where is that message coming from * @category: where is that message coming from
@ -663,8 +713,13 @@ virLogVersionString(const char **rawmsg, char **msg)
* Call the libvirt logger with some information. Based on the configuration * Call the libvirt logger with some information. Based on the configuration
* the message may be stored, sent to output or just discarded * the message may be stored, sent to output or just discarded
*/ */
void virLogMessage(const char *category, virLogPriority priority, const char *funcname, void
int linenr, unsigned int flags, const char *fmt, ...) virLogMessage(const char *category,
virLogPriority priority,
const char *funcname,
int linenr,
unsigned int flags,
const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -672,6 +727,7 @@ void virLogMessage(const char *category, virLogPriority priority, const char *fu
va_end(ap); va_end(ap);
} }
/** /**
* virLogVMessage: * virLogVMessage:
* @category: where is that message coming from * @category: where is that message coming from
@ -685,9 +741,14 @@ void virLogMessage(const char *category, virLogPriority priority, const char *fu
* Call the libvirt logger with some information. Based on the configuration * Call the libvirt logger with some information. Based on the configuration
* the message may be stored, sent to output or just discarded * the message may be stored, sent to output or just discarded
*/ */
void virLogVMessage(const char *category, virLogPriority priority, const char *funcname, void
int linenr, unsigned int flags, const char *fmt, virLogVMessage(const char *category,
va_list vargs) virLogPriority priority,
const char *funcname,
int linenr,
unsigned int flags,
const char *fmt,
va_list vargs)
{ {
static bool logVersionStderr = true; static bool logVersionStderr = true;
char *str = NULL; char *str = NULL;
@ -791,7 +852,8 @@ cleanup:
} }
static void virLogStackTraceToFd(int fd) static void
virLogStackTraceToFd(int fd)
{ {
void *array[100]; void *array[100];
int size; int size;
@ -810,15 +872,16 @@ static void virLogStackTraceToFd(int fd)
#undef STRIP_DEPTH #undef STRIP_DEPTH
} }
static void virLogOutputToFd(const char *category ATTRIBUTE_UNUSED, static void
virLogPriority priority ATTRIBUTE_UNUSED, virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED, virLogPriority priority ATTRIBUTE_UNUSED,
int linenr ATTRIBUTE_UNUSED, const char *funcname ATTRIBUTE_UNUSED,
const char *timestamp, int linenr ATTRIBUTE_UNUSED,
unsigned int flags, const char *timestamp,
const char *rawstr ATTRIBUTE_UNUSED, unsigned int flags,
const char *str, const char *rawstr ATTRIBUTE_UNUSED,
void *data) const char *str,
void *data)
{ {
int fd = (intptr_t) data; int fd = (intptr_t) data;
char *msg; char *msg;
@ -836,21 +899,30 @@ static void virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
virLogStackTraceToFd(fd); virLogStackTraceToFd(fd);
} }
static void virLogCloseFd(void *data)
static void
virLogCloseFd(void *data)
{ {
int fd = (intptr_t) data; int fd = (intptr_t) data;
VIR_LOG_CLOSE(fd); VIR_LOG_CLOSE(fd);
} }
static int virLogAddOutputToStderr(virLogPriority priority) {
static int
virLogAddOutputToStderr(virLogPriority priority)
{
if (virLogDefineOutput(virLogOutputToFd, NULL, (void *)2L, priority, if (virLogDefineOutput(virLogOutputToFd, NULL, (void *)2L, priority,
VIR_LOG_TO_STDERR, NULL, 0) < 0) VIR_LOG_TO_STDERR, NULL, 0) < 0)
return -1; return -1;
return 0; return 0;
} }
static int virLogAddOutputToFile(virLogPriority priority, const char *file) {
static int
virLogAddOutputToFile(virLogPriority priority,
const char *file)
{
int fd; int fd;
fd = open(file, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR); fd = open(file, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
@ -865,8 +937,10 @@ static int virLogAddOutputToFile(virLogPriority priority, const char *file) {
return 0; return 0;
} }
#if HAVE_SYSLOG_H #if HAVE_SYSLOG_H
static int virLogPrioritySyslog(virLogPriority priority) static int
virLogPrioritySyslog(virLogPriority priority)
{ {
switch (priority) { switch (priority) {
case VIR_LOG_DEBUG: case VIR_LOG_DEBUG:
@ -882,15 +956,17 @@ static int virLogPrioritySyslog(virLogPriority priority)
} }
} }
static void virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
virLogPriority priority, static void
const char *funcname ATTRIBUTE_UNUSED, virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
int linenr ATTRIBUTE_UNUSED, virLogPriority priority,
const char *timestamp ATTRIBUTE_UNUSED, const char *funcname ATTRIBUTE_UNUSED,
unsigned int flags, int linenr ATTRIBUTE_UNUSED,
const char *rawstr ATTRIBUTE_UNUSED, const char *timestamp ATTRIBUTE_UNUSED,
const char *str, unsigned int flags,
void *data ATTRIBUTE_UNUSED) const char *rawstr ATTRIBUTE_UNUSED,
const char *str,
void *data ATTRIBUTE_UNUSED)
{ {
virCheckFlags(VIR_LOG_STACK_TRACE,); virCheckFlags(VIR_LOG_STACK_TRACE,);
@ -899,12 +975,19 @@ static void virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
static char *current_ident = NULL; static char *current_ident = NULL;
static void virLogCloseSyslog(void *data ATTRIBUTE_UNUSED) {
static void
virLogCloseSyslog(void *data ATTRIBUTE_UNUSED)
{
closelog(); closelog();
VIR_FREE(current_ident); VIR_FREE(current_ident);
} }
static int virLogAddOutputToSyslog(virLogPriority priority, const char *ident) {
static int
virLogAddOutputToSyslog(virLogPriority priority,
const char *ident)
{
/* /*
* ident needs to be kept around on Solaris * ident needs to be kept around on Solaris
*/ */
@ -928,6 +1011,7 @@ static int virLogAddOutputToSyslog(virLogPriority priority, const char *ident) {
((*cur == ' ') || (*cur == '\t') || (*cur == '\n') || \ ((*cur == ' ') || (*cur == '\t') || (*cur == '\n') || \
(*cur == '\r') || (*cur == '\\')) (*cur == '\r') || (*cur == '\\'))
/** /**
* virLogParseOutputs: * virLogParseOutputs:
* @outputs: string defining a (set of) output(s) * @outputs: string defining a (set of) output(s)
@ -951,7 +1035,9 @@ static int virLogAddOutputToSyslog(virLogPriority priority, const char *ident) {
* *
* Returns the number of output parsed and installed or -1 in case of error * Returns the number of output parsed and installed or -1 in case of error
*/ */
int virLogParseOutputs(const char *outputs) { int
virLogParseOutputs(const char *outputs)
{
const char *cur = outputs, *str; const char *cur = outputs, *str;
char *name; char *name;
char *abspath; char *abspath;
@ -1025,6 +1111,7 @@ cleanup:
return ret; return ret;
} }
/** /**
* virLogParseFilters: * virLogParseFilters:
* @filters: string defining a (set of) filter(s) * @filters: string defining a (set of) filter(s)
@ -1043,7 +1130,9 @@ cleanup:
* *
* Returns the number of filter parsed and installed or -1 in case of error * Returns the number of filter parsed and installed or -1 in case of error
*/ */
int virLogParseFilters(const char *filters) { int
virLogParseFilters(const char *filters)
{
const char *cur = filters, *str; const char *cur = filters, *str;
char *name; char *name;
virLogPriority prio; virLogPriority prio;
@ -1086,15 +1175,19 @@ cleanup:
return ret; return ret;
} }
/** /**
* virLogGetDefaultPriority: * virLogGetDefaultPriority:
* *
* Returns the current logging priority level. * Returns the current logging priority level.
*/ */
virLogPriority virLogGetDefaultPriority(void) { virLogPriority
virLogGetDefaultPriority(void)
{
return virLogDefaultPriority; return virLogDefaultPriority;
} }
/** /**
* virLogGetFilters: * virLogGetFilters:
* *
@ -1102,7 +1195,9 @@ virLogPriority virLogGetDefaultPriority(void) {
* specified in the config file or environment. Caller must free the * specified in the config file or environment. Caller must free the
* result. * result.
*/ */
char *virLogGetFilters(void) { char *
virLogGetFilters(void)
{
int i; int i;
virBuffer filterbuf = VIR_BUFFER_INITIALIZER; virBuffer filterbuf = VIR_BUFFER_INITIALIZER;
@ -1126,6 +1221,7 @@ char *virLogGetFilters(void) {
return virBufferContentAndReset(&filterbuf); return virBufferContentAndReset(&filterbuf);
} }
/** /**
* virLogGetOutputs: * virLogGetOutputs:
* *
@ -1133,7 +1229,9 @@ char *virLogGetFilters(void) {
* specified in the config file or environment. Caller must free the * specified in the config file or environment. Caller must free the
* result. * result.
*/ */
char *virLogGetOutputs(void) { char *
virLogGetOutputs(void)
{
int i; int i;
virBuffer outputbuf = VIR_BUFFER_INITIALIZER; virBuffer outputbuf = VIR_BUFFER_INITIALIZER;
@ -1166,24 +1264,31 @@ char *virLogGetOutputs(void) {
return virBufferContentAndReset(&outputbuf); return virBufferContentAndReset(&outputbuf);
} }
/** /**
* virLogGetNbFilters: * virLogGetNbFilters:
* *
* Returns the current number of defined log filters. * Returns the current number of defined log filters.
*/ */
int virLogGetNbFilters(void) { int
virLogGetNbFilters(void)
{
return virLogNbFilters; return virLogNbFilters;
} }
/** /**
* virLogGetNbOutputs: * virLogGetNbOutputs:
* *
* Returns the current number of defined log outputs. * Returns the current number of defined log outputs.
*/ */
int virLogGetNbOutputs(void) { int
virLogGetNbOutputs(void)
{
return virLogNbOutputs; return virLogNbOutputs;
} }
/** /**
* virLogParseDefaultPriority: * virLogParseDefaultPriority:
* @priority: string defining the desired logging level * @priority: string defining the desired logging level
@ -1197,7 +1302,9 @@ int virLogGetNbOutputs(void) {
* *
* Returns the parsed log level or -1 on error. * Returns the parsed log level or -1 on error.
*/ */
int virLogParseDefaultPriority(const char *priority) { int
virLogParseDefaultPriority(const char *priority)
{
int ret = -1; int ret = -1;
if (STREQ(priority, "1") || STREQ(priority, "debug")) if (STREQ(priority, "1") || STREQ(priority, "debug"))
@ -1214,13 +1321,16 @@ int virLogParseDefaultPriority(const char *priority) {
return ret; return ret;
} }
/** /**
* virLogSetFromEnv: * virLogSetFromEnv:
* *
* Sets virLogDefaultPriority, virLogFilters and virLogOutputs based on * Sets virLogDefaultPriority, virLogFilters and virLogOutputs based on
* environment variables. * environment variables.
*/ */
void virLogSetFromEnv(void) { void
virLogSetFromEnv(void)
{
char *debugEnv; char *debugEnv;
debugEnv = getenv("LIBVIRT_DEBUG"); debugEnv = getenv("LIBVIRT_DEBUG");

View File

@ -96,11 +96,14 @@ typedef enum {
* *
* Callback function used to output messages * Callback function used to output messages
*/ */
typedef void (*virLogOutputFunc) (const char *category, virLogPriority priority, typedef void (*virLogOutputFunc) (const char *category,
const char *funcname, int linenr, virLogPriority priority,
const char *funcname,
int linenr,
const char *timestamp, const char *timestamp,
unsigned int flags, unsigned int flags,
const char *rawstr, const char *str, const char *rawstr,
const char *str,
void *data); void *data);
/** /**
@ -122,10 +125,15 @@ extern char *virLogGetOutputs(void);
extern virLogPriority virLogGetDefaultPriority(void); extern virLogPriority virLogGetDefaultPriority(void);
extern int virLogSetDefaultPriority(virLogPriority priority); extern int virLogSetDefaultPriority(virLogPriority priority);
extern void virLogSetFromEnv(void); extern void virLogSetFromEnv(void);
extern int virLogDefineFilter(const char *match, virLogPriority priority, extern int virLogDefineFilter(const char *match,
virLogPriority priority,
unsigned int flags); unsigned int flags);
extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data, extern int virLogDefineOutput(virLogOutputFunc f,
virLogPriority priority, virLogDestination dest, const char *name, virLogCloseFunc c,
void *data,
virLogPriority priority,
virLogDestination dest,
const char *name,
unsigned int flags); unsigned int flags);
/* /*
@ -138,12 +146,16 @@ extern int virLogReset(void);
extern int virLogParseDefaultPriority(const char *priority); extern int virLogParseDefaultPriority(const char *priority);
extern int virLogParseFilters(const char *filters); extern int virLogParseFilters(const char *filters);
extern int virLogParseOutputs(const char *output); extern int virLogParseOutputs(const char *output);
extern void virLogMessage(const char *category, virLogPriority priority, extern void virLogMessage(const char *category,
const char *funcname, int linenr, virLogPriority priority,
const char *funcname,
int linenr,
unsigned int flags, unsigned int flags,
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7); const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
extern void virLogVMessage(const char *category, virLogPriority priority, extern void virLogVMessage(const char *category,
const char *funcname, int linenr, virLogPriority priority,
const char *funcname,
int linenr,
unsigned int flags, unsigned int flags,
const char *fmt, const char *fmt,
va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0); va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);