Index: syslogger.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/syslogger.c,v
retrieving revision 1.8
diff -C1 -r1.8 syslogger.c
*** syslogger.c	31 Aug 2004 04:53:44 -0000	1.8
--- syslogger.c	20 Sep 2004 22:26:01 -0000
***************
*** 849,850 ****
--- 849,882 ----
  
+ 
+ /*
+  * Determine our offset from GMT so we can rotate on localtime boundaries.
+  */
+ pg_time_t 
+ utc_offset (pg_time_t now) {
+     int     offset = 1.0, count;
+     char    msg[8], hrs[3], min[3];
+ 
+     /* 
+      * We expect a strftime(%z) result of the form "[+-]HHMM" according to
+      * RFC822-conformant dates, where HH:MM is the unsigned UTC offset.
+      * If we don't get it, just return zero offset, and let the logs
+      * rotate on UTC time boundaries.
+      */
+ 
+     count = strftime(msg, 6, "%z", localtime(&now));
+     if ( count != 5 ) {
+         return 0;
+     }
+ 
+     if ( msg[0] == '-' )
+         offset = -1.0;
+     strncpy(hrs, msg[1], 2);
+     offset = offset * atoi(hrs) * 3600;
+     strncpy(min, msg[3], 2);
+     offset += atoi(min) * 60;
+ 
+     return offset;
+ }
+ 
+ 
  /*
***************
*** 865,868 ****
  	 * "multiple" of the log rotation interval.  "Multiple" can be interpreted
! 	 * fairly loosely --- in particular, for intervals larger than an hour,
! 	 * it might be interesting to align to local time instead of GMT.
  	 */
--- 897,909 ----
  	 * "multiple" of the log rotation interval.  "Multiple" can be interpreted
! 	 * fairly loosely and we attempt to align with local time.
! 	 *
! 	 * In cases of Daylight Savings Time, if local time shifts backward
!    	 * from 02:00 to 01:00, our UTC offset will move in the negative 
! 	 * direction.  This could cause a logfile rotation into the same 
!    	 * filename we just had open, thereby erasing an hour of log data 
! 	 * if 1) our policy were to truncate, 2) we were rotating hourly
!    	 * or more frequently, and 3) our filename did not contain the 
! 	 * epoch or UTC offset.  Apache's rotatelogs apparently has the 
!    	 * same issue.  Naming files with the epoch (%s) and/or UTC 
! 	 * offset (%z) avoids that problem.
  	 */
***************
*** 870,873 ****
  	now = time(NULL);
  	now -= now % rotinterval;
! 	now += rotinterval;
  	next_rotation_time = now;
--- 911,915 ----
  	now = time(NULL);
+ 	now += (offset = utc_offset(now));
  	now -= now % rotinterval;
! 	now += rotinterval - offset;
  	next_rotation_time = now;
