+cleanup of dead sandbox children
authorshort <>
Tue, 17 Jun 2003 08:19:28 +0000 (08:19 +0000)
committershort <>
Tue, 17 Jun 2003 08:19:28 +0000 (08:19 +0000)
src/libcaptive/client/vfs.h
src/libcaptive/sandbox/parent-Vfs.c
src/libcaptive/sandbox/split.c
src/libcaptive/sandbox/split.h

index c9ce143..2f5b510 100644 (file)
@@ -40,6 +40,7 @@ struct _CaptiveVfsObject {
                Captive_GLogFunc corba_GLogFunc_object;
                Captive_CaptiveIOChannel corba_CaptiveIOChannel_object;
                int corba_parentheart_fds_1;
+               pid_t corba_child_pid;
        };
 struct _CaptiveVfsObjectClass {
        GObjectClass parent_class;
index c693f82..fc0fe68 100644 (file)
@@ -27,6 +27,8 @@
 #include <unistd.h>
 #include "server-GLogFunc.h"
 #include "server-CaptiveIOChannel.h"
+#include <signal.h>    /* for kill(2) */
+#include <wait.h>
 
 
 GnomeVFSResult captive_sandbox_parent_vfs_new(CaptiveVfsObject *captive_vfs_object)
@@ -42,7 +44,8 @@ gboolean errbool;
                        &captive_vfs_object->corba_Vfs_object,  /* corba_Vfs_object_return */
                        &captive_vfs_object->corba_GLogFunc_object,     /* corba_GLogFunc_object_return */
                        &captive_vfs_object->corba_CaptiveIOChannel_object,     /* corba_CaptiveIOChannel_object_return */
-                       &captive_vfs_object->corba_parentheart_fds_1);  /* parentheart_fds_1_return */
+                       &captive_vfs_object->corba_parentheart_fds_1,   /* parentheart_fds_1_return */
+                       &captive_vfs_object->corba_child_pid);  /* child_pid_return */
        g_return_val_if_fail(errbool==TRUE,GNOME_VFS_ERROR_GENERIC);
 
        return GNOME_VFS_OK;
@@ -64,7 +67,7 @@ impl_POA_Captive_CaptiveIOChannel *CaptiveIOChannel_servant;
        CORBA_Object_release(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
-       /* Shutdown 'GLogFunc' servant */
+       /* Shutdown 'GLogFunc' servant. */
        GLogFunc_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
                        captive_vfs_object->corba_GLogFunc_object,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
@@ -73,7 +76,7 @@ impl_POA_Captive_CaptiveIOChannel *CaptiveIOChannel_servant;
        impl_Captive_GLogFunc__destroy(GLogFunc_servant,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
-       /* Shutdown 'CaptiveIOChannel' servant */
+       /* Shutdown 'CaptiveIOChannel' servant. */
        CaptiveIOChannel_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
                        captive_vfs_object->corba_CaptiveIOChannel_object,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
@@ -82,10 +85,28 @@ impl_POA_Captive_CaptiveIOChannel *CaptiveIOChannel_servant;
        impl_Captive_CaptiveIOChannel__destroy(CaptiveIOChannel_servant,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
+       /* Close parentheart_fd_write. */
        if (captive_vfs_object->corba_parentheart_fds_1!=-1) {
-               errint=close(captive_vfs_object->corba_parentheart_fds_1);      /* close parentheart_fd_write */
+               errint=close(captive_vfs_object->corba_parentheart_fds_1);
                g_return_val_if_fail(errint==0,FALSE);
                }
 
+       /* Cleanup the child process. */
+       if (captive_vfs_object->corba_child_pid!=(pid_t)-1) {
+               /*
+                *
+                *
+                *
+                *
+                */
+               kill(captive_vfs_object->corba_child_pid,SIGKILL);      /* errors ignored */
+               /*
+                *
+                */
+               waitpid(captive_vfs_object->corba_child_pid,
+                               NULL,   /* status */
+                               WNOHANG);       /* options */
+               }
+
        return r;
 }
index bdb9dc4..0c84c2e 100644 (file)
@@ -441,6 +441,7 @@ int errint;
        g_return_if_fail(Vfs_IOR!=NULL);
        g_return_if_fail(corba_Vfs_object_return!=NULL);
        g_return_if_fail(corba_GLogFunc_object_return!=NULL);
+       g_return_if_fail(corba_CaptiveIOChannel_object_return!=NULL);
 
        Vfs_object=CORBA_ORB_string_to_object(captive_corba_orb,Vfs_IOR,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
@@ -577,7 +578,8 @@ char *endptr;
 
 gboolean captive_sandbox_spawn(CaptiveVfsObject *child_captive_vfs_object,
                Captive_Vfs *corba_Vfs_object_return,Captive_GLogFunc *corba_GLogFunc_object_return,
-               Captive_CaptiveIOChannel *corba_CaptiveIOChannel_object_return,int *parentheart_fds_1_return)
+               Captive_CaptiveIOChannel *corba_CaptiveIOChannel_object_return,int *parentheart_fds_1_return,
+               pid_t *child_pid_return)
 {
 /* Vfs_IOR_fds[0] for reading by sandbox_parent() - client,
  * Vfs_IOR_fds[1] for writing by sandbox_child()  - server
@@ -589,6 +591,7 @@ int errint;
        g_return_val_if_fail(corba_Vfs_object_return!=NULL,FALSE);
        g_return_val_if_fail(corba_GLogFunc_object_return!=NULL,FALSE);
        g_return_val_if_fail(parentheart_fds_1_return!=NULL,FALSE);
+       g_return_val_if_fail(child_pid_return!=NULL,FALSE);
 
        errint=pipe(Vfs_IOR_fds);
        g_return_val_if_fail(errint==0,FALSE);
@@ -603,6 +606,7 @@ int errint;
        if (child_captive_vfs_object->options.sandbox_server_ior) {
                g_assert(child_captive_vfs_object->options.sandbox_server_argv==NULL);
                *parentheart_fds_1_return=-1;
+               *child_pid_return=-1;
                sandbox_parent(
                                child_captive_vfs_object->options.sandbox_server_ior,   /* Vfs_IOR */
                                NULL,   /* child_chroot_pid_hashkey_dir */
@@ -614,7 +618,7 @@ int errint;
                }
 
        g_assert(child_captive_vfs_object->options.sandbox_server_argv!=NULL);
-       switch (fork()) {
+       switch ((*child_pid_return=fork())) {
                case -1:        /* error */
                        g_return_val_if_reached(FALSE);
 
index 7d02def..e44e52f 100644 (file)
@@ -43,7 +43,8 @@ void sandbox_child_shutdown(void);
 #ifdef ORBIT2  /* Prevent missing $(ORBIT_CFLAGS) outside of libcaptive/sandbox/ */
 gboolean captive_sandbox_spawn(CaptiveVfsObject *child_captive_vfs_object,
                Captive_Vfs *corba_Vfs_object_return,Captive_GLogFunc *corba_GLogFunc_object_return,
-               Captive_CaptiveIOChannel *corba_CaptiveIOChannel_object_return,int *parentheart_fds_1_return);
+               Captive_CaptiveIOChannel *corba_CaptiveIOChannel_object_return,int *parentheart_fds_1_return,
+               pid_t *child_pid_return);
 gboolean validate_CORBA_Environment(CORBA_Environment *evp);
 GnomeVFSResult captive_sandbox_parent_return_from_CORBA_Environment(CORBA_Environment *evp);
 void captive_sandbox_child_GnomeVFSResultException_throw(CORBA_Environment *evp,GnomeVFSResult errvfsresult);