giochannel-blind moved from the sandboxed child to its parent.
[captive.git] / src / libcaptive / sandbox / parent-Vfs.c
1 /* $Id$
2  * CORBA/ORBit client side of Vfs object of sandbox_parent()
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include "captive/parent-Vfs.h" /* self */
23 #include <glib/gmessages.h>
24 #include "split.h"
25 #include "../client/vfs.h"
26 #include "sandbox.h"
27 #include <unistd.h>
28 #include "server-GLogFunc.h"
29 #include "server-CaptiveIOChannel.h"
30 #include <signal.h>     /* for kill(2) */
31 #include <wait.h>
32
33
34 GnomeVFSResult captive_sandbox_parent_vfs_new(CaptiveVfsObject *captive_vfs_object)
35 {
36 gboolean errbool;
37
38         g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
39
40         captive_vfs_object->is_sandbox_parent=TRUE;
41
42         errbool=captive_sandbox_spawn(
43                         captive_vfs_object,     /* child_captive_vfs_object */
44                         &captive_vfs_object->corba_Vfs_object,  /* corba_Vfs_object_return */
45                         &captive_vfs_object->corba_GLogFunc_object,     /* corba_GLogFunc_object_return */
46                         &captive_vfs_object->corba_CaptiveIOChannel_object,     /* corba_CaptiveIOChannel_object_return */
47                         &captive_vfs_object->corba_parent_giochanel_blind,      /* corba_parent_giochanel_blind_ptr */
48                         &captive_vfs_object->corba_parentheart_fds_1,   /* parentheart_fds_1_return */
49                         &captive_vfs_object->corba_child_pid);  /* child_pid_return */
50         g_return_val_if_fail(errbool==TRUE,GNOME_VFS_ERROR_GENERIC);
51
52         return GNOME_VFS_OK;
53 }
54
55
56 GnomeVFSResult captive_sandbox_parent_vfs_close(CaptiveVfsObject *captive_vfs_object)
57 {
58 GnomeVFSResult r;
59 int errint;
60 impl_POA_Captive_GLogFunc *GLogFunc_servant;
61 impl_POA_Captive_CaptiveIOChannel *CaptiveIOChannel_servant;
62 GIOStatus erriostatus;
63
64         g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
65
66         Captive_Vfs_shutdown(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
67         r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
68
69         CORBA_Object_release(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
70         g_assert(validate_CORBA_Environment(&captive_corba_ev));
71
72         /* Shutdown 'GLogFunc' servant. */
73         GLogFunc_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
74                         captive_vfs_object->corba_GLogFunc_object,&captive_corba_ev);
75         g_assert(validate_CORBA_Environment(&captive_corba_ev));
76         CORBA_Object_release(captive_vfs_object->corba_GLogFunc_object,&captive_corba_ev);
77         g_assert(validate_CORBA_Environment(&captive_corba_ev));
78         impl_Captive_GLogFunc__destroy(GLogFunc_servant,&captive_corba_ev);
79         g_assert(validate_CORBA_Environment(&captive_corba_ev));
80
81         /* Shutdown 'CaptiveIOChannel' servant. */
82         CaptiveIOChannel_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,
83                         captive_vfs_object->corba_CaptiveIOChannel_object,&captive_corba_ev);
84         g_assert(validate_CORBA_Environment(&captive_corba_ev));
85         CORBA_Object_release(captive_vfs_object->corba_CaptiveIOChannel_object,&captive_corba_ev);
86         g_assert(validate_CORBA_Environment(&captive_corba_ev));
87         impl_Captive_CaptiveIOChannel__destroy(CaptiveIOChannel_servant,&captive_corba_ev);
88         g_assert(validate_CORBA_Environment(&captive_corba_ev));
89         erriostatus=g_io_channel_flush(
90                         captive_vfs_object->corba_parent_giochanel_blind,       /* channel */
91                         NULL);  /* error */
92         g_assert(erriostatus==G_IO_STATUS_NORMAL);
93 #if 0
94         g_io_channel_unref(captive_vfs_object->corba_parent_giochanel_blind);
95 #endif
96
97         /* Close parentheart_fd_write. */
98         if (captive_vfs_object->corba_parentheart_fds_1!=-1) {
99                 errint=close(captive_vfs_object->corba_parentheart_fds_1);
100                 g_return_val_if_fail(errint==0,FALSE);
101                 }
102
103         /* Cleanup the child process. */
104         if (captive_vfs_object->corba_child_pid!=(pid_t)-1) {
105                 /*
106                  *
107                  *
108                  *
109                  *
110                  */
111                 kill(captive_vfs_object->corba_child_pid,SIGKILL);      /* errors ignored */
112                 /*
113                  *
114                  */
115                 waitpid(captive_vfs_object->corba_child_pid,
116                                 NULL,   /* status */
117                                 WNOHANG);       /* options */
118                 }
119
120         return r;
121 }