Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 29748

Summary: sandbox problems with mkdir
Product: Portage Development Reporter: Caleb Tennis (RETIRED) <caleb>
Component: UnclassifiedAssignee: Martin Schlemmer (RETIRED) <azarah>
Status: RESOLVED TEST-REQUEST    
Severity: normal CC: carpaski
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Caleb Tennis (RETIRED) gentoo-dev 2003-09-27 07:52:59 UTC
If an application attempts to do an mkdir call on a directory that already exists, the sandbox code always returns an error even if the directory already exists.

Instead, I propose that the sandbox return EEXIST if the directory exists, regardless of whether it's in the sandbox or not.  Only if the new directory is going to be created outside of the sandbox should an error be returned.

Rationale: some applications that may create files (perhaps config files) will attempt to verify that their destination directory exists before writing to them.  They do this by creating all of the directories up to the final destination:

mkdir /var
mkdir /var/tmp
mkdir /var/tmp/portage
mkdir /var/tmp/portage/blah

and they looks for EEXIST to verify that the directory already exists.
Comment 1 Martin Schlemmer (RETIRED) gentoo-dev 2003-09-27 09:47:50 UTC
Fixed in CVS.  Nick please have a look.

---------------------------------
Index: ChangeLog
===================================================================
RCS file: /home/cvsroot/gentoo-src/portage/src/sandbox-1.1/ChangeLog,v
retrieving revision 1.20
diff -u -p -r1.20 ChangeLog
--- ChangeLog   27 Jul 2003 15:05:49 -0000      1.20
+++ ChangeLog   27 Sep 2003 16:41:58 -0000
@@ -2,6 +2,10 @@
 # Copyright 2002 Gentoo Technologies, Inc.; Distributed under the GPL v2
 # $Header: /home/cvsroot/gentoo-src/portage/src/sandbox-1.1/ChangeLog,v
1.20 2003/07/27 15:05:49 azarah Exp $
  
+  27 Sep 2003; Martin Schlemmer <azarah@gentoo.org> libsandbox.c :
+  Fix our mkdir wrapper to check if the dir exist, and return EEXIST if
so,
+  rather than failing with a violation, bug #29748.
+
   27 Jul 2003; Martin Schlemmer <azarah@gentoo.org> libsandbox.c :
   Fix canonicalize() to ignore calls with path = "".
  
Index: libsandbox.c
===================================================================
RCS file: /home/cvsroot/gentoo-src/portage/src/sandbox-1.1/libsandbox.c,v
retrieving revision 1.9
diff -u -p -r1.9 libsandbox.c
--- libsandbox.c        27 Jul 2003 15:05:49 -0000      1.9
+++ libsandbox.c        27 Sep 2003 16:41:58 -0000
@@ -460,11 +460,20 @@ link(const char *oldpath, const char *ne
 int
 mkdir(const char *pathname, mode_t mode)
 {
-       int result = -1;
+       int result = -1, my_errno = errno;
        char canonic[SB_PATH_MAX];
+       struct stat st;
  
        canonicalize_int(pathname, canonic);
  
+       /* Check if the directory exist, return EEXIST rather than failing
*/
+       lstat(canonic, &st);
+       if (0 == errno) {
+               errno = EEXIST;
+               return errno;
+       }
+       errno = my_errno;
+
        if FUNCTION_SANDBOX_SAFE
                ("mkdir", canonic) {
                check_dlsym(mkdir);