Procházet zdrojové kódy

libdpkg: Fix crashes on Mac OS X when using first gettext() after fork()

On Mac OS X, the libintl code needs to call into the CoreFoundation
framework, which is internally threaded, to initialize some caches.
This is a problem when that first call is done after a fork(3),
because per POSIX, only one thread will survive, leaving the
process in a very inconsistent state, leading to crashes.

To workaround this, we try to force the caches initialization
at program startup time, by performing a dummy gettext("") call.

Tested-by: Martin Costabel <costabel@wanadoo.fr>
Guillem Jover před 12 roky
rodič
revize
4b924a7b47
2 změnil soubory, kde provedl 17 přidání a 0 odebrání
  1. 3 0
      debian/changelog
  2. 14 0
      lib/dpkg/i18n.c

+ 3 - 0
debian/changelog

@@ -84,6 +84,9 @@ dpkg (1.17.2) UNRELEASED; urgency=low
   * Add new dir_to_symlink command to dpkg-maintscript-helper. Closes: #583585
   * Distinguish dpkg error reports between errors while processing packages
     and archives.
+  * Fix crashes in the first call to gettext() after fork() on Mac OS X, by
+    forcing the initialization at program start of the CoreFoundation cached
+    values in libintl.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 14 - 0
lib/dpkg/i18n.c

@@ -29,4 +29,18 @@ dpkg_locales_init(const char *package)
 	setlocale(LC_ALL, "");
 	bindtextdomain(package, LOCALEDIR);
 	textdomain(package);
+
+#if defined(__APPLE__) && defined(__MACH__)
+	/*
+	 * On Mac OS X, the libintl code needs to call into the CoreFoundation
+	 * framework, which is internally threaded, to initialize some caches.
+	 * This is a problem when that first call is done after a fork(3),
+	 * because per POSIX, only one thread will survive, leaving the
+	 * process in a very inconsistent state, leading to crashes.
+	 *
+	 * XXX: To workaround this, we try to force the caches initialization
+	 * at program startup time, by performing a dummy gettext() call.
+	 */
+	gettext("");
+#endif
 }