Commit 9cb52aff authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

files: Receive real fd numbers using recv_fd_from_peer()

Move reopen_fd_as() from receive_fd() to this function.
Note, that recv_fd_from_peer() has other callers, and
all of them are OK with receiving real fds (before,
they received arbitrary fds, and they OK with any fds).

travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 692674b4
...@@ -933,7 +933,10 @@ again: ...@@ -933,7 +933,10 @@ again:
} }
fle->received = 1; fle->received = 1;
return fd; if (reopen_fd_as(fle->fe->fd, fd) < 0)
return -1;
return fle->fe->fd;
} }
int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle) int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle)
...@@ -1046,7 +1049,7 @@ static int open_fd(int pid, struct fdinfo_list_entry *fle) ...@@ -1046,7 +1049,7 @@ static int open_fd(int pid, struct fdinfo_list_entry *fle)
static int receive_fd(int pid, struct fdinfo_list_entry *fle) static int receive_fd(int pid, struct fdinfo_list_entry *fle)
{ {
int tmp; int fd;
struct fdinfo_list_entry *flem; struct fdinfo_list_entry *flem;
flem = file_master(fle->desc); flem = file_master(fle->desc);
...@@ -1055,14 +1058,13 @@ static int receive_fd(int pid, struct fdinfo_list_entry *fle) ...@@ -1055,14 +1058,13 @@ static int receive_fd(int pid, struct fdinfo_list_entry *fle)
pr_info("\tReceive fd for %d\n", fle->fe->fd); pr_info("\tReceive fd for %d\n", fle->fe->fd);
tmp = recv_fd_from_peer(fle); fd = recv_fd_from_peer(fle);
if (tmp < 0) { if (fd < 0) {
pr_err("Can't get fd %d\n", tmp); pr_err("Can't get fd=%d, pid=%d\n", fle->fe->fd, fle->pid);
return -1; return -1;
} }
if (reopen_fd_as(fle->fe->fd, tmp) < 0) BUG_ON(fd != fle->fe->fd);
return -1;
if (fcntl(fle->fe->fd, F_SETFD, fle->fe->flags) == -1) { if (fcntl(fle->fe->fd, F_SETFD, fle->fe->flags) == -1) {
pr_perror("Unable to set file descriptor flags"); pr_perror("Unable to set file descriptor flags");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment