Lines Matching refs:fd

47 static const char kFdPath[] = "/proc/self/fd";
132 static FileDescriptorInfo* CreateFromFd(int fd, std::string* error_msg);
140 const int fd;
150 FileDescriptorInfo(int fd);
152 FileDescriptorInfo(struct stat stat, const std::string& file_path, int fd, int open_flags,
155 // Returns the locally-bound name of the socket |fd|. Returns true
162 static bool GetSocketName(const int fd, std::string* result);
170 FileDescriptorInfo* FileDescriptorInfo::CreateFromFd(int fd, std::string* error_msg) {
174 if (TEMP_FAILURE_RETRY(fstat(fd, &f_stat)) == -1) {
175 *error_msg = android::base::StringPrintf("Unable to stat %d", fd);
183 if (!GetSocketName(fd, &socket_name)) {
189 *error_msg = android::base::StringPrintf("Socket name not whitelisted : %s (fd=%d)",
191 fd);
195 return new FileDescriptorInfo(fd);
214 const std::string fd_path = android::base::StringPrintf("/proc/self/fd/%d", fd);
216 *error_msg = android::base::StringPrintf("Could not read fd link %s: %s",
230 const int fd_flags = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD));
233 fd,
251 int fs_flags = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL));
254 fd,
261 const off_t offset = TEMP_FAILURE_RETRY(lseek64(fd, 0, SEEK_CUR));
269 return new FileDescriptorInfo(f_stat, file_path, fd, open_flags, fd_flags, fs_flags, offset);
274 if (TEMP_FAILURE_RETRY(fstat(fd, &f_stat)) == -1) {
275 PLOG(ERROR) << "Unable to restat fd " << fd;
329 if (TEMP_FAILURE_RETRY(dup2(new_fd, fd)) == -1) {
332 fd,
344 FileDescriptorInfo::FileDescriptorInfo(int fd) :
345 fd(fd),
355 int fd, int open_flags, int fd_flags, int fs_flags,
357 fd(fd),
368 bool FileDescriptorInfo::GetSocketName(const int fd, std::string* result) {
373 if (TEMP_FAILURE_RETRY(getsockname(fd, addr, &addr_len)) == -1) {
374 PLOG(ERROR) << "Failed getsockname(" << fd << ")";
379 LOG(ERROR) << "Unsupported socket (fd=" << fd << ") with family " << addr->sa_family;
388 LOG(ERROR) << "Unsupported AF_UNIX socket (fd=" << fd << ") with empty path.";
418 if (dup2(dev_null_fd, fd) == -1) {
420 fd,
446 const int fd = ParseFd(e, dir_fd);
447 if (fd == -1) {
450 if (std::find(fds_to_ignore.begin(), fds_to_ignore.end(), fd) != fds_to_ignore.end()) {
451 LOG(INFO) << "Ignoring open file descriptor " << fd;
455 FileDescriptorInfo* info = FileDescriptorInfo::CreateFromFd(fd, error_msg);
462 open_fd_map[fd] = info;
487 const int fd = ParseFd(e, dir_fd);
488 if (fd == -1) {
491 if (std::find(fds_to_ignore.begin(), fds_to_ignore.end(), fd) != fds_to_ignore.end()) {
492 LOG(INFO) << "Ignoring open file descriptor " << fd;
496 open_fds.insert(fd);
591 const int fd = (*it);
592 FileDescriptorInfo* info = FileDescriptorInfo::CreateFromFd(fd, error_msg);
599 open_fd_map_[fd] = info;
610 const int fd = strtol(e->d_name, &end, 10);
617 if (fd <= STDERR_FILENO || fd == dir_fd) {
621 return fd;