Преглед изворни кода

Port better to old Linux kernels

Problem reported by Igor Ivanov in:
https://mm.icann.org/pipermail/tz/2022-October/032192.html
* NEWS: Mention this.
* zic.c (get_rand_u64): Don’t use clock_gettime; it’s too much of
a configuration hassle.
Paul Eggert пре 3 година
родитељ
комит
317cc2c05a
2 измењених фајлова са 5 додато и 15 уклоњено
  1. 2 3
      NEWS
  2. 3 12
      zic.c

+ 2 - 3
NEWS

@@ -7,9 +7,8 @@ Unreleased, experimental changes
     Fix bug in zdump's tzalloc emulation on hosts that lack tm_zone.
     (Problem reported by Đoàn Trần Công Danh.)
 
-    Fix zic's default configuration to not use getrandom on macOS,
-    which has sys/random.h but lacks getrandom.  (Problem reported by
-    Gilmore Davidson.)
+    Fix zic configuration to avoid linkage failures on some platforms.
+    (Problems reported by Gilmore Davidson and Igor Ivanov.)
 
   Changes to build procedure
 

+ 3 - 12
zic.c

@@ -1210,21 +1210,12 @@ get_rand_u64(void)
 #endif
 
   /* getrandom didn't work, so fall back on portable code that is
-     not the best because the seed doesn't necessarily have enough bits,
-     the seed isn't cryptographically random on platforms lacking
-     getrandom, and 'rand' might not be cryptographically secure.  */
+     not the best because the seed isn't cryptographically random and
+     'rand' might not be cryptographically secure.  */
   {
     static bool initialized;
     if (!initialized) {
-      unsigned seed;
-#ifdef CLOCK_REALTIME
-      struct timespec now;
-      clock_gettime (CLOCK_REALTIME, &now);
-      seed = now.tv_sec ^ now.tv_nsec;
-#else
-      seed = time(NULL);
-#endif
-      srand(seed);
+      srand(time(NULL));
       initialized = true;
     }
   }