1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
$NetBSD: patch-src_zm_logger_cpp,v 1.7 2022/09/27 01:20:39 gdt Exp $
Use libgen.h for basename.
Kludge around const for basename.
If the system has syscall() but not SYS_gettid [E.g. NetBSD], don't attempt
to use SYS_gettid.
Fix time types (sizes).
--- src/zm_logger.cpp.orig 2019-02-22 15:38:47.000000000 +0000
+++ src/zm_logger.cpp
@@ -33,9 +33,11 @@
#include <errno.h>
#ifdef __FreeBSD__
#include <sys/thr.h>
-#include <libgen.h>
#endif
+/* POSIX specifies libgen.h for basename() */
+#include <libgen.h>
+
bool Logger::smInitialised = false;
Logger *Logger::smInstance = 0;
@@ -515,7 +517,8 @@ void Logger::logPrint( bool hex, const c
va_list argPtr;
struct timeval timeVal;
- const char * const file = basename(filepath);
+ /* \todo Verify that the cast is safe. */
+ const char * const file = basename((char *)filepath);
if ( level < PANIC || level > DEBUG9 )
Panic( "Invalid logger level %d", level );
@@ -531,14 +534,14 @@ void Logger::logPrint( bool hex, const c
subtractTime( &timeVal, &logStart );
- snprintf( timeString, sizeof(timeString), "%ld.%03ld", timeVal.tv_sec, timeVal.tv_usec/1000 );
+ snprintf( timeString, sizeof(timeString), "%jd.%03ld", (intmax_t) timeVal.tv_sec, timeVal.tv_usec/1000 );
}
else
{
#endif
char *timePtr = timeString;
timePtr += strftime( timePtr, sizeof(timeString), "%x %H:%M:%S", localtime(&timeVal.tv_sec) );
- snprintf( timePtr, sizeof(timeString)-(timePtr-timeString), ".%06ld", timeVal.tv_usec );
+ snprintf( timePtr, sizeof(timeString)-(timePtr-timeString), ".%06jd", (intmax_t) timeVal.tv_usec );
#if 0
}
#endif
@@ -615,7 +618,7 @@ void Logger::logPrint( bool hex, const c
mysql_real_escape_string( &mDbConnection, escapedString, syslogStart, strlen(syslogStart) );
- snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line );
+ snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %jd.%06jd, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", (intmax_t) timeVal.tv_sec, (intmax_t) timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line );
if ( mysql_query( &mDbConnection, sql ) )
{
Level tempDatabaseLevel = mDatabaseLevel;
|