Subject: [alpine-aports] [PATCH] main/busybox: fix timezone adjustment in syslogd

From: Oleg Omelyusik <[email-masked]>
Date: Sat, 22 Jul 2017 01:23:42 +0300

---
 ...gd-fix-timezone-adjustment-implementation.patch | 47 ++++++++++++++++++++++
 main/busybox/APKBUILD                              |  2 +
 2 files changed, 49 insertions(+)
 create mode 100644 main/busybox/0012-syslogd-fix-timezone-adjustment-implementation.patch

diff --git a/main/busybox/0012-syslogd-fix-timezone-adjustment-implementation.patch b/main/busybox/0012-syslogd-fix-timezone-adjustment-implementation.patch
new file mode 100644
index 0000000000..f276bc3e57
--- /dev/null
+++ b/main/busybox/0012-syslogd-fix-timezone-adjustment-implementation.patch
@@ -0,0 +1,47 @@
+From b09a292755943b3881aa3525c906989929c19fc8 Mon Sep 17 00:00:00 2001
+From: Oleg Omelyusik <[email-masked]>
+Date: Fri, 21 Jul 2017 16:29:55 +0300
+Subject: [PATCH] syslogd: fix timezone adjustment implementation
+
+strptime() does not set year value which is needed for mktime().
+Also need to take into account year value when operating with timestamps
+to prevent invalid convertions for leap years (e.g. Feb 28 23:00:00 UTC to GMT+2).
+---
+ sysklogd/syslogd.c | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
+index 1c67d1379..5ad50acd0 100644
+--- a/sysklogd/syslogd.c
++++ b/sysklogd/syslogd.c
+@@ -820,7 +820,8 @@ static void timestamp_and_log(int pri, char *msg, int len)
+ {
+ 	char *timestamp;
+ 	time_t now;
+-	struct tm nowtm = { .tm_isdst = 0 };
++	struct tm msgtm = { .tm_isdst = 0 };
++	struct tm nowtm = { 0 };
+ 
+ 	/* Jan 18 00:11:22 msg... */
+ 	/* 01234567890123456 */
+@@ -830,8 +831,15 @@ static void timestamp_and_log(int pri, char *msg, int len)
+ 		now = time(NULL);
+ 		timestamp = ctime(&now) + 4; /* skip day of week */
+ 	} else {
+-		if (G.adjustTimezone && strptime(msg, "%b %e %T", &nowtm)) {
+-			now = mktime(&nowtm) - timezone;
++		if (G.adjustTimezone && strptime(msg, "%b %e %T", &msgtm)) {
++			/* set message year as current or previous year */
++			now = time(NULL);
++			gmtime_r(&now, &nowtm);
++			msgtm.tm_year = nowtm.tm_year;
++			if (nowtm.tm_mon < msgtm.tm_mon)
++				--msgtm.tm_year;
++			/* adjust message timestamp */
++			now = mktime(&msgtm) - timezone;
+ 			timestamp = ctime(&now) + 4; /* skip day of week */
+ 		} else {
+ 			now = 0;
+-- 
+2.13.0
+
diff --git a/main/busybox/APKBUILD b/main/busybox/APKBUILD
index 0010854105..e2d61f8799 100644
--- a/main/busybox/APKBUILD
+++ b/main/busybox/APKBUILD
@@ -29,6 +29,7 @@ source="http://busybox.net/downloads/$pkgname-$pkgver.tar.bz2
 	0009-sysklogd-add-Z-option-to-adjust-message-timezones.patch
 	0010-udhcpc-Don-t-background-if-n-is-given.patch
 	0011-testsuite-fix-cpio-tests.patch
+	0012-syslogd-fix-timezone-adjustment-implementation.patch
 
 	top-buffer-overflow.patch
 
@@ -179,6 +180,7 @@ baac796f8aa96fbeab19f96eea7787ace5737b182f49e02f1b1e911d0a927ae14f3c334daad42418
 d1c375184f806f7550bac5c82ab5471bdb8085d845172c973724b22af05ab3759b3ce982e088b4c45815ade56b9adfb7a677d0c180e077545ac7ec003c8aa7c4  0009-sysklogd-add-Z-option-to-adjust-message-timezones.patch
 9b5143d0be615b1604d82007628d59a62721f1e61a63cca7a4ffa5e60fa8da102bfc21fa20cc35c2f5a0a24bc8013598f8eff5888f9d0f3bcfa796343b5f5a91  0010-udhcpc-Don-t-background-if-n-is-given.patch
 f4e00eb13fda752df13f300a7ed9b1320ca9f573c4309247f292c8710464d7be8740148f42e4aff16312335eadabce5a629dce4af58334b9199faf2fd658e4f9  0011-testsuite-fix-cpio-tests.patch
+e6774045441a88bf6b1edb83865cac33ee1a51c2da510b190cf6d790f1d2e6f13dc386c992ef414810dad7b80686f772b28adc5c25171bdc14cddc256344cdff  0012-syslogd-fix-timezone-adjustment-implementation.patch
 524e858b52cb31fb8d24e8c7f18606fff349aeab6a14da9cca3902641f6127980daed73c53586c6e8b41eecda06cdb29c40ff1dde2dc82a318c2649680458921  top-buffer-overflow.patch
 a9b1403c844c51934637215307dd9e2adb9458921047acff0d86dcf229b6e0027f4b2c6cdaa25a58407aad9d098fb5685d58eb5ff8d2aa3de4912cdea21fe54c  acpid.logrotate
 857dece10267a065e0e8c16dd6190656f890a5aff774e96321715673dda23e75a8e61148e81d6286b7bdfe737a0b99104f9b04deeb4f392c72b63d8e3d00e556  busyboxconfig
-- 
2.13.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Natanael Copa <[email-masked]>
Date: Mon, 24 Jul 2017 14:49:37 +0200

On Sat, 22 Jul 2017 01:23:42 +0300

> +++ b/main/busybox/0012-syslogd-fix-timezone-adjustment-implementation.patch

Was this patch sent upstream?

-nc

---

---

From: Oleg Omelyusik <[email-masked]>
Date: Mon, 24 Jul 2017 16:06:22 +0300

Hello,

No it wasn't, since timezone adjustment is Alpine specific feature.
This is about '-Z' option added to syslogd (commit
318c497f003be1645152235d1b08005f7dfde3ee in aports repo).
I've also found related open bug in your tracker and updated it:
https://bugs.alpinelinux.org/issues/3694

Thanks,
Oleg

---

---

From: Natanael Copa <[email-masked]>
Date: Thu, 3 Aug 2017 15:31:14 +0200

On Mon, 24 Jul 2017 16:06:22 +0300

> https://bugs.alpinelinux.org/issues/3694

Shiz: Can you please have a look at this?

-nc

---

---

From: Oleg Omelyusik <[email-masked]>
Date: Tue, 22 Aug 2017 14:58:22 +0300

---
Changes v1 -> v2:
  - rebased to the master branch

 ...gd-fix-timezone-adjustment-implementation.patch | 47 ++++++++++++++++++++++
 main/busybox/APKBUILD                              |  2 +
 2 files changed, 49 insertions(+)
 create mode 100644 main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch

diff --git a/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch b/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch
new file mode 100644
+++ b/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch
index 63fc3369c6..97c5491b0c 100644
@@ -32,6 +32,7 @@ source="http://busybox.net/downloads/$pkgname-$pkgver.tar.bz2
 	0001-unzip-fix-regression-on-big-endian-machines.patch
 	0012-microcom-segfault.patch
+	0013-syslogd-fix-timezone-adjustment-implementation.patch

@@ -184,6 +185,7 @@ d1c375184f806f7550bac5c82ab5471bdb8085d845172c973724b22af05ab3759b3ce982e088b4c4
 f4e00eb13fda752df13f300a7ed9b1320ca9f573c4309247f292c8710464d7be8740148f42e4aff16312335eadabce5a629dce4af58334b9199faf2fd658e4f9  0011-testsuite-fix-cpio-tests.patch
 daa6732a95a52a194d2031f2d5af5f658b9da3e8669fc2206000faaab7da56966a62646eed615fd1cbc5f07d42c03bf19ff183ef6f933b7daaeef1d388e21874  0001-unzip-fix-regression-on-big-endian-machines.patch
 a09a64b3bce8048c58a68dcd2dd9e63c911009c06195d6bb4e5aecfb5700e479c25b34635c60899127975fae32275ad51846ee75f840d612e00668ce9aba8322  0012-microcom-segfault.patch
+e6774045441a88bf6b1edb83865cac33ee1a51c2da510b190cf6d790f1d2e6f13dc386c992ef414810dad7b80686f772b28adc5c25171bdc14cddc256344cdff  0013-syslogd-fix-timezone-adjustment-implementation.patch
 524e858b52cb31fb8d24e8c7f18606fff349aeab6a14da9cca3902641f6127980daed73c53586c6e8b41eecda06cdb29c40ff1dde2dc82a318c2649680458921  top-buffer-overflow.patch
 a9b1403c844c51934637215307dd9e2adb9458921047acff0d86dcf229b6e0027f4b2c6cdaa25a58407aad9d098fb5685d58eb5ff8d2aa3de4912cdea21fe54c  acpid.logrotate
 857dece10267a065e0e8c16dd6190656f890a5aff774e96321715673dda23e75a8e61148e81d6286b7bdfe737a0b99104f9b04deeb4f392c72b63d8e3d00e556  busyboxconfig
-- 
2.13.5

---