ORBit SIGCHLD fix



This makes CORBA_Object_non_existent protect itself against
applications with SIGCHLD handlers that do waitpid(-1, ...).

(It also deals with waitpid() being interrupted by a signal.)

OK to commit (and to pull up to the stable branch afterward)?

Index: src/orb/corba_object.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/corba_object.c,v
retrieving revision 1.25
diff -u -r1.25 corba_object.c
--- src/orb/corba_object.c	2000/08/02 23:30:45	1.25
+++ src/orb/corba_object.c	2000/12/14 15:01:59
@@ -30,6 +30,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <errno.h>
 
 /* Section 4.2.1 */
 CORBA_InterfaceDef CORBA_Object_get_interface(CORBA_Object obj, CORBA_Environment *ev)
@@ -231,6 +232,7 @@
 CORBA_boolean CORBA_Object_non_existent(CORBA_Object obj, CORBA_Environment *ev)
 {
   int childpid, exitstatus, itmp;
+  sigset_t mask, omask;
 
   ev->_major = CORBA_NO_EXCEPTION;
 
@@ -243,6 +245,11 @@
   if(obj->connection && obj->connection->is_valid)
 	  return FALSE;
 
+  /* Block SIGCHLD so no one else can wait() on the child before we do. */
+  sigemptyset(&mask);
+  sigaddset(&mask, SIGCHLD);
+  sigprocmask(SIG_BLOCK, &mask, &omask);
+
   childpid = fork();
 
   if(!childpid) {
@@ -260,7 +267,9 @@
 	  _exit((cnx == NULL)?1:0);
   }
 
-  itmp = waitpid(childpid, &exitstatus, 0);
+  while ((itmp = waitpid(childpid, &exitstatus, 0)) == -1 && errno == EINTR)
+	  ;
+  sigprocmask (SIG_SETMASK, &omask, NULL);
 
   if(itmp < 0) return TRUE;
   return WEXITSTATUS(exitstatus) && TRUE;




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