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..298820026dcc3817d4a6f879d298c9923748f802 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,8 @@ int KernelProxy::open_resource(const char* path) { |
return -1; |
} |
- return AllocateFD(handle); |
+ int fd = AllocateFD(handle, path); |
binji
2014/01/07 21:40:29
return AllocateFD(handle, path);
is fine. Here an
|
+ return fd; |
} |
int KernelProxy::open(const char* path, int open_flags) { |
@@ -192,7 +193,8 @@ int KernelProxy::open(const char* path, int open_flags) { |
return -1; |
} |
- return AllocateFD(handle); |
+ int fd = AllocateFD(handle, path); |
+ return fd; |
} |
int KernelProxy::pipe(int pipefds[2]) { |
@@ -209,8 +211,8 @@ int KernelProxy::pipe(int pipefds[2]) { |
return -1; |
} |
- pipefds[0] = AllocateFD(handle0); |
- pipefds[1] = AllocateFD(handle1); |
+ pipefds[0] = AllocateFD(handle0, ""); |
binji
2014/01/07 21:40:29
I think I'd prefer having the second parameter def
|
+ pipefds[1] = AllocateFD(handle1, ""); |
return 0; |
} |
@@ -238,8 +240,12 @@ int KernelProxy::dup(int oldfd) { |
errno = error; |
return -1; |
} |
- |
- return AllocateFD(handle); |
+ // Return value will be NULL if fd is not a path, which matches with the |
+ // appropriate argument to AllocateFD. Note that this will be a normalized |
+ // Path. |
+ std::string path = GetFDPath(oldfd); |
binji
2014/01/07 21:40:29
hm, I think there's a race here. The oldfd mapping
|
+ int fd = AllocateFD(handle, path); |
+ return fd; |
} |
int KernelProxy::dup2(int oldfd, int newfd) { |
@@ -514,8 +520,31 @@ 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; |
+ } |
+ |
+ std::string path = GetFDPath(fd); |
+ if (path.empty()) { |
+ errno = EBADF; |
+ return -1; |
+ } |
+ |
+ error = SetCWD(path); |
+ if (error) { |
+ // errno is return value from SetCWD |
+ errno = error; |
+ return -1; |
+ } |
+ return 0; |
} |
int KernelProxy::ftruncate(int fd, off_t length) { |
@@ -1202,7 +1231,7 @@ int KernelProxy::accept(int fd, struct sockaddr* addr, socklen_t* len) { |
return -1; |
} |
- return AllocateFD(new_handle); |
+ return AllocateFD(new_handle, ""); |
} |
int KernelProxy::bind(int fd, const struct sockaddr* addr, socklen_t len) { |
@@ -1563,7 +1592,7 @@ int KernelProxy::socket(int domain, int type, int protocol) { |
return -1; |
} |
- return AllocateFD(handle); |
+ return AllocateFD(handle, ""); |
} |
int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) { |