[PATCH] dup3 fix
[safe/jmp/linux-2.6] / fs / fcntl.c
index 9679fcb..ce12a68 100644 (file)
@@ -139,8 +139,13 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
        if (!(file = fcheck(oldfd)))
                goto out_unlock;
        err = newfd;
-       if (newfd == oldfd)
+       if (unlikely(newfd == oldfd)) {
+               if (flags & O_CLOEXEC) {
+                       fdt = files_fdtable(files);
+                       FD_SET(newfd, fdt->close_on_exec);
+               }
                goto out_unlock;
+       }
        err = -EBADF;
        if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
                goto out_unlock;