From 307b66716ade717cc40da94ef3d779299204495b Mon Sep 17 00:00:00 2001 From: short <> Date: Thu, 21 Aug 2003 16:07:47 +0000 Subject: [PATCH] Delete '/tmp/captive-orbit-$$/' directory on any kind of process exit. --- src/libcaptive/sandbox/split.c | 105 ++++++++++++++++++++++++++++++++++------- 1 file changed, 87 insertions(+), 18 deletions(-) diff --git a/src/libcaptive/sandbox/split.c b/src/libcaptive/sandbox/split.c index 6fe2b41..3702276 100644 --- a/src/libcaptive/sandbox/split.c +++ b/src/libcaptive/sandbox/split.c @@ -37,6 +37,7 @@ #include "server-CaptiveIOChannel.h" #include #include "../client/giochannel-blind.h" /* for captive_giochannel_blind_new() */ +#include /* CONFIG: */ @@ -333,10 +334,91 @@ static void options_module_captive_to_options_module_corba 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; + sigstructpsignum==signum) + break; + } + g_assert(sigstructpsighandler_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; + sigstructpsighandler_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; @@ -355,26 +437,13 @@ gboolean errbool; 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); } -- 1.8.3.1