--- /dev/null
+# $Id$
+# automake source for CORBA ORBit IDL definition of sandbox intra-captive interface Makefile
+# Copyright (C) 2002-2003 Jan Kratochvil <project-captive@jankratochvil.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; exactly version 2 of June 1991 is required
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+include $(top_srcdir)/Makefile-head.am
+include $(top_srcdir)/src/libcaptive/Makefile-libcaptive.am
+
+SANDBOX_IDL_SOURCES= \
+ sandbox-common.c \
+ sandbox-skels.c \
+ sandbox-stubs.c \
+ sandbox.h
+
+noinst_LTLIBRARIES=libsandbox.la
+libsandbox_la_SOURCES=
+# FIXME: Not yet finished
+# $(SANDBOX_IDL_SOURCES) \
+# split.c \
+# server-GlibLogFunc.c \
+# server-GlibLogFunc.h \
+# server-Directory.c \
+# server-Directory.h \
+# server-VFS.c \
+# server-VFS.h
+
+libsandbox_la_CFLAGS=$(ORBIT_CFLAGS) $(LINC_CFLAGS)
+# $(LINC_LIBS) should be included by $(ORBIT_LIBS)
+# As we have no direct dependency on 'linc' it would be fatal if unexpectedly
+# ORBit-2 would not use 'linc'.
+libsandbox_la_LIBADD=$(ORBIT_LIBS)
+
+CLEANFILES+= \
+ $(sandbox_SOURCES)
+
+# Produced 'sandbox-skelimpl.c' is never compiled,
+# it is just a source of templates for server-*.[ch] files
+$(SANDBOX_IDL_SOURCES): sandbox.idl
+ $(ORBIT_IDL) --skeleton-impl $<
+
+split.lo: sandbox.h
--- /dev/null
+/* $Id$
+ * CORBA ORBit IDL definition of sandbox intra-captive interface
+ * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+module Captive
+{
+ typedef unsigned long GnomeVFSResult; /* enum */
+ exception GnomeVFSResultException {
+ GnomeVFSResult gnome_vfs_result;
+ };
+
+ typedef unsigned long GLogLevelFlags; /* enum */
+ struct GlibLogMessage { /* accepted by 'GLogFunc' */
+ /* string log_domain; always "Captive" */
+ GLogLevelFlags log_level;
+ string message;
+ };
+ exception GlibLogMessageFatal {
+ GlibLogMessage g_log_message;
+ };
+
+ interface GlibLogFunc {
+ /* Do not use 'oneway' as we would loose logging order coherency. */
+ void glibLogFunc(in GlibLogMessage glib_log_message);
+ };
+
+ interface Directory
+ {
+ enum GnomeVFSFileType {
+ GNOME_VFS_FILE_TYPE_UNKNOWN,
+ GNOME_VFS_FILE_TYPE_REGULAR,
+ GNOME_VFS_FILE_TYPE_DIRECTORY,
+ GNOME_VFS_FILE_TYPE_SOCKET,
+ GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE,
+ GNOME_VFS_FILE_TYPE_BLOCK_DEVICE
+ };
+ typedef unsigned short GnomeVFSFilePermissions;
+ typedef unsigned long long time_t;
+ typedef unsigned long long GnomeVFSFileSize;
+ struct GnomeVFSFileInfo {
+ string name; /* Base name of the file (no path). */
+ /* File type (i.e. regular, directory, block device...). */
+ GnomeVFSFileType type;
+ GnomeVFSFilePermissions permissions; /* File permissions. */
+ GnomeVFSFileSize size; /* Size in bytes. */
+ GnomeVFSFileSize block_count; /* Size measured in units of 512-byte blocks. */
+ /* Access, modification and change times. */
+ time_t atime; /* not present if ==(time_t)0 */
+ time_t mtime; /* not present if ==(time_t)0 */
+ time_t ctime; /* not present if ==(time_t)0 */
+ };
+ GnomeVFSFileInfo read()
+ raises (GnomeVFSResultException,GlibLogMessageFatal);
+ };
+ interface VFS
+ {
+ void registerGlibLogFunc(in GlibLogFunc glib_log_func);
+ Directory openDirectory(in string pathname)
+ raises (GnomeVFSResultException,GlibLogMessageFatal);
+ };
+};
--- /dev/null
+/* $Id$
+ * CORBA/ORBit server side of Directory object, ran by sandbox_child()
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include "server-Directory.h" /* self */
+#include "sandbox.h"
+#include <glib/gmessages.h>
+#include "captive/macros.h"
+
+
+typedef struct {
+ POA_Captive_Directory servant;
+ PortableServer_POA poa;
+ } impl_POA_Captive_Directory;
+
+static Captive_Directory_GnomeVFSFileInfo *impl_Captive_Directory_read
+ (impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
+
+static PortableServer_ServantBase__epv impl_Captive_Directory_base_epv={
+ NULL, /* _private data */
+ NULL, /* finalize routine */
+ NULL, /* default_POA routine */
+ };
+static POA_Captive_Directory__epv impl_Captive_Directory_epv={
+ NULL, /* _private */
+ (gpointer)&impl_Captive_Directory_read,
+ };
+static POA_Captive_Directory__vepv impl_Captive_Directory_vepv={
+ &impl_Captive_Directory_base_epv,
+ &impl_Captive_Directory_epv,
+ };
+
+
+Captive_Directory impl_Captive_Directory__create(PortableServer_POA poa,CORBA_Environment *ev)
+{
+Captive_Directory retval;
+impl_POA_Captive_Directory *newservant;
+PortableServer_ObjectId *objid;
+
+ captive_new0(newservant); /* FIXME: leak */
+ newservant->servant.vepv=&impl_Captive_Directory_vepv;
+ newservant->poa=poa;
+ POA_Captive_Directory__init((PortableServer_Servant)newservant,ev);
+ objid=PortableServer_POA_activate_object(poa,newservant,ev);
+ CORBA_free(objid);
+ retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
+
+ return retval;
+}
+
+
+static Captive_Directory_GnomeVFSFileInfo *impl_Captive_Directory_read
+ (impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
+{
+Captive_Directory_GnomeVFSFileInfo *retval;
+
+ retval=Captive_Directory_GnomeVFSFileInfo__alloc();
+/*
+ CORBA_string name;
+ Captive_Directory_GnomeVFSFileType type;
+ Captive_Directory_GnomeVFSFilePermissions permissions;
+ Captive_Directory_GnomeVFSFileSize size;
+ Captive_Directory_GnomeVFSFileSize block_count;
+ Captive_Directory_time_t atime;
+ Captive_Directory_time_t mtime;
+ Captive_Directory_time_t ctime;
+*/
+ return retval;
+}
--- /dev/null
+/* $Id$
+ * Include file for CORBA/ORBit server side of Directory object
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _SERVER_DIRECTORY_H
+#define _SERVER_DIRECTORY_H 1
+
+
+#include <glib/gmacros.h>
+#include "sandbox.h"
+
+
+G_BEGIN_DECLS
+
+Captive_Directory impl_Captive_Directory__create(PortableServer_POA poa,CORBA_Environment *ev);
+
+G_END_DECLS
+
+
+#endif /* _SERVER_DIRECTORY_H */
--- /dev/null
+/* $Id$
+ * CORBA/ORBit server side of GlibLogFunc object, ran by sandbox_parent()
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include "server-GlibLogFunc.h" /* self */
+#include "sandbox.h"
+#include "split.h"
+#include <glib/gmessages.h>
+#include "captive/macros.h"
+
+
+typedef struct {
+ POA_Captive_GlibLogFunc servant;
+ PortableServer_POA poa;
+ } impl_POA_Captive_GlibLogFunc;
+
+static void impl_Captive_GlibLogFunc_glibLogFunc
+ (impl_POA_Captive_GlibLogFunc *servant,const Captive_GlibLogMessage *glib_log_message,CORBA_Environment *ev);
+
+static PortableServer_ServantBase__epv impl_Captive_GlibLogFunc_base_epv={
+ NULL, /* _private data */
+ NULL, /* finalize routine */
+ NULL, /* default_POA routine */
+ };
+static POA_Captive_GlibLogFunc__epv impl_Captive_GlibLogFunc_epv={
+ NULL, /* _private */
+ (gpointer)&impl_Captive_GlibLogFunc_glibLogFunc,
+ };
+static POA_Captive_GlibLogFunc__vepv impl_Captive_GlibLogFunc_vepv={
+ &impl_Captive_GlibLogFunc_base_epv,
+ &impl_Captive_GlibLogFunc_epv,
+ };
+
+
+Captive_GlibLogFunc impl_Captive_GlibLogFunc__create(PortableServer_POA poa,CORBA_Environment *ev)
+{
+Captive_GlibLogFunc retval;
+impl_POA_Captive_GlibLogFunc *newservant;
+PortableServer_ObjectId *objid;
+
+ captive_new0(newservant); /* FIXME: leak */
+ newservant->servant.vepv=&impl_Captive_GlibLogFunc_vepv;
+ newservant->poa=poa;
+ POA_Captive_GlibLogFunc__init((PortableServer_Servant)newservant,ev);
+ objid=PortableServer_POA_activate_object(poa,newservant,ev);
+ CORBA_free(objid);
+ retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
+
+ return retval;
+}
+
+
+static void impl_Captive_GlibLogFunc_glibLogFunc
+ (impl_POA_Captive_GlibLogFunc *servant,const Captive_GlibLogMessage *glib_log_message,CORBA_Environment *ev)
+{
+ g_log(G_LOG_DOMAIN,glib_log_message->log_level,"%s",glib_log_message->message);
+}
+
+
+static void impl_Captive_VFS_registerGlibLogFunc_log_func
+ (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,const Captive_GlibLogFunc obj /* user_data */)
+{
+CORBA_Environment ev;
+Captive_GlibLogMessage glib_log_message;
+
+ /* Init 'ev' */
+ CORBA_exception_init(&ev);
+
+ glib_log_message.log_level=log_level;
+ glib_log_message.message=(CORBA_string)message;
+ Captive_GlibLogFunc_glibLogFunc(obj,&glib_log_message,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+
+ /* Shutdown 'ev' */
+ CORBA_exception_free(&ev);
+}
+
+
+void impl_Captive_VFS_registerGlibLogFunc
+ (impl_POA_Captive_VFS *servant,const Captive_GlibLogFunc glib_log_func,CORBA_Environment *ev)
+{
+ g_log_set_handler(
+ G_LOG_DOMAIN, /* log_domain; "Captive" */
+ 0 /* log_levels */
+ | 0 /* !G_LOG_FLAG_RECURSION */
+ | G_LOG_FLAG_FATAL
+ | G_LOG_LEVEL_MASK,
+ (GLogFunc)impl_Captive_VFS_registerGlibLogFunc_log_func, /* log_func */
+ (gpointer)glib_log_func); /* user_data */
+}
--- /dev/null
+/* $Id$
+ * Include file for CORBA/ORBit server side of GlibLogFunc object
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _SERVER_GLIBLOGFUNC_H
+#define _SERVER_GLIBLOGFUNC_H 1
+
+
+#include <glib/gmacros.h>
+#include "sandbox.h"
+#include "server-VFS.h" /* for impl_POA_Captive_VFS */
+
+
+G_BEGIN_DECLS
+
+void impl_Captive_VFS_registerGlibLogFunc
+ (impl_POA_Captive_VFS *servant,const Captive_GlibLogFunc glib_log_func,CORBA_Environment *ev);
+Captive_GlibLogFunc impl_Captive_GlibLogFunc__create(PortableServer_POA poa,CORBA_Environment *ev);
+
+G_END_DECLS
+
+
+#endif /* _SERVER_GLIBLOGFUNC_H */
--- /dev/null
+/* $Id$
+ * CORBA/ORBit server side of VFS object, ran by sandbox_child()
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include "server-VFS.h" /* self */
+#include "server-GlibLogFunc.h" /* for impl_Captive_VFS_registerGlibLogFunc() */
+#include "sandbox.h"
+#include <glib/gmessages.h>
+#include "captive/macros.h"
+
+
+static Captive_Directory impl_Captive_VFS_openDirectory
+ (impl_POA_Captive_VFS *servant,const CORBA_char *pathname,CORBA_Environment *ev);
+
+static PortableServer_ServantBase__epv impl_Captive_VFS_base_epv={
+ NULL, /* _private data */
+ NULL, /* finalize routine */
+ NULL, /* default_POA routine */
+ };
+static POA_Captive_VFS__epv impl_Captive_VFS_epv={
+ NULL, /* _private */
+ (gpointer)&impl_Captive_VFS_registerGlibLogFunc,
+ (gpointer)&impl_Captive_VFS_openDirectory,
+ };
+static POA_Captive_VFS__vepv impl_Captive_VFS_vepv={
+ &impl_Captive_VFS_base_epv,
+ &impl_Captive_VFS_epv,
+ };
+
+
+Captive_VFS impl_Captive_VFS__create(PortableServer_POA poa,CORBA_Environment *ev)
+{
+Captive_VFS retval;
+impl_POA_Captive_VFS *newservant;
+PortableServer_ObjectId *objid;
+
+ captive_new0(newservant); /* FIXME: leak */
+ newservant->servant.vepv=&impl_Captive_VFS_vepv;
+ newservant->poa=poa;
+ POA_Captive_VFS__init((PortableServer_Servant)newservant,ev);
+ objid=PortableServer_POA_activate_object(poa,newservant,ev);
+ CORBA_free(objid);
+ retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
+
+ return retval;
+}
+
+
+static Captive_Directory impl_Captive_VFS_openDirectory
+ (impl_POA_Captive_VFS *servant,const CORBA_char *pathname,CORBA_Environment *ev)
+{
+Captive_Directory retval;
+
+ return retval;
+}
--- /dev/null
+/* $Id$
+ * Include file for CORBA/ORBit server side of VFS object
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _SERVER_VFS_H
+#define _SERVER_VFS_H 1
+
+
+#include <glib/gmacros.h>
+#include "sandbox.h"
+
+
+G_BEGIN_DECLS
+
+typedef struct {
+ POA_Captive_VFS servant;
+ PortableServer_POA poa;
+ } impl_POA_Captive_VFS;
+
+
+Captive_VFS impl_Captive_VFS__create(PortableServer_POA poa,CORBA_Environment *ev);
+
+G_END_DECLS
+
+
+#endif /* _SERVER_VFS_H */
--- /dev/null
+/* $Id$
+ * Connection of captive-vfs interface through CORBA/ORBit
+ * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include "split.h" /* self */
+#include "sandbox.h"
+#include "server-GlibLogFunc.h"
+#include "captive/macros.h"
+#include <glib/gmacros.h>
+#include <stdlib.h>
+#include "captive/rtl-file.h"
+#include <unistd.h>
+#include <fcntl.h>
+#include <linc/linc.h> /* for linc_main_get_loop() */
+#include "server-GlibLogFunc.h"
+#include "server-Directory.h"
+#include "server-VFS.h"
+
+
+/* CONFIG: */
+
+#define HEARTBEAT_SOURCE_CHECK_EVENTS (G_IO_IN|G_IO_PRI)
+#define HEARTBEAT_SOURCE_CHECK_REVENTS (HEARTBEAT_SOURCE_CHECK_EVENTS|G_IO_ERR|G_IO_HUP|G_IO_NVAL)
+
+
+gboolean validate_CORBA_Environment(const CORBA_Environment *evp)
+{
+ g_return_val_if_fail(evp->_major==CORBA_NO_EXCEPTION,FALSE);
+
+ return TRUE;
+}
+
+
+static gboolean corba_init(const char *pname,CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
+{
+int orb_argc=1;
+gchar *orb_argv[]={
+ (gchar *)captive_strdup_alloca(pname),
+ NULL};
+
+ g_return_val_if_fail(evp!=NULL,FALSE);
+ g_return_val_if_fail(orbp!=NULL,FALSE);
+ g_return_val_if_fail(poap!=NULL,FALSE);
+
+ /* Init 'ev' */
+ CORBA_exception_init(evp);
+
+ /* Init 'orb' */
+ *orbp=CORBA_ORB_init(&orb_argc,orb_argv,"orbit-local-orb",evp);
+ g_return_val_if_fail(*orbp!=CORBA_OBJECT_NIL,FALSE);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+
+ /* Init 'poa' */
+ *poap=(PortableServer_POA)CORBA_ORB_resolve_initial_references(*orbp,"RootPOA",evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ {
+PortableServer_POAManager poa_mgr;
+ poa_mgr=PortableServer_POA__get_the_POAManager(*poap,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ PortableServer_POAManager_activate(poa_mgr,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ CORBA_Object_release((CORBA_Object)poa_mgr,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ }
+
+ return TRUE;
+}
+
+
+static CORBA_ORB heartbeat_source_callback_orb=CORBA_OBJECT_NIL;
+
+static gboolean corba_shutdown(CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
+{
+PortableServer_POA poa;
+CORBA_ORB orb;
+
+ g_return_val_if_fail(evp!=NULL,FALSE);
+ g_return_val_if_fail(orbp!=NULL,FALSE);
+ g_return_val_if_fail(poap!=NULL,FALSE);
+
+ /* Shutdown 'poa' */
+ poa=*poap;
+ *poap=CORBA_OBJECT_NIL;
+ CORBA_Object_release((CORBA_Object)poa,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+
+ /* Shutdown 'orb' */
+ orb=*orbp;
+ *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);
+
+ /* Shutdown 'ev' */
+ CORBA_exception_free(evp);
+
+ return TRUE;
+}
+
+
+static gboolean corba_servant_object_destroy(PortableServer_POA poa,CORBA_Object reference,CORBA_Environment *evp)
+{
+PortableServer_ObjectId *objid;
+PortableServer_Servant servant;
+
+ g_return_val_if_fail(poa!=CORBA_OBJECT_NIL,FALSE);
+ g_return_val_if_fail(reference!=CORBA_OBJECT_NIL,FALSE);
+ g_return_val_if_fail(evp!=NULL,FALSE);
+
+ objid=PortableServer_POA_reference_to_id(poa,reference,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ servant=PortableServer_POA_reference_to_servant(poa,reference,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ PortableServer_POA_deactivate_object(poa,objid,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ CORBA_free(objid);
+ (*((PortableServer_ServantBase *)servant)->vepv[0]->finalize)(servant,evp);
+ g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
+ g_free(servant);
+
+ return TRUE;
+}
+
+
+static gboolean heartbeat_source_callback(gpointer data /* unused */)
+{
+CORBA_Environment ev;
+
+ g_return_val_if_fail(heartbeat_source_callback_orb!=CORBA_OBJECT_NIL,FALSE); /* the source should be removed */
+
+ CORBA_exception_init(&ev);
+ /* CORBA_ORB_shutdown() is not enough as 'init_level' still >0 */
+ CORBA_ORB_destroy(
+ heartbeat_source_callback_orb, /* orb */
+ &ev); /* ev */
+ g_assert(validate_CORBA_Environment(&ev));
+ CORBA_exception_free(&ev);
+
+ return FALSE; /* the source should be removed */
+}
+
+
+static void sandbox_child(int VFS_IOR_fd_write,GSource *gsource) G_GNUC_NORETURN;
+static void sandbox_child(int VFS_IOR_fd_write,GSource *gsource)
+{
+CORBA_Environment ev;
+CORBA_ORB orb;
+PortableServer_POA poa;
+Captive_VFS VFS_object;
+gboolean errbool;
+int errint;
+guint errguint;
+
+ errbool=corba_init("sandbox_child",&ev,&orb,&poa);
+ g_assert(errbool==TRUE);
+ heartbeat_source_callback_orb=orb;
+
+ /* linc_main_get_loop() makes sense only after corba_init() -> CORBA_ORB_init() */
+ errguint=g_source_attach(
+ gsource, /* source */
+ g_main_loop_get_context(linc_main_get_loop())); /* context; NULL means 'default context' */
+ g_assert(errguint!=0);
+
+ /* Init 'VFS_object' */
+ VFS_object=impl_Captive_VFS__create(poa,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+
+ /* pass IOR to our parent */
+ {
+char *VFS_IOR;
+ VFS_IOR=CORBA_ORB_object_to_string(orb,VFS_object,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+ g_assert(VFS_IOR!=NULL);
+ errint=write(VFS_IOR_fd_write,VFS_IOR,strlen(VFS_IOR)+1);
+ g_assert((unsigned)errint==strlen(VFS_IOR)+1);
+ errint=close(VFS_IOR_fd_write);
+ g_assert(errint==0);
+ CORBA_free(VFS_IOR);
+ }
+
+ /* CORBA_ORB_run() -> linc_main_loop_run() -> g_main_loop_run()
+ * and therefore we should be safe with glib events handling.
+ */
+ CORBA_ORB_run(orb,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+
+ /* Shutdown 'VFS' servant */
+ errbool=corba_servant_object_destroy(poa,VFS_object,&ev);
+ g_assert(errbool==TRUE);
+
+ errbool=corba_shutdown(&ev,&orb,&poa);
+ g_assert(errbool==TRUE);
+
+ _exit(EXIT_SUCCESS);
+}
+
+static void sandbox_parent(int VFS_IOR_fd_read)
+{
+CORBA_Environment ev;
+CORBA_ORB orb;
+PortableServer_POA poa;
+gboolean errbool;
+char *VFS_IOR;
+gsize VFS_IOR_size;
+Captive_Directory directory_object;
+Captive_VFS VFS_object;
+Captive_GlibLogFunc GlibLogFunc_object;
+int errint;
+
+ errbool=corba_init("sandbox_parent",&ev,&orb,&poa);
+ g_return_if_fail(errbool==TRUE);
+
+ VFS_IOR=captive_rtl_file_read(VFS_IOR_fd_read,&VFS_IOR_size);
+ g_assert(VFS_IOR!=NULL);
+ g_assert(VFS_IOR_size>=1);
+ g_assert(memchr(VFS_IOR,0,VFS_IOR_size)==VFS_IOR+(VFS_IOR_size-1)); /* check exactly for 0-terminated string */
+ errint=close(VFS_IOR_fd_read);
+ g_assert(errint==0);
+
+ VFS_object=CORBA_ORB_string_to_object(orb,VFS_IOR,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+ g_free(VFS_IOR);
+
+ /* Init 'GlibLogFunc_object' */
+ GlibLogFunc_object=impl_Captive_GlibLogFunc__create(poa,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+ Captive_VFS_registerGlibLogFunc(VFS_object,GlibLogFunc_object,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+
+ directory_object=Captive_VFS_openDirectory(VFS_object,"/directory",&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+ puts("TEST DONE");
+
+ /* Shutdown 'GlibLogFunc' servant */
+ errbool=corba_servant_object_destroy(poa,GlibLogFunc_object,&ev);
+ g_assert(errbool==TRUE);
+
+ CORBA_Object_release(VFS_object,&ev);
+ g_assert(validate_CORBA_Environment(&ev));
+
+ errbool=corba_shutdown(&ev,&orb,&poa);
+ g_assert(errbool==TRUE);
+}
+
+static gboolean heartbeat_source_prepare(GSource *source,gint *timeout)
+{
+ *timeout=-1;
+
+ return FALSE;
+}
+
+static GPollFD heartbeat_source_check_gpollfd;
+
+static gboolean heartbeat_source_check(GSource *source)
+{
+ return !!(heartbeat_source_check_gpollfd.revents & HEARTBEAT_SOURCE_CHECK_REVENTS);
+}
+
+static gboolean heartbeat_source_dispatch(GSource *source,GSourceFunc callback,gpointer user_data)
+{
+ g_assert(callback!=NULL);
+ return (*callback)(user_data);
+}
+
+static GSourceFuncs heartbeat_source_watch_funcs={
+ heartbeat_source_prepare,
+ heartbeat_source_check,
+ heartbeat_source_dispatch,
+ NULL, /* finalize */
+ };
+
+
+void captive_sandbox_init(void)
+{
+/* VFS_IOR_fds[0] for reading by sandbox_parent() - client,
+ * VFS_IOR_fds[1] for writing by sandbox_child() - server
+ */
+int VFS_IOR_fds[2],parentheart_fds[2];
+int errint;
+
+ errint=pipe(VFS_IOR_fds);
+ g_assert(errint==0);
+ errint=pipe(parentheart_fds);
+ g_assert(errint==0);
+ switch (fork()) {
+ case -1: /* error */
+ g_assert_not_reached();
+
+ case 0: { /* child */
+GSource *gsource;
+
+ errint=close(VFS_IOR_fds[0]); /* close VFS_IOR_fd_read */
+ g_assert(errint==0);
+ errint=close(parentheart_fds[1]); /* close parentheart_fd_write */
+ g_assert(errint==0);
+
+ /* 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_assert(gsource!=NULL);
+ g_source_set_callback(
+ gsource, /* source */
+ heartbeat_source_callback, /* func */
+ NULL, /* data */
+ NULL); /* notify */
+ heartbeat_source_check_gpollfd.fd=parentheart_fds[0]; /* 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);
+ sandbox_child(VFS_IOR_fds[1],gsource); /* pass VFS_IOR_fd_write */
+ } /* NOTREACHED */
+
+ default: /* parent */
+ errint=close(VFS_IOR_fds[1]); /* close VFS_IOR_fd_write */
+ g_assert(errint==0);
+ errint=close(parentheart_fds[0]); /* close parentheart_fd_read */
+ g_assert(errint==0);
+ errint=fcntl(parentheart_fds[1],F_SETFD,FD_CLOEXEC);
+ /* This fcntl(2) may not be enough - some fork(2) may duplicate this
+ * write descriptor and even if we do some process finish the child
+ * may remain alone connected with some unknown fork(2)er from us.
+ * Currently I am not aware such case would occur.
+ */
+ g_assert(errint==0);
+ sandbox_parent(VFS_IOR_fds[0]); /* pass VFS_IOR_fd_read, it will be closed there */
+ break;
+ }
+ /* 'parentheart_fds[1]' - parentheart_fd_write - is left open here */
+}
--- /dev/null
+/* $Id$
+ * Include file for CORBA/ORBit split-mode initializer
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _SERVER_SPLIT_H
+#define _SERVER_SPLIT_H 1
+
+
+#include <glib/gmacros.h>
+#include "sandbox.h"
+
+
+G_BEGIN_DECLS
+
+gboolean validate_CORBA_Environment(const CORBA_Environment *evp);
+
+G_END_DECLS
+
+
+#endif /* _SERVER_SPLIT_H */