diff options
| author | njoly <njoly@NetBSD.org> | 2014-05-18 09:30:00 +0000 |
|---|---|---|
| committer | njoly <njoly@NetBSD.org> | 2014-05-18 09:30:00 +0000 |
| commit | c14fb7b15abfadeecf8ead602b5ca7fb44ec4bcc (patch) | |
| tree | 898c07544031d1412b034fc407562c67b19b3c4a /sys | |
| parent | 7879567381d7b056297c42d4aea7f8febb7cbe29 (diff) | |
Simplify dup3 emulation to call dodup() directly instead of
sys_dup2()+fd_set_exclose(). While here, add some error conditions.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/compat/linux/common/linux_file.c | 18 | ||||
| -rw-r--r-- | sys/compat/linux32/common/linux32_unistd.c | 16 |
2 files changed, 15 insertions, 19 deletions
diff --git a/sys/compat/linux/common/linux_file.c b/sys/compat/linux/common/linux_file.c index 492e063e6f9..40738827fe4 100644 --- a/sys/compat/linux/common/linux_file.c +++ b/sys/compat/linux/common/linux_file.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_file.c,v 1.110 2014/05/06 13:21:50 njoly Exp $ */ +/* $NetBSD: linux_file.c,v 1.111 2014/05/18 09:30:00 njoly Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.110 2014/05/06 13:21:50 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.111 2014/05/18 09:30:00 njoly Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -784,14 +784,16 @@ linux_sys_dup3(struct lwp *l, const struct linux_sys_dup3_args *uap, syscallarg(int) to; syscallarg(int) flags; } */ - int error; - if ((error = sys_dup2(l, (const struct sys_dup2_args *)uap, retval))) - return error; + int flags; - if (SCARG(uap, flags) & LINUX_O_CLOEXEC) - fd_set_exclose(l, SCARG(uap, to), true); + flags = linux_to_bsd_ioflags(SCARG(uap, flags)); + if ((flags & ~O_CLOEXEC) != 0) + return EINVAL; - return 0; + if (SCARG(uap, from) == SCARG(uap, to)) + return EINVAL; + + return dodup(l, SCARG(uap, from), SCARG(uap, to), flags, retval); } diff --git a/sys/compat/linux32/common/linux32_unistd.c b/sys/compat/linux32/common/linux32_unistd.c index 90aa1c23cf1..7855b067c84 100644 --- a/sys/compat/linux32/common/linux32_unistd.c +++ b/sys/compat/linux32/common/linux32_unistd.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_unistd.c,v 1.37 2014/05/04 10:08:53 njoly Exp $ */ +/* $NetBSD: linux32_unistd.c,v 1.38 2014/05/18 09:30:00 njoly Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.37 2014/05/04 10:08:53 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.38 2014/05/18 09:30:00 njoly Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -293,19 +293,13 @@ linux32_sys_dup3(struct lwp *l, const struct linux32_sys_dup3_args *uap, syscallarg(int) to; syscallarg(int) flags; } */ - struct sys_dup2_args ua; - int error; + struct linux_sys_dup3_args ua; NETBSD32TO64_UAP(from); NETBSD32TO64_UAP(to); + NETBSD32TO64_UAP(flags); - if ((error = sys_dup2(l, &ua, retval))) - return error; - - if (SCARG(uap, flags) & LINUX_O_CLOEXEC) - fd_set_exclose(l, SCARG(uap, to), true); - - return 0; + return linux_sys_dup3(l, &ua, retval); } |
