This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Reread /etc/localtime even if just mtime changed


Hi!

If /etc/localtime is a symlink or hardlink to /usr/share/zoneinfo/something,
the dev/ino test is sufficient.
But on some systems /etc/localtime is a copy of the zoneinfo file for
the chosen timezone (e.g. so that /etc/localtime is usable even when /usr
is not mounted), and there timezone changes are done just by overwriting
that file.  That doesn't change dev/ino, just mtime.
As we already fstat64 the file, comparing mtime is almost for free.

2004-09-29  Jakub Jelinek  <jakub@redhat.com>

	* time/tzfile.c (tzfile_mtime): New variable.
	(__tzfile_read): Reread the file if mtime is different.

--- libc/time/tzfile.c.jj	2004-08-11 21:25:51.000000000 +0200
+++ libc/time/tzfile.c	2004-09-29 11:55:55.525516513 +0200
@@ -32,6 +32,7 @@
 int __use_tzfile;
 static dev_t tzfile_dev;
 static ino64_t tzfile_ino;
+static time_t tzfile_mtime;
 
 struct ttinfo
   {
@@ -161,7 +162,8 @@ __tzfile_read (const char *file, size_t 
       fclose (f);
       goto ret_free_transitions;
     }
-  if (was_using_tzfile && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev)
+  if (was_using_tzfile && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev
+      && tzfile_mtime == st.st_mtime)
     {
       /* It's the same file.  No further work needed.  */
       fclose (f);
@@ -172,9 +174,10 @@ __tzfile_read (const char *file, size_t 
   free ((void *) transitions);
   transitions = NULL;
 
-  /* Remember the inode and device number.  */
+  /* Remember the inode and device number and modification time.  */
   tzfile_dev = st.st_dev;
   tzfile_ino = st.st_ino;
+  tzfile_mtime = st.st_mtime;
 
   /* No threads reading this stream.  */
   __fsetlocking (f, FSETLOCKING_BYCALLER);

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]