Fix fchdir.
--- a/model/dce-at.cc Wed Feb 22 09:59:40 2012 +0100
+++ b/model/dce-at.cc Wed Feb 22 10:38:31 2012 +0100
@@ -60,7 +60,7 @@
}
else
{
- std::string path = std::string( get_current_dir_name()) + "/" + UtilsGetRealFilePath (pathname);
+ std::string path = UtilsGetCurrentDirName () + "/" + UtilsGetRealFilePath (pathname);
retval = ::__fxstatat (ver, fd, path.c_str (), buf, flag);
}
if (retval == -1)
@@ -106,7 +106,7 @@
}
else
{
- realpath = std::string(get_current_dir_name()) +"/"+ UtilsGetRealFilePath (pathname);
+ realpath = UtilsGetCurrentDirName () +"/"+ UtilsGetRealFilePath (pathname);
retval = ::unlinkat (fd , realpath.c_str (), flags);
}
if (retval == -1)
--- a/model/dce.cc Wed Feb 22 09:59:40 2012 +0100
+++ b/model/dce.cc Wed Feb 22 10:38:31 2012 +0100
@@ -633,11 +633,10 @@
current->err = EBADF;
return -1;
}
- std::string base = std::string(get_current_dir_name()) + "/" + UtilsGetRealFilePath ("/");
+ std::string base = UtilsGetCurrentDirName () + "/" + UtilsGetRealFilePath ("/");
current->process->cwd = UtilsGetVirtualFilePath (std::string (p, base.length() - 1 ));
return 0;
}
-
unsigned dce_if_nametoindex (const char *ifname)
{
int index = 0;
--- a/model/utils.cc Wed Feb 22 09:59:40 2012 +0100
+++ b/model/utils.cc Wed Feb 22 10:38:31 2012 +0100
@@ -535,4 +535,19 @@
}
return 0;
}
+std::string UtilsGetCurrentDirName (void)
+{
+ // DCE and NS3 never change the cwd.
+ static std::string pwd = "";
+ if (pwd.length () > 0)
+ {
+ return pwd;
+ }
+ char *thePwd = get_current_dir_name();
+ int fd = open (thePwd, O_RDONLY);
+ pwd = PathOfFd (fd);
+ close (fd);
+ free (thePwd);
+ return pwd;
+}
} // namespace ns3
--- a/model/utils.h Wed Feb 22 09:59:40 2012 +0100
+++ b/model/utils.h Wed Feb 22 10:38:31 2012 +0100
@@ -62,6 +62,7 @@
bool CheckShellScript (std::string fileName,
std::ostringstream &shellName, std::ostringstream &optionalArg);
char *seek_env (const char *name, char **array);
+std::string UtilsGetCurrentDirName (void);
#define MAX_FDS 1024
--- a/test/test-fd-simple.cc Wed Feb 22 09:59:40 2012 +0100
+++ b/test/test-fd-simple.cc Wed Feb 22 10:38:31 2012 +0100
@@ -394,9 +394,8 @@
// cd to /tmp
status = chdir ("/tmp");
TEST_ASSERT_EQUAL (status, 0);
- // status = fchdir (fddir); TODO fix it : may fail because of symbolic link or chroot ...
- // for example it failed launched from /user/furbani/home/dev/dce/dev/ns-3-dce-ccnx and not from /home/furbani/dev/dce/dev/ns-3-dce-ccnx ...
- // TEST_ASSERT_EQUAL (status, 0);
+ status = fchdir (fddir);
+ TEST_ASSERT_EQUAL (status, 0);
status = close (fddir);
TEST_ASSERT_EQUAL (status, 0);
// create file /tmp/U