Index: native_client_sdk/src/libraries/nacl_io/kernel_object.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc |
index fccc5c85fd0cfe7da600482c4d9103531b2266ff..c356607810472d6df64b3c23fea17fa2e10dc9ac 100644 |
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc |
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc |
@@ -152,6 +152,16 @@ Error KernelObject::GetFDFlags(int fd, int* out_flags) { |
return 0; |
} |
+std::string KernelObject::GetFDPath(int fd) { |
+ AUTO_LOCK(handle_lock_); |
+ |
+ FdPathMap_t::iterator iter = fd_paths_.find(fd); |
+ if (iter == fd_paths_.end()) |
+ return std::string(); |
+ |
+ return iter->second; |
+} |
+ |
Error KernelObject::SetFDFlags(int fd, int flags) { |
AUTO_LOCK(handle_lock_); |
if (fd < 0 || fd >= static_cast<int>(handle_map_.size())) |
@@ -179,7 +189,25 @@ Error KernelObject::AcquireHandle(int fd, ScopedKernelHandle* out_handle) { |
return EBADF; |
} |
-int KernelObject::AllocateFD(const ScopedKernelHandle& handle) { |
+Error KernelObject::AcquireHandleAndPath(int fd, ScopedKernelHandle* out_handle, |
+ std::string &out_path){ |
Sam Clegg
2014/01/07 23:56:39
Put '&' next to the type according to the local st
|
+ out_handle->reset(NULL); |
+ |
+ AUTO_LOCK(handle_lock_); |
+ if (fd < 0 || fd >= static_cast<int>(handle_map_.size())) |
+ return EBADF; |
+ |
+ *out_handle = handle_map_[fd].handle; |
+ if (!out_handle) |
+ return EBADF; |
+ |
+ out_path = fd_paths_[fd]; |
+ |
+ return 0; |
+} |
+ |
+int KernelObject::AllocateFD(const ScopedKernelHandle& handle, |
+ std::string path) { |
Sam Clegg
2014/01/07 23:56:39
Why not pass string by reference here too?
|
AUTO_LOCK(handle_lock_); |
int id; |
@@ -196,10 +224,16 @@ int KernelObject::AllocateFD(const ScopedKernelHandle& handle) { |
id = handle_map_.size(); |
handle_map_.push_back(descriptor); |
} |
+ // With our final fd identifier, we insert into our fd_paths_ mapping as long |
+ // as path is non-NULL. |
+ if (!path.empty()) |
+ fd_paths_[id] = GetAbsParts(path).Join(); |
+ |
return id; |
} |
-void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle) { |
+void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle, |
+ const std::string &path) { |
Sam Clegg
2014/01/07 23:56:39
& next to type name.
|
if (NULL == handle) { |
FreeFD(fd); |
} else { |
@@ -210,6 +244,8 @@ void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle) { |
handle_map_.resize(fd + 1); |
handle_map_[fd] = Descriptor_t(handle); |
+ // Safe even if oldfd has no path. |
+ fd_paths_[fd] = path; |
} |
} |
@@ -221,6 +257,9 @@ void KernelObject::FreeFD(int fd) { |
// Force lower numbered FD to be available first. |
std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); |
+ // |
+ // Remove the FD from the map of fd to absolute path |
+ fd_paths_.erase(fd); |
} |
} // namespace nacl_io |