#include "server-CaptiveIOChannel.h"
#include <errno.h>
#include "../client/giochannel-blind.h" /* for captive_giochannel_blind_new() */
+#include <signal.h>
/* CONFIG: */
dest_options_module_corba->data._release=TRUE;
}
+static void unlink_nonrecursive(const gchar *dirname)
+{
+DIR *dir;
+struct dirent *dirent;
+int errint;
+
+ dir=opendir(dirname);
+ g_assert(dir!=NULL);
+
+ while (errno=0,(dirent=readdir(dir))) {
+gchar *pathname;
+
+ if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
+ continue;
+ pathname=g_strdup_printf("%s/%s",dirname,dirent->d_name);
+ errint=unlink(pathname);
+ g_assert(errint==0);
+ g_free(pathname);
+ }
+ g_assert(errno==0);
+ errint=closedir(dir);
+ g_assert(errint==0);
+ errint=rmdir(dirname);
+ g_assert(errint==0);
+}
static const gchar *sandbox_parent_own_orbit_dir;
static const gchar *sandbox_parent_own_orbit_socket;
+static void sandbox_parent_own_orbit_dir_cleanup_atexit(void)
+{
+static gboolean done=FALSE;
+
+ if (done)
+ return;
+ done=TRUE;
+
+ unlink_nonrecursive(sandbox_parent_own_orbit_dir);
+}
+
+static struct sandbox_parent_own_orbit_dir_cleanup_signal {
+ int signum;
+ /* FIXME: Why we cannot use 'sighandler_t'? */ void (*sighandler_orig)(int signum);
+ } sandbox_parent_own_orbit_dir_cleanup_signals[]={
+ { SIGINT },
+ { SIGQUIT },
+ { SIGTERM },
+ { SIGHUP },
+ { SIGABRT },
+ { SIGFPE },
+ };
+
+static void sandbox_parent_own_orbit_dir_cleanup_sighandler(int signum)
+{
+struct sandbox_parent_own_orbit_dir_cleanup_signal *sigstructp;
+
+ sandbox_parent_own_orbit_dir_cleanup_atexit();
+
+ for (
+ sigstructp=sandbox_parent_own_orbit_dir_cleanup_signals;
+ sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals);
+ sigstructp++) {
+ if (sigstructp->signum==signum)
+ break;
+ }
+ g_assert(sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals));
+ signal(signum,sigstructp->sighandler_orig);
+ raise(signum);
+}
+
+static void sandbox_parent_own_orbit_dir_cleanup_init(void)
+{
+struct sandbox_parent_own_orbit_dir_cleanup_signal *sigstructp;
+
+ g_atexit(sandbox_parent_own_orbit_dir_cleanup_atexit);
+ for (
+ sigstructp=sandbox_parent_own_orbit_dir_cleanup_signals;
+ sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals);
+ sigstructp++) {
+ sigstructp->sighandler_orig=signal(sigstructp->signum,sandbox_parent_own_orbit_dir_cleanup_sighandler);
+ if (sigstructp->sighandler_orig==SIG_IGN)
+ sigstructp->sighandler_orig=SIG_DFL;
+ }
+}
+
gchar *sandbox_parent_read_ior(int Vfs_IOR_fd_read,gchar **child_chroot_pid_hashkey_dirp)
{
gchar *data;
if (!sandbox_parent_own_orbit_dir) {
sandbox_parent_own_orbit_dir=g_strdup_printf("/tmp/captive-orbit-%d",getpid());
if (mkdir(sandbox_parent_own_orbit_dir,0700)) {
-DIR *dir;
-struct dirent *dirent;
g_assert(errno==EEXIST);
-
- dir=opendir(sandbox_parent_own_orbit_dir);
- g_assert(dir!=NULL);
-
- while (errno=0,(dirent=readdir(dir))) {
-gchar *pathname;
- if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
- continue;
- pathname=g_strdup_printf("%s/%s",sandbox_parent_own_orbit_dir,dirent->d_name);
- errint=unlink(pathname);
- g_assert(errint==0);
- g_free(pathname);
- }
- g_assert(errno==0);
- errint=closedir(dir);
- g_assert(errint==0);
+ sandbox_parent_own_orbit_dir_cleanup_init();
+ unlink_nonrecursive(sandbox_parent_own_orbit_dir);
+ if (mkdir(sandbox_parent_own_orbit_dir,0700))
+ g_assert_not_reached();
}
+ sandbox_parent_own_orbit_dir_cleanup_init();
linc_set_tmpdir(sandbox_parent_own_orbit_dir);
}