Warning about reaped children



Hi,

I forgot to pass G_SPAWN_DO_NOT_REAP_CHILD to g_spawn_async_with_pipes()
and ended up scratching my head about why my GChildWatch callback wasn't
firing.  After some hot strace action and RTFM, I added that flag and
everything worked perfectly.  Do we need a warning like the one in the
attached patch?

  Federico
--- gmain.c~	2007-01-22 11:12:44.000000000 -0600
+++ gmain.c	2007-03-29 15:38:01.000000000 -0600
@@ -3605,12 +3605,21 @@ check_for_child_exited (GSource *source)
   if (child_watch_source->count < count)
     {
       gint child_status;
+      GPid pid;
 
-      if (waitpid (child_watch_source->pid, &child_status, WNOHANG) > 0)
+      pid = waitpid (child_watch_source->pid, &child_status, WNOHANG);
+
+      if (pid > 0)
 	{
 	  child_watch_source->child_status = child_status;
 	  child_watch_source->child_exited = TRUE;
 	}
+      else if (pid == -1 && errno == ECHILD)
+	g_warning ("waitpid() for process %d returned ECHILD.  Did you launch the process "
+		   "with g_spawn_async*() but forget to pass G_SPAWN_DO_NOT_REAP_CHILD? "
+		   "The notification about child termination will not be emitted!",
+		   child_watch_source->pid);
+      
       child_watch_source->count = count;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]