File ntp-sntp-dst.patch of Package ntp.9120
Index: ntp-4.2.8p4/sntp/utilities.c
===================================================================
--- ntp-4.2.8p4.orig/sntp/utilities.c
+++ ntp-4.2.8p4/sntp/utilities.c
@@ -139,34 +139,36 @@ tv_to_str(
{
const size_t bufsize = 48;
char *buf;
- time_t gmt_time, local_time;
- struct tm *p_tm_local;
+ time_t time_gmt, time_local;
+ struct tm tm_gmt, tm_local;
int hh, mm, lto;
- /*
- * convert to struct tm in UTC, then intentionally feed
- * that tm to mktime() which expects local time input, to
- * derive the offset from UTC to local time.
+ /* Get local time, convert it to GMT, adjust the tm_isdst to the
+ * current local DST value. Then call mktime which will not adjust
+ * for DST allowing us to calculate the offset from local to GMT
*/
- gmt_time = tv->tv_sec;
- local_time = mktime(gmtime(&gmt_time));
- p_tm_local = localtime(&gmt_time);
+ time_gmt = tv->tv_sec;
+ localtime_r(&time_gmt, &tm_local);
+ time_local = mktime(&tm_local);
+ gmtime_r(&time_local, &tm_gmt);
+ tm_gmt.tm_isdst=tm_local.tm_isdst;
+ time_gmt = mktime(&tm_gmt);
/* Local timezone offsets should never cause an overflow. Yeah. */
- lto = difftime(local_time, gmt_time);
+ lto = difftime(time_local, time_gmt);
lto /= 60;
hh = lto / 60;
mm = abs(lto % 60);
- buf = emalloc(bufsize);
+ buf = malloc(bufsize);
snprintf(buf, bufsize,
"%d-%.2d-%.2d %.2d:%.2d:%.2d.%.6d (%+03d%02d)",
- p_tm_local->tm_year + 1900,
- p_tm_local->tm_mon + 1,
- p_tm_local->tm_mday,
- p_tm_local->tm_hour,
- p_tm_local->tm_min,
- p_tm_local->tm_sec,
+ tm_local.tm_year + 1900,
+ tm_local.tm_mon + 1,
+ tm_local.tm_mday,
+ tm_local.tm_hour,
+ tm_local.tm_min,
+ tm_local.tm_sec,
(int)tv->tv_usec,
hh,
mm);