Simplified captive_sandbox_spawn() prototype.
authorshort <>
Fri, 4 Jul 2003 04:51:56 +0000 (04:51 +0000)
committershort <>
Fri, 4 Jul 2003 04:51:56 +0000 (04:51 +0000)
Implemented 3-stage image_iochannel GIOChannel sequence for commits.
validate_CORBA_Environment(): CORBA Exception reporting is fatal
 - all its callers considered such case fatal anyway
corba_shutdown(): CORBA_ORB_destroy() errors ignored
 - it sometimes reports: a total of X refs to X ORB objects were leaked
   - FIXME - 1 ref per each sandbox child failure-restart cycle; why?
Disabled sandbox child shutdown process exit as it is killed by its parent
 - otherwise COMM_FAILURE occured on shutdown() method call by parent
Fixed heartbeat disable by sandbox_child_prepare_shutdown()
captive_sandbox_parent_query_vfs_retry(): Fixed exception memory leak

src/libcaptive/sandbox/split.c

index 2aa1b21..30ddca8 100644 (file)
@@ -50,8 +50,9 @@ gboolean validate_CORBA_Environment(CORBA_Environment *evp)
        if (evp->_major==CORBA_NO_EXCEPTION)
                return TRUE;
 
-       g_message(_("CORBA Exception occured: id=\"%s\", value=%p"),
+       g_error(_("CORBA Exception occured: id=\"%s\", value=%p"),
                        CORBA_exception_id(evp),CORBA_exception_value(evp));
+       CORBA_exception_free(evp);
        return FALSE;
 }
 
@@ -126,7 +127,11 @@ CORBA_ORB orb;
        *orbp=CORBA_OBJECT_NIL;
        heartbeat_source_callback_orb=CORBA_OBJECT_NIL;
        CORBA_ORB_destroy(orb,evp);
-       g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+       /* Do not: g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+        * here as CORBA_ORB_destroy() sometimes reports:
+        *      WARNING **: ORB: a total of X refs to X ORB objects were leaked
+        */
+       CORBA_exception_free(evp);
 
        /* Shutdown 'ev' */
        CORBA_exception_free(evp);
@@ -145,6 +150,7 @@ gboolean errbool;
 
 static GSource *captive_corba_sandbox_child_heartbeat_gsource;
 
+#if 0  /* Currently unused - see server-Vfs.c:impl_Captive_Vfs_shutdown() */
 void sandbox_child_prepare_shutdown(void)
 {
        /* Prevent during shutdown: Captive-WARNING **: CORBA Exception occured: id="IDL:omg.org/CORBA/COMM_FAILURE:1.0" */
@@ -154,6 +160,7 @@ void sandbox_child_prepare_shutdown(void)
                captive_corba_sandbox_child_heartbeat_gsource=NULL;
                }
 }
+#endif
 
 
 void sandbox_child_shutdown(void)
@@ -208,23 +215,22 @@ Captive_Vfs Vfs_object;
 impl_POA_Captive_Vfs *Vfs_servant;
 gboolean errbool;
 guint errguint;
-GSource *gsource;
 int errint;
 
        /* attach heartbeat_source_callback() to watch for any abnormalities
         * on our open pipe 'parentheart_fds' and terminate the child if parent dies.
         */
-       gsource=g_source_new(&heartbeat_source_watch_funcs,sizeof(GSource));
-       g_return_if_fail(gsource!=NULL);
+       captive_corba_sandbox_child_heartbeat_gsource=g_source_new(&heartbeat_source_watch_funcs,sizeof(GSource));
+       g_return_if_fail(captive_corba_sandbox_child_heartbeat_gsource!=NULL);
        g_source_set_callback(
-                       gsource,        /* source */
+                       captive_corba_sandbox_child_heartbeat_gsource,  /* source */
                        heartbeat_source_callback,      /* func */
                        NULL,   /* data */
                        NULL);  /* notify */
        heartbeat_source_check_gpollfd.fd=0 /* STDIN */;        /* parentheart_fd_read */
        heartbeat_source_check_gpollfd.events=HEARTBEAT_SOURCE_CHECK_EVENTS;
        heartbeat_source_check_gpollfd.revents=0;
-       g_source_add_poll(gsource,&heartbeat_source_check_gpollfd);
+       g_source_add_poll(captive_corba_sandbox_child_heartbeat_gsource,&heartbeat_source_check_gpollfd);
 
        errbool=corba_init("captive-sandbox-child",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
        g_return_if_fail(errbool==TRUE);
@@ -233,7 +239,7 @@ int errint;
 
        /* linc_main_get_loop() makes sense only after corba_init() -> CORBA_ORB_init() */
        errguint=g_source_attach(
-                       gsource,        /* source */
+                       captive_corba_sandbox_child_heartbeat_gsource,  /* source */
                        g_main_loop_get_context(linc_main_get_loop())); /* context; NULL means 'default context' */
        g_assert(errguint!=0);
 
@@ -425,10 +431,7 @@ const gchar *chrooted_orbit_dir;
 }
 
 
-static void sandbox_parent(const gchar *Vfs_IOR,const gchar *child_chroot_pid_hashkey_dir,
-               struct captive_options *options_captive,Captive_Vfs *corba_Vfs_object_return,
-               Captive_GLogFunc *corba_GLogFunc_object_return,Captive_CaptiveIOChannel *corba_CaptiveIOChannel_object_return,
-               GIOChannel **corba_parent_giochanel_blind_ptr)
+static void sandbox_parent(const gchar *Vfs_IOR,const gchar *child_chroot_pid_hashkey_dir,CaptiveVfsObject *captive_vfs_object)
 {
 Captive_Vfs Vfs_object;
 Captive_GLogFunc GLogFunc_object;
@@ -441,9 +444,8 @@ const gchar *child_chroot_parent_own_orbit_socket,*child_chroot_parent_own_orbit
 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);
+       /* 'child_chroot_pid_hashkey_dir' may be NULL */
+       g_return_if_fail(captive_vfs_object!=NULL);
 
        Vfs_object=CORBA_ORB_string_to_object(captive_corba_orb,Vfs_IOR,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
@@ -453,10 +455,25 @@ int errint;
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
        /* Init 'CaptiveIOChannel_object' */
-       if (!*corba_parent_giochanel_blind_ptr)
-               *corba_parent_giochanel_blind_ptr=(GIOChannel *)captive_giochannel_blind_new(options_captive->image_iochannel);
+       if (!captive_vfs_object->corba_parent_giochanel_blind_source)
+               switch (captive_vfs_object->options.rwmode) {
+                       case CAPTIVE_OPTION_RWMODE_RO:
+                       case CAPTIVE_OPTION_RWMODE_RW:
+                               captive_vfs_object->corba_parent_giochanel_blind_source=captive_vfs_object->options.image_iochannel;
+                               break;
+                       case CAPTIVE_OPTION_RWMODE_BLIND:
+                               captive_vfs_object->corba_parent_giochanel_blind_source=(GIOChannel *)captive_giochannel_blind_new(
+                                               captive_vfs_object->options.image_iochannel,    /* giochannel_orig */
+                                               TRUE); /* writeable */
+                               break;
+                       default: g_assert_not_reached();
+                       }
+       if (!captive_vfs_object->corba_parent_giochanel_blind)
+               captive_vfs_object->corba_parent_giochanel_blind=(GIOChannel *)captive_giochannel_blind_new(
+                               captive_vfs_object->corba_parent_giochanel_blind_source,  /* giochannel_orig */
+                               (captive_vfs_object->options.rwmode!=CAPTIVE_OPTION_RWMODE_RO)); /* writeable */
        CaptiveIOChannel_object=impl_Captive_CaptiveIOChannel__create(captive_corba_poa,
-                       *corba_parent_giochanel_blind_ptr,&captive_corba_ev);
+                       captive_vfs_object->corba_parent_giochanel_blind,&captive_corba_ev);
        g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
        /* Create the socket needed for 'sandbox_parent_own_orbit_socket' below
@@ -503,22 +520,22 @@ struct dirent *dirent;
                }
 
        options_corba.g_log_func=GLogFunc_object;
-       options_module_captive_to_options_module_corba(&options_corba.filesystem,&options_captive->filesystem);
+       options_module_captive_to_options_module_corba(&options_corba.filesystem,&captive_vfs_object->options.filesystem);
        /* Prevent secondary captive_giochannel_blind inside of our sandbox child
         * as we already have one captive_giochannel_blind in the parent.
         */
-       options_corba.rwmode        =(options_captive->rwmode == CAPTIVE_OPTION_RWMODE_BLIND ? CAPTIVE_OPTION_RWMODE_RW
-                       : options_captive->rwmode);
-       options_corba.media         =options_captive->media;
-       options_corba.debug_messages=options_captive->debug_messages;
+       options_corba.rwmode        =(captive_vfs_object->options.rwmode == CAPTIVE_OPTION_RWMODE_BLIND ? CAPTIVE_OPTION_RWMODE_RW
+                       : captive_vfs_object->options.rwmode);
+       options_corba.media         =captive_vfs_object->options.media;
+       options_corba.debug_messages=captive_vfs_object->options.debug_messages;
        options_corba.image_iochannel=CaptiveIOChannel_object;
 
-       load_module_length=g_list_length(options_captive->load_module);
+       load_module_length=g_list_length(captive_vfs_object->options.load_module);
        captive_newn(options_corba.load_module._buffer,load_module_length);
        options_corba.load_module._maximum=load_module_length;
        options_corba.load_module._length=load_module_length;
        options_corba.load_module._release=TRUE;
-       for (load_moduleui=0,load_module_node=options_captive->load_module;
+       for (load_moduleui=0,load_module_node=captive_vfs_object->options.load_module;
                        load_module_node;
                        load_moduleui++,load_module_node=load_module_node->next) {
                options_module=load_module_node->data;
@@ -530,9 +547,9 @@ struct dirent *dirent;
 
        /* FIXME: Free 'options_corba' - LEAK */
 
-       *corba_Vfs_object_return=Vfs_object;
-       *corba_GLogFunc_object_return=GLogFunc_object;
-       *corba_CaptiveIOChannel_object_return=CaptiveIOChannel_object;
+       captive_vfs_object->corba_Vfs_object=Vfs_object;
+       captive_vfs_object->corba_GLogFunc_object=GLogFunc_object;
+       captive_vfs_object->corba_CaptiveIOChannel_object=CaptiveIOChannel_object;
 }
 
 static void fd_shiftup(int *fdp)
@@ -584,10 +601,7 @@ char *endptr;
        close(dir_fd); g_assert(errno==EBADF);  /* just a bit of paranoia; it should be already closed by closedir() */
 }
 
-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,GIOChannel **corba_parent_giochanel_blind_ptr,
-               int *parentheart_fds_1_return,pid_t *child_pid_return)
+gboolean captive_sandbox_spawn(CaptiveVfsObject *captive_vfs_object)
 {
 /* Vfs_IOR_fds[0] for reading by sandbox_parent() - client,
  * Vfs_IOR_fds[1] for writing by sandbox_child()  - server
@@ -596,11 +610,7 @@ int Vfs_IOR_fds[2],parentheart_fds[2];
 int errint;
 gboolean errbool;
 
-       g_return_val_if_fail(child_captive_vfs_object!=NULL,FALSE);
-       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);
+       g_return_val_if_fail(captive_vfs_object!=NULL,FALSE);
 
        errint=pipe(Vfs_IOR_fds);
        g_return_val_if_fail(errint==0,FALSE);
@@ -612,27 +622,23 @@ gboolean errbool;
         *     g_assert(errbool==TRUE);
         */
 
-       if (child_captive_vfs_object->options.sandbox_server_ior) {
-               g_assert(child_captive_vfs_object->options.sandbox_server_argv==NULL);
+       if (captive_vfs_object->options.sandbox_server_ior) {
+               g_assert(captive_vfs_object->options.sandbox_server_argv==NULL);
 
                errbool=corba_init("captive-sandbox-parent",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
                g_assert(errbool==TRUE);
 
-               *parentheart_fds_1_return=-1;
-               *child_pid_return=-1;
+               captive_vfs_object->corba_parentheart_fds_1=-1;
+               captive_vfs_object->corba_child_pid=-1;
                sandbox_parent(
-                               child_captive_vfs_object->options.sandbox_server_ior,   /* Vfs_IOR */
+                               captive_vfs_object->options.sandbox_server_ior, /* Vfs_IOR */
                                NULL,   /* child_chroot_pid_hashkey_dir */
-                               &child_captive_vfs_object->options,     /* options_captive */
-                               corba_Vfs_object_return,        /* corba_Vfs_object_return */
-                               corba_GLogFunc_object_return,   /* corba_GLogFunc_object_return */
-                               corba_CaptiveIOChannel_object_return,   /* corba_CaptiveIOChannel_object_return */
-                               corba_parent_giochanel_blind_ptr);      /* corba_parent_giochanel_blind_ptr */
+                               captive_vfs_object);    /* captive_vfs_object */
                return TRUE;
                }
 
-       g_assert(child_captive_vfs_object->options.sandbox_server_argv!=NULL);
-       switch ((*child_pid_return=fork())) {
+       g_assert(captive_vfs_object->options.sandbox_server_argv!=NULL);
+       switch ((captive_vfs_object->corba_child_pid=fork())) {
                case -1:        /* error */
                        g_return_val_if_reached(FALSE);
 
@@ -652,8 +658,8 @@ gboolean errbool;
 
                        captive_sandbox_fd_closeup(2 /* STDERR */ +1);
 
-                       execv(child_captive_vfs_object->options.sandbox_server_argv[0],
-                                       /* re-const */ (char * const *)child_captive_vfs_object->options.sandbox_server_argv);
+                       execv(captive_vfs_object->options.sandbox_server_argv[0],
+                                       /* re-const */ (char * const *)captive_vfs_object->options.sandbox_server_argv);
                        g_return_val_if_reached(FALSE);
                        } /* NOTREACHED */
 
@@ -672,7 +678,7 @@ gchar *child_chroot_pid_hashkey_dir;
                         * Currently I am not aware such case would occur.
                         */
                        g_return_val_if_fail(errint==0,FALSE);
-                       *parentheart_fds_1_return=parentheart_fds[1];
+                       captive_vfs_object->corba_parentheart_fds_1=parentheart_fds[1];
 
                        Vfs_IOR=sandbox_parent_read_ior(
                                        Vfs_IOR_fds[0], /* Vfs_IOR_fd_read */
@@ -681,11 +687,7 @@ gchar *child_chroot_pid_hashkey_dir;
                        sandbox_parent(
                                        Vfs_IOR,        /* Vfs_IOR */
                                        child_chroot_pid_hashkey_dir,   /* child_chroot_pid_hashkey_dir */
-                                       &child_captive_vfs_object->options,     /* options_captive */
-                                       corba_Vfs_object_return,        /* corba_Vfs_object_return */
-                                       corba_GLogFunc_object_return,   /* corba_GLogFunc_object_return */
-                                       corba_CaptiveIOChannel_object_return,   /* corba_CaptiveIOChannel_object_return */
-                                       corba_parent_giochanel_blind_ptr);      /* corba_parent_giochanel_blind_ptr */
+                                       captive_vfs_object);    /* captive_vfs_object */
 
                        g_free(Vfs_IOR);
                        g_free(child_chroot_pid_hashkey_dir);
@@ -722,17 +724,19 @@ GnomeVFSResult r;
 gboolean captive_sandbox_parent_query_vfs_retry(CORBA_Environment *evp,CaptiveVfsObject *captive_vfs_object)
 {
 GnomeVFSResult errvfsresult;
+gboolean want_retry;
 
        g_return_val_if_fail(evp!=NULL,FALSE);
        g_return_val_if_fail(captive_vfs_object!=NULL,FALSE);
 
-       /* If !child_captive_vfs_object->options.sandbox_server_argv it is child_captive_vfs_object->options.sandbox_server_ior
+       /* If !captive_vfs_object->options.sandbox_server_argv it is captive_vfs_object->options.sandbox_server_ior
         * where we cannot do any restart anyway.
         */
-       if (!captive_vfs_object->options.sandbox_server_argv
-                       || !(evp->_major==CORBA_SYSTEM_EXCEPTION && !strcmp(ex_CORBA_COMM_FAILURE,CORBA_exception_id(evp))))
-               return FALSE;   /* no retry */
+       want_retry=(captive_vfs_object->options.sandbox_server_argv
+                       && (evp->_major==CORBA_SYSTEM_EXCEPTION && !strcmp(ex_CORBA_COMM_FAILURE,CORBA_exception_id(evp))));
        CORBA_exception_free(evp);
+       if (!want_retry)
+               return FALSE;   /* no retry */
 
        captive_sandbox_parent_vfs_close(captive_vfs_object);   /* errors ignored */
        errvfsresult=captive_sandbox_parent_vfs_new(captive_vfs_object);