From 8c9a5708e7d7fde18f5b72d064f449156d5bfb3b Mon Sep 17 00:00:00 2001 From: Petr Skocik Date: Fri, 20 Oct 2017 10:50:24 +0200 Subject: [PATCH] New posix_spawn_file_actions_adddup2 semantics Clear FD_CLOEXEC on the target fd in dup2 file actions where target fd == src_fd. Ref: http://austingroupbugs.net/view.php?id=411 --- src/process/posix_spawn.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c index ea5d2998..cd355f17 100644 --- a/src/process/posix_spawn.c +++ b/src/process/posix_spawn.c @@ -109,8 +109,15 @@ static int child(void *args_vp) __syscall(SYS_close, op->fd); break; case FDOP_DUP2: - if ((ret=__sys_dup2(op->srcfd, op->fd))<0) - goto fail; + if (op->srcfd != op->fd){ + if ((ret=__sys_dup2(op->srcfd, op->fd))<0) + goto fail; + }else{ + if ((ret=__syscall(SYS_fcntl, op->fd, F_GETFD))<0) + goto fail; + if ((ret=__syscall(SYS_fcntl, op->fd, F_SETFD, ret & ~FD_CLOEXEC))<0) + goto fail; + } break; case FDOP_OPEN: fd = __sys_open(op->path, op->oflag, op->mode); -- 2.14.2