Subject: bug#14569: 24.3.50; bootstrap fails on Cygwin

From: Ken Brown <[email-masked]>
Date: Fri, 28 Jun 2013 17:40:38 -0400

On 6/28/2013 11:29 AM, Ken Brown wrote:
> I don't know, because I don't know when the race during bootstrapping 
> was happening.  If it was happening when emacs was doing the tickling 
> (in init_process_emacs), then my suggested change could conceivably 
> cause emacs to crash immediately after startup.  Assuming this doesn't 
> happen often, I think it's better than having bugs in subprocess handling.
> 
> On the other hand, if the race happens when emacs *executes* the glib 
> handler (stored in lib_child_handler), then I agree with you that my 
> proposal is unacceptable.

I've done some further testing [*] and determined that the bootstrap failures always occur as a result of the tickling, as I had hoped.  This should mean that, if my patch is applied, the only problem will be a possible random crash right after emacs is started.  The only question is how often this will happen in practice.  I think we can only determine this by applying the patch and asking users to test it.

Ken

[*] I tested this by applying the following patch and then bootstrapping:

=== modified file 'src/process.c'
--- src/process.c       2013-06-27 14:47:52 +0000
+++ src/process.c       2013-06-28 21:30:27 +0000
@@ -7095,7 +7095,7 @@
   if (! noninteractive || initialized)
 #endif
     {
-#if defined HAVE_GLIB && !defined WINDOWSNT && !defined CYGWIN
+#if defined HAVE_GLIB && !defined WINDOWSNT
       /* Tickle glib's child-handling code.  Ask glib to wait for Emacs itself;
         this should always fail, but is enough to initialize glib's
         private SIGCHLD handler, allowing the code below to copy it into
@@ -7105,6 +7105,9 @@
         skipped under Cygwin.  FIXME: Skipping the tickling likely causes
         bugs in subprocess handling under Cygwin (Bug#14569).  */
       g_source_unref (g_child_watch_source_new (getpid ()));
+      fprintf (stderr, "Glib has been tickled.\n");
+      sleep (1);
+      fprintf (stderr, "Calling catch_child_signal.\n");
 #endif
       catch_child_signal ();
     }

Every error that occurred was like the following:

Compiling obsolete/pgg.el
Glib has been tickled.
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_setspecific': Invalid argument.  Aborting.
Makefile:251: recipe for target `obsolete/pgg.elc' failed
make[2]: *** [obsolete/pgg.elc] Aborted