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

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

Issue 99203014: [NaCl SDK] Map active fds to absolute paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Map active fds to absolute paths. Created 6 years, 11 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_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..1c495804e9badfd62002b98a5da8934fc3095eef 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,17 @@ 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()) {
binji 2014/01/07 21:40:29 nit: no braces for single-line ifs
+ return "";
binji 2014/01/07 21:40:29 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 +190,8 @@ Error KernelObject::AcquireHandle(int fd, ScopedKernelHandle* out_handle) {
return EBADF;
}
-int KernelObject::AllocateFD(const ScopedKernelHandle& handle) {
+int KernelObject::AllocateFD(const ScopedKernelHandle& handle,
+ std::string path) {
AUTO_LOCK(handle_lock_);
int id;
@@ -196,6 +208,12 @@ 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()) {
+ std::string abs_path = GetAbsParts(path).Join();
+ fd_paths_[id] = abs_path;
binji 2014/01/07 21:40:29 nit: fs_paths_[id] = GetAbsParts(path).Join();
+ }
return id;
}
@@ -221,6 +239,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

Powered by Google App Engine
This is Rietveld 408576698