Stop checking for fork() across GMainContext
authorRyan Lortie <desrt@desrt.ca>
Fri, 14 Oct 2011 23:41:08 +0000 (19:41 -0400)
committerRyan Lortie <desrt@desrt.ca>
Sat, 15 Oct 2011 00:01:22 +0000 (20:01 -0400)
01ed78d525cf2f8769022e27cc2573ec7ba123b3 introduced assertion checks for
creating a main context, forking, and attempting to use the main context
from the child side of the fork.

Some code (such as gnome-keyring-daemon) daemonise after calling
GMainContext.  That's probably still mostly safe since we still only
have one side of the fork touching the context afterwards.

This use case is still troubling, however, since if any worker threads
have been created at the time of the fork(), we could end up in the
classic situation of leaving some mutexes in a locked state when the
other threads disappear from the copy of the image that the child gets.

This will require some deeper thinking...

glib/gmain.c

index df87f90..6a7cfc0 100644 (file)
@@ -378,7 +378,6 @@ static gboolean g_idle_dispatch    (GSource     *source,
                                    gpointer     user_data);
 
 static GMainContext *glib_worker_context;
-static gboolean      g_main_context_fork_detected;
 
 G_LOCK_DEFINE_STATIC (main_loop);
 static GMainContext *default_main_context;
@@ -500,14 +499,6 @@ g_main_context_unref (GMainContext *context)
   g_free (context);
 }
 
-#ifdef G_OS_UNIX
-static void
-g_main_context_forked (void)
-{
-  g_main_context_fork_detected = TRUE;
-}
-#endif
-
 /**
  * g_main_context_new:
  * 
@@ -528,10 +519,6 @@ g_main_context_new (void)
         _g_main_poll_debug = TRUE;
 #endif
 
-#ifdef G_OS_UNIX
-      pthread_atfork (NULL, NULL, g_main_context_forked);
-#endif
-
       g_once_init_leave (&initialised, TRUE);
     }
 
@@ -3000,7 +2987,6 @@ g_main_context_iterate (GMainContext *context,
   if (!block)
     timeout = 0;
   
-  g_assert (!g_main_context_fork_detected);
   g_main_context_poll (context, timeout, max_priority, fds, nfds);
   
   some_ready = g_main_context_check (context, max_priority, fds, nfds);