fatal("Unsuccessful setrlimit(%s)",resource_string);
}
-static gchar *chrooted_orbit_dir;
+static void sandbox_server_mkdir_p(const gchar *dirpathname)
+{
+gchar *pathname=(/* de-const */ gchar *)captive_strdup_alloca(dirpathname);
+gchar *gs,*gs2;
+
+ /* Missing mkdir(2) of the last component path is intentional: */
+ for (gs=pathname;(gs2=strchr(gs,'/'));gs=gs2) {
+ *gs2='\0';
+ if (*pathname && mkdir(pathname,S_ISVTX|0777)) {
+ if (errno!=EEXIST)
+ fatal("Failed to mkdir(\"%s\"): %m",pathname);
+ }
+ *gs2++='/';
+ }
+}
+
+static const gchar *chrooted_orbit_dir;
static void chroot_setup(gboolean fragile)
{
/* Prepare /t for /t/o-$PID directories for ORBit2
* and also for parent's hardlink to its /t/o-$pid directory. */
if (optarg_chroot) {
-gchar *chrooted_orbit_dir_old,*gs,*gs2;
+gchar *chrooted_orbit_dir_old;
if (mkdir("/t",S_ISVTX|0777)) {
if (errno!=EEXIST)
}
g_assert(chroot_pid_hashkey_dir!=NULL);
chrooted_orbit_dir=g_strdup_printf("%s/t/o-%d",chroot_pid_hashkey_dir,getpid());
- /* Missing mkdir(2) of the last component path is intentional: */
- for (gs=chrooted_orbit_dir;(gs2=strchr(gs,'/'));gs=gs2) {
- *gs2='\0';
- if (*chrooted_orbit_dir && mkdir(chrooted_orbit_dir,S_ISVTX|0777)) {
- if (errno!=EEXIST)
- fatal("Failed to mkdir(\"%s\"): %m",chrooted_orbit_dir);
- }
- *gs2++='/';
- }
- /* Prepare '/tmp' for the initial CORBA_ORB_init() default path: */
- if (mkdir("/tmp",S_ISVTX|0777)) {
- if (errno!=EEXIST)
- fatal("Failed to mkdir(\"%s\"): %m","/tmp");
- }
+ /* Last pathname component is not created: */
+ sandbox_server_mkdir_p(chrooted_orbit_dir);
+ /* Prepare '/tmp' for the initial CORBA_ORB_init() default path.
+ * Workaround sandbox_server_mkdir_p() does not create last component.
+ * Do not use '/tmp' directly as some distributions may set custom
+ * tmpdir pathname by $ENV{"TMPDIR"} etc.
+ */
+ sandbox_server_mkdir_p(captive_printf_alloca("%s/",g_get_tmp_dir()));
/* Set '0700' to prevent: Wrong permissions for ...
* by linc-1.0.1-1/src/linc-protocols.c/make_local_tmpdir()
*/