2 * CORBA/ORBit client side of Vfs object of sandbox_parent()
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "captive/parent-Vfs.h" /* self */
23 #include <glib/gmessages.h>
25 #include "../client/vfs.h"
28 #include "server-GLogFunc.h"
29 #include "server-CaptiveIOChannel.h"
30 #include <signal.h> /* for kill(2) */
32 #include "../client/giochannel-blind.h" /* for captive_giochannel_blind_commit() */
35 GnomeVFSResult captive_sandbox_parent_vfs_new(CaptiveVfsObject *captive_vfs_object)
39 g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
41 captive_vfs_object->is_sandbox_parent=TRUE;
43 errbool=captive_sandbox_spawn(captive_vfs_object);
44 g_return_val_if_fail(errbool==TRUE,GNOME_VFS_ERROR_GENERIC);
50 GnomeVFSResult captive_sandbox_parent_vfs_close(CaptiveVfsObject *captive_vfs_object)
54 impl_POA_Captive_GLogFunc *GLogFunc_servant;
55 impl_POA_Captive_CaptiveIOChannel *CaptiveIOChannel_servant;
56 GIOStatus erriostatus;
58 g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
60 Captive_Vfs_shutdown(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
61 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
63 CORBA_Object_release(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
64 g_assert(validate_CORBA_Environment(&captive_corba_ev));
66 /* Shutdown 'GLogFunc' servant. */
67 GLogFunc_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
68 captive_vfs_object->corba_GLogFunc_object,&captive_corba_ev);
69 g_assert(validate_CORBA_Environment(&captive_corba_ev));
70 CORBA_Object_release(captive_vfs_object->corba_GLogFunc_object,&captive_corba_ev);
71 g_assert(validate_CORBA_Environment(&captive_corba_ev));
72 impl_Captive_GLogFunc__destroy(GLogFunc_servant,&captive_corba_ev);
73 g_assert(validate_CORBA_Environment(&captive_corba_ev));
75 /* Shutdown 'CaptiveIOChannel' servant. */
76 CaptiveIOChannel_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
77 captive_vfs_object->corba_CaptiveIOChannel_object,&captive_corba_ev);
78 g_assert(validate_CORBA_Environment(&captive_corba_ev));
79 CORBA_Object_release(captive_vfs_object->corba_CaptiveIOChannel_object,&captive_corba_ev);
80 g_assert(validate_CORBA_Environment(&captive_corba_ev));
81 impl_Captive_CaptiveIOChannel__destroy(CaptiveIOChannel_servant,&captive_corba_ev);
82 g_assert(validate_CORBA_Environment(&captive_corba_ev));
84 /* Close parentheart_fd_write. */
85 if (captive_vfs_object->corba_parentheart_fds_1!=-1) {
86 errint=close(captive_vfs_object->corba_parentheart_fds_1);
87 g_return_val_if_fail(errint==0,FALSE);
90 /* Cleanup the child process. */
91 if (captive_vfs_object->corba_child_pid!=(pid_t)-1) {
98 kill(captive_vfs_object->corba_child_pid,SIGKILL); /* errors ignored */
102 waitpid(captive_vfs_object->corba_child_pid,
104 WNOHANG); /* options */
107 if (r==GNOME_VFS_OK) {
108 erriostatus=captive_giochannel_blind_commit(captive_vfs_object->corba_parent_giochanel_blind);
109 g_assert(erriostatus==G_IO_STATUS_NORMAL);
111 else { /* sandbox child failure */
112 /* Flush the channel to catch all the disk accesses to the bugreport. */
113 erriostatus=g_io_channel_flush(
114 captive_vfs_object->corba_parent_giochanel_blind, /* channel */
116 g_assert(erriostatus==G_IO_STATUS_NORMAL);
118 /* TODO: Summarize the bugreport. */
120 g_io_channel_unref(captive_vfs_object->corba_parent_giochanel_blind);
121 captive_vfs_object->corba_parent_giochanel_blind=NULL;
127 GnomeVFSResult captive_sandbox_parent_vfs_commit(CaptiveVfsObject *captive_vfs_object)
129 GnomeVFSResult r_close,r_new;
131 g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
133 r_close=captive_sandbox_parent_vfs_close(captive_vfs_object); /* errors ignored */
134 r_new=captive_sandbox_parent_vfs_new(captive_vfs_object);
136 return (r_new!=GNOME_VFS_OK ? r_new : r_close);