changeset 5277:f7cc2b4c10d8

7149608: Default TZ detection fails on linux when symbolic links to non default location used. Reviewed-by: alanb, okutsu
author coffeys
date Thu, 07 Jun 2012 17:38:57 +0100
parents 15435b9b51ec
children cbd726c8b322
files src/solaris/native/java/util/TimeZone_md.c
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/util/TimeZone_md.c	Wed Jun 06 21:56:14 2012 -0700
+++ b/src/solaris/native/java/util/TimeZone_md.c	Thu Jun 07 17:38:57 2012 +0100
@@ -96,9 +96,9 @@
 /*
  * Scans the specified directory and its subdirectories to find a
  * zoneinfo file which has the same content as /etc/localtime on Linux
- * or /usr/share/lib/zoneinfo/localtime (most likely a symbolic link)
- * on Solaris given in 'buf'. Returns a zone ID if found, otherwise,
- * NULL is returned.
+ * or /usr/share/lib/zoneinfo/localtime on Solaris given in 'buf'.
+ * If file is symbolic link, then the contents it points to are in buf.
+ * Returns a zone ID if found, otherwise, NULL is returned.
  */
 static char *
 findZoneinfoFile(char *buf, size_t size, const char *dir)
@@ -281,21 +281,27 @@
         tz = getZoneName(linkbuf);
         if (tz != NULL) {
             tz = strdup(tz);
+            return tz;
         }
-        return tz;
     }
 
     /*
      * If it's a regular file, we need to find out the same zoneinfo file
      * that has been copied as /etc/localtime.
+     * If initial symbolic link resolution failed, we should treat target
+     * file as a regular file.
      */
+    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
+        return NULL;
+    }
+    if (fstat(fd, &statbuf) == -1) {
+        (void) close(fd);
+        return NULL;
+    }
     size = (size_t) statbuf.st_size;
     buf = (char *) malloc(size);
     if (buf == NULL) {
-        return NULL;
-    }
-    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
-        free((void *) buf);
+        (void) close(fd);
         return NULL;
     }