90 lines
2.5 KiB
Diff
90 lines
2.5 KiB
Diff
From 744247bcfdba1dc90f71f3ef693f557b663a9cc8 Mon Sep 17 00:00:00 2001
|
|
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
Date: Tue, 29 Nov 2011 12:32:31 +0000
|
|
Subject: [PATCH 04/13] Make logging async signal safe wrt time stamp
|
|
generation
|
|
|
|
cherry pick (with small conflict resolution in src/util/logging.c) from
|
|
upstream 32d3ec7 to address:
|
|
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=757382
|
|
|
|
Use the new virTimeStringNowRaw() API for generating log timestamps
|
|
in an async signal safe manner
|
|
|
|
* src/util/logging.c: Use virTimeStringNowRaw
|
|
---
|
|
src/util/logging.c | 28 ++++------------------------
|
|
1 files changed, 4 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/src/util/logging.c b/src/util/logging.c
|
|
index 9df9003..22d7c2b 100644
|
|
--- a/src/util/logging.c
|
|
+++ b/src/util/logging.c
|
|
@@ -43,6 +43,7 @@
|
|
#include "buf.h"
|
|
#include "threads.h"
|
|
#include "virfile.h"
|
|
+#include "virtime.h"
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
@@ -618,26 +619,6 @@ cleanup:
|
|
return ret;
|
|
}
|
|
|
|
-static char *
|
|
-virLogFormatTimestamp(void)
|
|
-{
|
|
- struct timeval cur_time;
|
|
- struct tm time_info;
|
|
- char *str = NULL;
|
|
-
|
|
- gettimeofday(&cur_time, NULL);
|
|
- localtime_r(&cur_time.tv_sec, &time_info);
|
|
- time_info.tm_year += 1900;
|
|
-
|
|
- if (virAsprintf(&str, "%4d-%02d-%02d %02d:%02d:%02d.%03d",
|
|
- time_info.tm_year, time_info.tm_mon, time_info.tm_mday,
|
|
- time_info.tm_hour, time_info.tm_min, time_info.tm_sec,
|
|
- (int) (cur_time.tv_usec / 1000)) < 0)
|
|
- return NULL;
|
|
-
|
|
- return str;
|
|
-}
|
|
-
|
|
static int
|
|
virLogFormatString(char **msg,
|
|
const char *funcname,
|
|
@@ -704,7 +685,7 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|
static bool logVersionStderr = true;
|
|
char *str = NULL;
|
|
char *msg = NULL;
|
|
- char *timestamp = NULL;
|
|
+ char timestamp[VIR_TIME_STRING_BUFLEN];
|
|
int fprio, i, ret;
|
|
int saved_errno = errno;
|
|
int emit = 1;
|
|
@@ -745,8 +726,8 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|
if (ret < 0)
|
|
goto cleanup;
|
|
|
|
- if (!(timestamp = virLogFormatTimestamp()))
|
|
- goto cleanup;
|
|
+ if (virTimeStringNowRaw(timestamp) < 0)
|
|
+ timestamp[0] = '\0';
|
|
|
|
/*
|
|
* Log based on defaults, first store in the history buffer,
|
|
@@ -798,7 +779,6 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|
|
|
cleanup:
|
|
VIR_FREE(msg);
|
|
- VIR_FREE(timestamp);
|
|
errno = saved_errno;
|
|
}
|
|
|
|
--
|
|
1.7.7.3
|
|
|