From 98c8e44f749dd7ed0aa8c540f566bda54d7adfa1 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Thu, 2 Jul 2015 12:47:07 +0300 Subject: [PATCH] pipe: don't create a tranport descriptor for inhereted pipes Otherwise we can get an error like this: 1: \t\tCreate transport fd /crtools-fd-1-5 ... 1: Found id pipe:[122747] (fd 8) in inherit fd list 1: File pipe:[122747] will be restored from fd 9 duped from inherit 1: Error (util.c:131): fd 5 already in use (called at files.c:872) Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- files.c | 3 +++ pipes.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/files.c b/files.c index 4eeb988..3e69be7 100644 --- a/files.c +++ b/files.c @@ -1394,6 +1394,9 @@ bool inherited_fd(struct file_desc *d, int *fd_p) if (i_fd < 0) return false; + if (fd_p == NULL) + return true; + *fd_p = dup(i_fd); if (*fd_p < 0) pr_perror("Inherit fd DUP failed"); diff --git a/pipes.c b/pipes.c index 7590472..62f550c 100644 --- a/pipes.c +++ b/pipes.c @@ -393,18 +393,22 @@ static int collect_one_pipe(void *o, ProtobufCMessage *base) pr_info("Collected pipe entry ID %#x PIPE ID %#x\n", pi->pe->id, pi->pe->pipe_id); - list_for_each_entry(tmp, &pipes, list) - if (pi->pe->pipe_id == tmp->pe->pipe_id) - break; + if (file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops)) + return -1; - if (&tmp->list == &pipes) - INIT_LIST_HEAD(&pi->pipe_list); - else - list_add(&pi->pipe_list, &tmp->pipe_list); + INIT_LIST_HEAD(&pi->pipe_list); + if (!inherited_fd(&pi->d, NULL)) { + list_for_each_entry(tmp, &pipes, list) + if (pi->pe->pipe_id == tmp->pe->pipe_id) + break; + + if (&tmp->list != &pipes) + list_add(&pi->pipe_list, &tmp->pipe_list); + } list_add_tail(&pi->list, &pipes); - return file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops); + return 0; } struct collect_image_info pipe_cinfo = {