aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorPaul Eggert2014-10-11 23:09:50 -0700
committerPaul Eggert2014-10-11 23:09:50 -0700
commit4c4c5b9121a550d006d1b57bc2ad97b0415cee9f (patch)
tree3b5921413aeaa73741d0a234572f151a05e6f7bd /src/dbusbind.c
parentc1ec59da4905015d841ffeba9bb53a674b3a44f4 (diff)
downloademacs-4c4c5b9121a550d006d1b57bc2ad97b0415cee9f.tar.gz
emacs-4c4c5b9121a550d006d1b57bc2ad97b0415cee9f.zip
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/dbusbind.c')
-rw-r--r--src/dbusbind.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index f81666ba7bd..4852739d8e4 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -1054,6 +1054,7 @@ xd_remove_watch (DBusWatch *watch, void *data)
1054 1054
1055 /* Unset session environment. */ 1055 /* Unset session environment. */
1056#if 0 1056#if 0
1057 /* This is buggy, since unsetenv is not thread-safe. */
1057 if (XSYMBOL (QCdbus_session_bus) == data) 1058 if (XSYMBOL (QCdbus_session_bus) == data)
1058 { 1059 {
1059 XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS"); 1060 XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS");
@@ -1219,9 +1220,6 @@ this connection to those buses. */)
1219 XSETFASTINT (val, (intptr_t) connection); 1220 XSETFASTINT (val, (intptr_t) connection);
1220 xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); 1221 xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses);
1221 1222
1222 /* We do not want to abort. */
1223 xputenv ("DBUS_FATAL_WARNINGS=0");
1224
1225 /* Cleanup. */ 1223 /* Cleanup. */
1226 dbus_error_free (&derror); 1224 dbus_error_free (&derror);
1227 } 1225 }
@@ -1738,6 +1736,13 @@ xd_read_queued_messages (int fd, void *data)
1738 1736
1739 1737
1740void 1738void
1739init_dbusbind (void)
1740{
1741 /* We do not want to abort. */
1742 xputenv ("DBUS_FATAL_WARNINGS=0");
1743}
1744
1745void
1741syms_of_dbusbind (void) 1746syms_of_dbusbind (void)
1742{ 1747{
1743 1748