#define VIR_FROM_THIS VIR_FROM_NONE
-/*
- * Macro used to format the message as a string in virLogMessage
- * and borrowed from libxml2 (also used in virRaiseError)
- */
-#define VIR_GET_VAR_STR(msg, str) { \
- int size, prev_size = -1; \
- int chars; \
- char *larger; \
- va_list ap; \
- \
- str = (char *) malloc(150); \
- if (str != NULL) { \
- \
- size = 150; \
- \
- while (1) { \
- va_start(ap, msg); \
- chars = vsnprintf(str, size, msg, ap); \
- va_end(ap); \
- if ((chars > -1) && (chars < size)) { \
- if (prev_size == chars) { \
- break; \
- } else { \
- prev_size = chars; \
- } \
- } \
- if (chars > -1) \
- size += chars + 1; \
- else \
- size += 100; \
- if ((larger = (char *) realloc(str, size)) == NULL) { \
- break; \
- } \
- str = larger; \
- }} \
-}
-
/*
* A logging buffer to keep some history over logs
*/
int len, fprio, i, ret;
int saved_errno = errno;
int emit = 1;
+ va_list ap;
if (!virLogInitialized)
virLogStartup();
/*
* serialize the error message, add level and timestamp
*/
- VIR_GET_VAR_STR(fmt, str);
- if (str == NULL)
+ va_start(ap, fmt);
+ if (virVasprintf(&str, fmt, ap) < 0) {
+ va_end(ap);
goto cleanup;
+ }
+ va_end(ap);
gettimeofday(&cur_time, NULL);
localtime_r(&cur_time.tv_sec, &time_info);
void *virUserData = NULL; /* associated data */
virErrorLogPriorityFunc virErrorLogPriorityFilter = NULL;
-/*
- * Macro used to format the message as a string in virRaiseError
- * and borrowed from libxml2.
- */
-#define VIR_GET_VAR_STR(msg, str) { \
- int size, prev_size = -1; \
- int chars; \
- char *larger; \
- va_list ap; \
- \
- str = (char *) malloc(150); \
- if (str != NULL) { \
- \
- size = 150; \
- \
- while (1) { \
- va_start(ap, msg); \
- chars = vsnprintf(str, size, msg, ap); \
- va_end(ap); \
- if ((chars > -1) && (chars < size)) { \
- if (prev_size == chars) { \
- break; \
- } else { \
- prev_size = chars; \
- } \
- } \
- if (chars > -1) \
- size += chars + 1; \
- else \
- size += 100; \
- if ((larger = (char *) realloc(str, size)) == NULL) { \
- break; \
- } \
- str = larger; \
- }} \
-}
-
static virLogPriority virErrorLevelPriority(virErrorLevel level) {
switch (level) {
case VIR_ERR_NONE:
}
/*
- * formats the message
+ * formats the message; drop message on OOM situations
*/
if (fmt == NULL) {
str = strdup(_("No error message provided"));
} else {
- VIR_GET_VAR_STR(fmt, str);
+ va_list ap;
+ va_start(ap, fmt);
+ virVasprintf(&str, fmt, ap);
+ va_end(ap);
}
/*