diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-10-11 23:09:50 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-10-11 23:09:50 -0700 |
commit | 4c4c5b9121a550d006d1b57bc2ad97b0415cee9f (patch) | |
tree | 3b5921413aeaa73741d0a234572f151a05e6f7bd /src/systime.h | |
parent | c1ec59da4905015d841ffeba9bb53a674b3a44f4 (diff) | |
download | emacs-4c4c5b9121a550d006d1b57bc2ad97b0415cee9f.tar.gz |
Fix putenv race conditions with undefined behavior.
Do all putenv calls before Emacs creates any threads.
Use a safer way to modify the TZ environment variable in the
presence of multiple threads. For further thread-safety,
prefer localtime_r and gmtime_r to localtime and gmtime,
and prefer struct tm's tm_gmtoff (if available) to calling
both localtime_r and gmtime_r.
* configure.ac (LOCALTIME_CACHE): Remove.
We needn't worry about SunOS 4 any more; Sun dropped support in 2003.
All uses of LOCALTIME_CACHE removed. This simplifies the fix.
(tzalloc): Add check for this function.
* admin/merge-gnulib (GNULIB_MODULES): Add time_r, since Emacs now
calls localtime_r and gmtime_r directly.
* src/dbusbind.c (Fdbus__init_bus): Move xputenv call from here ...
(init_dbusbind): ... to this new function.
* src/emacs.c (main) [HAVE_DBUS]: Call it before creating threads.
* src/xterm.c (x_term_init): Move xputenv call from here ...
(init_xterm): ... to this new function.
* src/emacs.c (main) [USE_GTK]: Call it before creating threads.
* src/editfns.c (HAVE_TM_GMTOFF): Default to false.
(dump_tz_string): New constant.
(init_editfns): Use it. This centralizes the dump_tz stuff.
Call set_time_zone_rule here, so that its xputenv is done
before Emacs goes multithreaded.
(mktime_z) [!HAVE_TZALLOC]: New function, which is typically
thread-safe enough for Emacs.
(format_time_string, Fdecode_time, Fcurrent_time_string)
(Fcurrent_time_zone):
Prefer localtime_r and gmtime_r, which are more thread-safe, to
localtime and gmtime. Remove now-unnecessary calls to block_input.
(tm_gmtoff): New static function.
(Fdecode_time, Fcurrent_time_zone): Use it.
(Fencode_time): Use mktime_z, for better thread-safety.
(set_time_zone_rule): Now static. Rewrite to be mostly thread-safe,
i.e., not quite thread-safe but good enough for Emacs typical usage.
Do not reclaim storage that is in the environment; let it leak.
Always call tzset, since localtime_r does not.
* src/emacs.c (dump_tz, Fdump_emacs) [HAVE_TZSET]: Remove dump_tz stuff.
This is now done in init_editfns.
* src/systime.h (mktime_z, timezone_t, tzalloc, tzfree) [!HAVE_TZALLOC]:
New macros and declarations, for platforms lacking tzalloc & friends.
Fixes: debbugs:8705
Diffstat (limited to 'src/systime.h')
-rw-r--r-- | src/systime.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/systime.h b/src/systime.h index a834bce76dc..8f018044660 100644 --- a/src/systime.h +++ b/src/systime.h @@ -93,6 +93,22 @@ extern bool decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, extern struct timespec lisp_time_argument (Lisp_Object); #endif +#ifndef HAVE_TZALLOC +# undef mktime_z +# undef timezone_t +# undef tzalloc +# undef tzfree +# define mktime_z emacs_mktime_z +# define timezone_t emacs_timezone_t +# define tzalloc emacs_tzalloc +# define tzfree emacs_tzfree +typedef char const *timezone_t; +INLINE timezone_t tzalloc (char const *name) { return name; } +INLINE void tzfree (timezone_t tz) { } +/* Defined in editfns.c. */ +extern time_t mktime_z (timezone_t, struct tm *); +#endif + INLINE_HEADER_END #endif /* EMACS_SYSTIME_H */ |