ソースを参照

Merge trunk revision 2571:
r2571 | honzaf | 2009-12-07 10:14:44 -0700 (Mon, 07 Dec 2009) | 2 lines

Remove potentially thread unsafe call of strftime



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2626 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 16 年 前
コミット
0dd48c65a4
2 ファイル変更10 行追加2 行削除
  1. 0 1
      configure.ac
  2. 10 1
      exec/logsys.c

+ 0 - 1
configure.ac

@@ -110,7 +110,6 @@ AC_FUNC_MEMCMP
 AC_FUNC_REALLOC
 AC_FUNC_SELECT_ARGTYPES
 AC_TYPE_SIGNAL
-AC_FUNC_STRFTIME
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
 		getcwd getpeerucred getpeereid gettimeofday inet_ntoa memmove \

+ 10 - 1
exec/logsys.c

@@ -410,6 +410,11 @@ static inline int strcpy_cutoff (char *dest, const char *src, size_t cutoff,
 	return (cutoff);
 }
 
+static const char log_month_name[][4] = {
+	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
 /*
  * %s SUBSYSTEM
  * %n FUNCTION NAME
@@ -441,6 +446,7 @@ static void log_printf_to_logs (
 	int subsysid;
 	unsigned int level;
 	int c;
+	struct tm tm_res;
 
 	if (LOGSYS_DECODE_RECID(rec_ident) != LOGSYS_RECID_LOG) {
 		return;
@@ -490,7 +496,10 @@ static void log_printf_to_logs (
 
 				case 't':
 					gettimeofday (&tv, NULL);
-					(void)strftime (char_time, sizeof (char_time), "%b %d %T", localtime ((time_t *)&tv.tv_sec));
+					(void)localtime_r ((time_t *)&tv.tv_sec, &tm_res);
+					snprintf (char_time, sizeof (char_time), "%s %02d %02d:%02d:%02d",
+					    log_month_name[tm_res.tm_mon], tm_res.tm_mday, tm_res.tm_hour,
+					    tm_res.tm_min, tm_res.tm_sec);
 					normal_p = char_time;
 
 					/*