dbus/dbus dbus-spawn.c,1.20,1.21

Ray Strode halfline at freedesktop.org
Tue Jun 28 08:14:23 PDT 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv25107/dbus

Modified Files:
	dbus-spawn.c 
Log Message:
2005-06-28  Ray Strode  <rstrode at redhat.com>

	*  dbus/dbus-spawn.c (_dbus_babysitter_unref): kill
	babysitter helper process on last unref, bug #2813.


Index: dbus-spawn.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-spawn.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus-spawn.c	10 Nov 2004 20:12:15 -0000	1.20
+++ dbus-spawn.c	28 Jun 2005 15:14:21 -0000	1.21
@@ -252,6 +252,9 @@
 
 /**
  * Decrement the reference count on the babysitter object.
+ * When the reference count of the babysitter object reaches
+ * zero, the babysitter is killed and the child that was being
+ * babysat gets emancipated.
  *
  * @param sitter the babysitter
  */
@@ -266,6 +269,13 @@
     {      
       if (sitter->socket_to_babysitter >= 0)
         {
+          /* If we haven't forked other babysitters
+           * since this babysitter and socket were
+           * created then this close will cause the
+           * babysitter to wake up from poll with
+           * a hangup and then the babysitter will
+           * quit itself.
+           */
           close (sitter->socket_to_babysitter);
           sitter->socket_to_babysitter = -1;
         }
@@ -276,14 +286,27 @@
           sitter->error_pipe_from_child = -1;
         }
 
-      if (sitter->sitter_pid != -1)
+      if (sitter->sitter_pid > 0)
         {
           int status;
           int ret;
 
-          /* Reap the babysitter */
+          /* It's possible the babysitter died on its own above 
+           * from the close, or was killed randomly
+           * by some other process, so first try to reap it
+           */
+          ret = waitpid (sitter->sitter_pid, &status, WNOHANG);
+
+          /* If we couldn't reap the child then kill it, and
+           * try again
+           */
+          if (ret == 0)
+            kill (sitter->sitter_pid, SIGKILL);
+
         again:
-          ret = waitpid (sitter->sitter_pid, &status, 0);
+          if (ret == 0)
+            ret = waitpid (sitter->sitter_pid, &status, 0);
+
           if (ret < 0)
             {
               if (errno == EINTR)



More information about the dbus-commit mailing list