Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-14556 client: rely on dup2() to allocate desired fd. Do not land… #13335

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/client/dfuse/pil4dfs/int_dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4867,22 +4867,35 @@ dup2(int oldfd, int newfd)
else
fd_directed = query_fd_forward_dest(oldfd);
if (fd_directed >= FD_FILE_BASE) {
rc = close(newfd);
if (rc != 0 && errno != EBADF)
return -1;
fd = allocate_a_fd_from_kernel();
int fd_tmp;

fd_tmp = allocate_a_fd_from_kernel();
if (fd_tmp < 0) {
/* failed to allocate an fd from kernel */
errno_save = errno;
DS_ERROR(errno_save, "failed to get a fd from kernel");
errno = errno_save;
return (-1);
}
/* rely on dup2() to get the desired fd */
fd = next_dup2(fd_tmp, newfd);
if (fd < 0) {
/* failed to allocate an fd from kernel */
errno_save = errno;
DS_ERROR(errno_save, "failed to get a fd from kernel");
close(fd_tmp);
errno = errno_save;
return (-1);
} else if (fd != newfd) {
close(fd);
close(fd_tmp);
DS_ERROR(EBUSY, "failed to get the desired fd in dup2()");
errno = EBUSY;
return (-1);
}
rc = close(fd_tmp);
if (rc != 0)
return -1;
idx = allocate_dup2ed_fd(fd, fd_directed);
if (idx >= 0)
return fd;
Expand Down