Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc

Issue 99203014: [NaCl SDK] Map active fds to absolute paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
index 672f51c30825aa1c9a8b4febf07f1047128e7b0c..3badd25efde968446437b8caeed1fd1a65d88c8a 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -172,7 +172,9 @@ int KernelProxy::open_resource(const char* path) {
return -1;
}
- return AllocateFD(handle);
+ int fd = AllocateFD(handle);
+ fd_paths_[fd] = GetAbsParts(path).Join();
binji 2014/01/06 19:32:04 this probably should be handled in AllocateFD. fd_
Matthew Turk 2014/01/07 20:33:11 It does -- and I've gone through and put path as a
+ return fd;
}
int KernelProxy::open(const char* path, int open_flags) {
@@ -192,7 +194,9 @@ int KernelProxy::open(const char* path, int open_flags) {
return -1;
}
- return AllocateFD(handle);
+ int fd = AllocateFD(handle);
+ fd_paths_[fd] = GetAbsParts(path).Join();
+ return fd;
}
int KernelProxy::pipe(int pipefds[2]) {
@@ -228,6 +232,8 @@ int KernelProxy::close(int fd) {
// Remove the FD from the process open file descriptor map
FreeFD(fd);
+ // Remove the FD from the map of fd to absolute path
+ fd_paths_.erase(fd);
Sam Clegg 2014/01/06 18:52:50 Would this be better done as part of FreeFD()?
binji 2014/01/06 19:32:04 agreed.
return 0;
}
@@ -239,7 +245,9 @@ int KernelProxy::dup(int oldfd) {
return -1;
}
- return AllocateFD(handle);
+ int fd = AllocateFD(handle);
+ fd_paths_[fd] = fd_paths_[oldfd];
+ return fd;
}
int KernelProxy::dup2(int oldfd, int newfd) {
@@ -514,8 +522,30 @@ int KernelProxy::getdents(int fd, void* buf, unsigned int count) {
}
int KernelProxy::fchdir(int fd) {
- errno = ENOSYS;
- return -1;
+ ScopedKernelHandle handle;
+ Error error = AcquireHandle(fd, &handle);
+ if (error) {
+ errno = error;
+ return -1;
+ }
+
+ if (!handle->node()->IsaDir()) {
+ errno = ENOTDIR;
+ return -1;
+ }
+
+ FdPathMap_t::iterator iter = fd_paths_.find(fd);
+ if (iter == fd_paths_.end()) {
+ errno = EBADF;
+ return -1;
+ }
+
+ error = SetCWD(iter->second);
+ if (error) {
+ // errno set by SetCWD
Sam Clegg 2014/01/06 18:52:50 Are you sure? I don't see SetCWD setting errno.
binji 2014/01/06 19:32:04 Only the KernelProxy sets errno. KernelObject::Set
+ return -1;
+ }
+ return 0;
}
int KernelProxy::ftruncate(int fd, off_t length) {

Powered by Google App Engine
This is Rietveld 408576698