Patchwork Force rereading TZDEFRULES after it was used to set DST rules only (bug #19253)

login
register
mail settings
Submitter Andreas Schwab
Date Nov. 17, 2015, 12:57 p.m.
Message ID <mvmk2pgu6jt.fsf@hawking.suse.de>
Download mbox | patch
Permalink /patch/9699/
State New
Headers show

Comments

Andreas Schwab - Nov. 17, 2015, 12:57 p.m.
Actually we can test it.

Andreas.

	[BZ #19253]
	* time/tzfile.c (__tzfile_default): Invalidate tzfile attribute
	cache when TZDEFRULES was used.
	* time/tst-tzname.c: New file.
	* time/Makefile (test): Add tst-tzname.
	* timezone/Makefile (test-zones): Add $(posixrules-file).
	($(testdata)/$(posixrules-file)): New rule.
---
 time/Makefile     |  3 ++-
 time/tst-tzname.c | 33 +++++++++++++++++++++++++++++++++
 time/tzfile.c     |  6 ++++++
 timezone/Makefile |  5 ++++-
 4 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 time/tst-tzname.c

Patch

diff --git a/time/Makefile b/time/Makefile
index 933e70e..d029993 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -37,7 +37,8 @@  aux :=	    era alt_digit lc-time-cleanup
 tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
 	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
-	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime
+	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
+	   tst-tzname
 
 include ../Rules
 
diff --git a/time/tst-tzname.c b/time/tst-tzname.c
new file mode 100644
index 0000000..7ac7184
--- /dev/null
+++ b/time/tst-tzname.c
@@ -0,0 +1,33 @@ 
+/* Test that tzset sets tzname correctly (BZ #19253). */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+static int
+do_test (void)
+{
+  int result = 0;
+
+  setenv ("TZ", "posixrules", 1);
+  tzset ();
+  const char *stdtz = strdup (tzname[0]);
+  setenv ("TZ", "STD-1DST", 1);
+  tzset ();
+  if (strcmp (tzname[0], "STD") != 0)
+    {
+      printf ("FAIL: TZ=STD-1DST, tzname[0] = %s\n", tzname[0]);
+      result = 1;
+    }
+  setenv ("TZ", "posixrules", 1);
+  tzset ();
+  if (strcmp (tzname[0], stdtz) != 0)
+    {
+      printf ("FAIL: TZ=posixrules, tzname[0] = %s\n", tzname[0]);
+      result = 1;
+    }
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/time/tzfile.c b/time/tzfile.c
index 57abbb8..0e581f2 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -628,6 +628,12 @@  __tzfile_default (const char *std, const char *dst,
   __timezone = -types[0].offset;
 
   compute_tzname_max (stdlen + dstlen);
+
+  /* Invalidate the tzfile attribute cache to force rereading
+     TZDEFRULES the next time it is used.  */
+  tzfile_dev = 0;
+  tzfile_ino = 0;
+  tzfile_mtime = 0;
 }
 
 void
diff --git a/timezone/Makefile b/timezone/Makefile
index 99566cb..754b49c 100644
--- a/timezone/Makefile
+++ b/timezone/Makefile
@@ -42,7 +42,8 @@  ifeq ($(run-built-tests),yes)
 # List zones generated by separate commands running zic on the host.
 # Each such zic run counts as a separate test.
 test-zones := America/New_York Etc/UTC UTC Europe/Berlin \
-	      Australia/Melbourne America/Sao_Paulo Asia/Tokyo
+	      Australia/Melbourne America/Sao_Paulo Asia/Tokyo \
+	      $(posixrules-file)
 tests-special += $(addprefix $(testdata)/, $(test-zones))
 endif
 
@@ -96,6 +97,8 @@  zic-deps = $(objpfx)zic $(leapseconds) yearistype
 
 $(testdata)/America/New_York: northamerica $(zic-deps)
 	$(build-testdata)
+$(testdata)/$(posixrules-file): $(testdata)/America/New_York
+	$(make-link)
 $(testdata)/Etc/UTC: etcetera $(zic-deps)
 	$(build-testdata)
 # Use a pattern rule to indicate the command produces both targets at once.