[syslog-ng] TZ DST offset problem in 1.6.8 syslog-ng using
$TZOFFSET or $ISODATE....
Balazs Scheidler
bazsi at balabit.hu
Wed Nov 2 20:37:51 CET 2005
Hi,
Can you check if this patch fixes the problem? I've just commited it to
CVS, so it should be available in tomorrow's snapshot.
Index: syslog-ng/configure.in
diff -u syslog-ng/configure.in:1.72.4.25 syslog-ng/configure.in:1.72.4.26
--- syslog-ng/configure.in:1.72.4.25 Thu Jun 30 11:20:10 2005
+++ syslog-ng/configure.in Wed Nov 2 20:35:47 2005
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.72.4.25 2005/06/30 09:20:10 bazsi Exp $
+dnl $Id: configure.in,v 1.72.4.26 2005/11/02 19:35:47 bazsi Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/affile.c)
AC_PREREQ(2.50)
@@ -136,6 +136,7 @@
AC_DEFINE(HAVE_MODERN_UTMP, 1, [new style UTMP is defined on the system])
fi
+
dnl Seek a type for UINT32
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4)
@@ -185,7 +186,7 @@
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_FUNCS(select snprintf vsnprintf strerror inet_aton strncpy getutent)
-AC_CHECK_FUNCS(getopt_long strcasecmp strptime)
+AC_CHECK_FUNCS(getopt_long strcasecmp strptime strftime)
old_LIBS=$LIBS
@@ -218,6 +219,34 @@
LIBS=$old_LIBS
LIBWRAP_LIBS=$blb_cv_c_lwrap
+AC_CACHE_CHECK([for %z format string in strftime],
+ blb_cv_c_strftime_percent_z,
+[AC_TRY_RUN([
+#include <time.h>
+#include <string.h>
+
+int main(void)
+{
+ struct tm tm;
+ char buf[32];
+
+ memset(&tm, 0, sizeof(tm));
+ strftime(buf, sizeof(buf), "%z", &tm);
+
+ if (strlen(buf) == 5)
+ return 0;
+ return 1;
+}
+],
+blb_cv_c_strftime_percent_z=yes,
+blb_cv_c_strftime_percent_z=no,
+blb_cv_c_strftime_percent_z=no)])
+
+if test "x$blb_cv_c_strftime_percent_z" = "xyes"; then
+ AC_DEFINE(HAVE_STRFTIME_PERCENT_Z, 1, [strftime has a %z format argument])
+fi
+
+
if test "x$ac_cv_func_snprintf" = "xno" -o \
"x$ac_cv_func_vsnprintf" = "xno"; then
AC_LIBOBJ(snprintf)
Index: syslog-ng/src/macros.c
diff -u syslog-ng/src/macros.c:1.4.4.6 syslog-ng/src/macros.c:1.4.4.7
--- syslog-ng/src/macros.c:1.4.4.6 Thu Aug 5 13:35:12 2004
+++ syslog-ng/src/macros.c Wed Nov 2 20:35:47 2005
@@ -19,7 +19,7 @@
*
* Inspired by nsyslog, originally written by Darren Reed.
*
- * $Id: macros.c,v 1.4.4.6 2004/08/05 11:35:12 bazsi Exp $
+ * $Id: macros.c,v 1.4.4.7 2005/11/02 19:35:47 bazsi Exp $
*
***************************************************************************/
@@ -109,17 +109,33 @@
}
static size_t
-format_tzofs(char *dest, size_t left, struct tm *tm)
+format_tzofs(char *dest, size_t left, time_t unixtime, struct tm *tm)
{
size_t length;
-#if HAVE_GLOBAL_TIMEZONE
- length = snprintf(dest, left - 1, "%c%02ld%02ld",
- timezone > 0 ? '-' : '+',
- (timezone < 0 ? -timezone : timezone) / 3600,
- (timezone % 3600) / 60);
-#else
+#if HAVE_STRFTIME_PERCENT_Z
length = strftime(dest, left -1, "%z", tm);
+#else
+ struct tm ltm, *gtm;
+ long tzoff;
+
+ ltm = *localtime(&unixtime);
+ gtm = gmtime(&unixtime);
+
+ tzoff = (ltm.tm_hour - gtm->tm_hour) * 3600;
+ tzoff += (ltm.tm_min - gtm->tm_min) * 60;
+ tzoff += ltm.tm_sec - gtm->tm_sec;
+
+ /* normalize within +/- 12 hours */
+ if (tzoff < -12*3600)
+ tzoff += 24*3600;
+ else if (tzoff > 12*3600)
+ tzoff -= 24*3600;
+
+ length = snprintf(dest, left - 1, "%c%02ld%02ld",
+ tzoff < 0 ? '-' : '+',
+ (tzoff < 0 ? -tzoff : tzoff) / 3600,
+ (tzoff % 3600) / 60);
#endif
return length;
}
@@ -340,7 +356,7 @@
case M_ISODATE_RECVD:
case M_ISODATE_STAMP:
length = strftime(*dest, *left - 1, "%Y-%m-%dT%H:%M:%S", tm);
- length = length + format_tzofs((*dest) + length, *left - length - 1, tm);
+ length = length + format_tzofs((*dest) + length, *left - length - 1, unixtime, tm);
break;
case M_FULLDATE:
case M_FULLDATE_RECVD:
@@ -355,7 +371,7 @@
case M_TZOFFSET:
case M_TZOFFSET_RECVD:
case M_TZOFFSET_STAMP:
- length = format_tzofs(*dest, *left - 1, tm);
+ length = format_tzofs(*dest, *left - 1, unixtime, tm);
break;
case M_TZ:
case M_TZ_RECVD:
On Mon, 2005-10-31 at 14:37 +0100, Peter Valdemar Mørch wrote:
> Hi,
--
Bazsi
More information about the syslog-ng
mailing list