Commit af1dfdda authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Add comment about closing pipes descriptors

Also a few style nitpicks.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent eb457b71
...@@ -821,8 +821,8 @@ static int execute_image(int pid) ...@@ -821,8 +821,8 @@ static int execute_image(int pid)
static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int pipes_fd) static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int pipes_fd)
{ {
int pfd[2], tmp;
unsigned long time = 1000; unsigned long time = 1000;
int pfd[2], tmp;
pr_info("\t%d: Creating pipe %x\n", pid, e->pipeid); pr_info("\t%d: Creating pipe %x\n", pid, e->pipeid);
...@@ -849,7 +849,7 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int ...@@ -849,7 +849,7 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
pi->real_pid = getpid(); pi->real_pid = getpid();
pr_info("\t%d: Done, waiting for others on %d pid with r:%d w:%d\n", pr_info("\t%d: Done, waiting for others on %d pid with r:%d w:%d\n",
pid, pi->real_pid, pfd[0], pfd[1]); pid, pi->real_pid, pi->read_fd, pi->write_fd);
while (1) { while (1) {
if (pi->users == 1) /* only I left */ if (pi->users == 1) /* only I left */
...@@ -862,6 +862,12 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int ...@@ -862,6 +862,12 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
usleep(time); usleep(time);
} }
/*
* At this point everyone who needed our pipe descriptors
* should have them attched so we're safe to close pipe
* descriptors here.
*/
pr_info("\t%d: All is ok - reopening pipe for %d\n", pid, e->fd); pr_info("\t%d: All is ok - reopening pipe for %d\n", pid, e->fd);
if (e->flags & O_WRONLY) { if (e->flags & O_WRONLY) {
close_safe(&pi->read_fd); close_safe(&pi->read_fd);
...@@ -892,6 +898,11 @@ static int attach_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi) ...@@ -892,6 +898,11 @@ static int attach_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi)
else else
tmp = pi->read_fd; tmp = pi->read_fd;
if (tmp == -1) {
pr_panic("Attaching closed pipe\n");
return 1;
}
sprintf(path, "/proc/%d/fd/%d", pi->real_pid, tmp); sprintf(path, "/proc/%d/fd/%d", pi->real_pid, tmp);
pr_info("\t%d: Attaching pipe %s\n", pid, path); pr_info("\t%d: Attaching pipe %s\n", pid, path);
......
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