mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 23:37:42 +00:00
logging: make VIR_ERROR and friends preserve errno
Followup to commit17e19add
, and would have prevented the bug independently fixed in commit76c57a7c
. * src/util/logging.c (virLogMessage): Preserve errno, since logging should be as unintrusive as possible.
This commit is contained in:
parent
ce6fd65088
commit
bb904f45ff
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* logging.c: internal logging and debugging
|
* logging.c: internal logging and debugging
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2010 Red Hat, Inc.
|
* Copyright (C) 2008, 2010-2011 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
|
||||||
@ -573,12 +573,13 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|||||||
struct timeval cur_time;
|
struct timeval cur_time;
|
||||||
struct tm time_info;
|
struct tm time_info;
|
||||||
int len, fprio, i, ret;
|
int len, fprio, i, ret;
|
||||||
|
int saved_errno = errno;
|
||||||
|
|
||||||
if (!virLogInitialized)
|
if (!virLogInitialized)
|
||||||
virLogStartup();
|
virLogStartup();
|
||||||
|
|
||||||
if (fmt == NULL)
|
if (fmt == NULL)
|
||||||
return;
|
goto cleanup;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check against list of specific logging patterns
|
* check against list of specific logging patterns
|
||||||
@ -586,16 +587,17 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|||||||
fprio = virLogFiltersCheck(category);
|
fprio = virLogFiltersCheck(category);
|
||||||
if (fprio == 0) {
|
if (fprio == 0) {
|
||||||
if (priority < virLogDefaultPriority)
|
if (priority < virLogDefaultPriority)
|
||||||
return;
|
goto cleanup;
|
||||||
} else if (priority < fprio)
|
} else if (priority < fprio) {
|
||||||
return;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* serialize the error message, add level and timestamp
|
* serialize the error message, add level and timestamp
|
||||||
*/
|
*/
|
||||||
VIR_GET_VAR_STR(fmt, str);
|
VIR_GET_VAR_STR(fmt, str);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return;
|
goto cleanup;
|
||||||
gettimeofday(&cur_time, NULL);
|
gettimeofday(&cur_time, NULL);
|
||||||
localtime_r(&cur_time.tv_sec, &time_info);
|
localtime_r(&cur_time.tv_sec, &time_info);
|
||||||
|
|
||||||
@ -603,10 +605,8 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|||||||
&time_info, &cur_time,
|
&time_info, &cur_time,
|
||||||
priority, str);
|
priority, str);
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
/* apparently we're running out of memory */
|
goto cleanup;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log based on defaults, first store in the history buffer
|
* Log based on defaults, first store in the history buffer
|
||||||
@ -648,6 +648,8 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|||||||
virLogUnlock();
|
virLogUnlock();
|
||||||
|
|
||||||
VIR_FREE(msg);
|
VIR_FREE(msg);
|
||||||
|
cleanup:
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
|
static int virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
|
||||||
|
Loading…
Reference in New Issue
Block a user