From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
Sanil kumar <sanil.kumar@huawei.com>,
shyju pv <shyju.pv@huawei.com>,
Nagamani Mantha <nagamani.mantha@huawei.com>,
"Maxiansheng (Max)" <max.maxiansheng@huawei.com>
Subject: Re: dup2 return value mismatch
Date: Wed, 31 Oct 2012 03:39:07 +0000 [thread overview]
Message-ID: <20121031033907.GI2616@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20121031033748.GH2616@ZenIV.linux.org.uk>
On Wed, Oct 31, 2012 at 03:37:48AM +0000, Al Viro wrote:
> On Tue, Oct 30, 2012 at 08:14:52PM -0700, Linus Torvalds wrote:
> > On Tue, Oct 30, 2012 at 8:00 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> > >
> > > Umm... After looking at what POSIX actually says... There is an issue,
> > > all right. Thanks for spotting. Fix follows:
> > >
> > > Return the right error value when dup2() or dup3() newfd argument is too large
> >
> > I don't think this fixes anything.
> >
> > You're fixing replace_fd(), but dup2/dup3 don't actually *use* that.
> > They have their own RLIMIT_NOFILE check and return -EMFILE there.
>
> Ow... Moral: when :r in vi picks the file you've just scp'ed there from
> another xterm, it might be the variant you've sent there a couple of
> minutes prior ;-/ You are right, of course - sys_dup3() gets the same
> change (sys_dup2() doesn't; dup2(n, n) with n opened and currently beyond
> rlimit is not worth bothering *and* we'd never failed with EBADF in that
> case anyway; all other cases are covered by sys_dup3() change).
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> diff --git a/fs/file.c b/fs/file.c
> index ec20de9..603c7b5 100644
> --- a/fs/file.c
> +++ b/fs/file.c
> @@ -894,7 +894,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
> return __close_fd(files, fd);
>
> if (fd >= rlimit(RLIMIT_NOFILE))
> - return -EMFILE;
> + return -EBADF;
>
> spin_lock(&files->file_lock);
> err = expand_files(files, fd);
> @@ -920,7 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
> return -EINVAL;
>
> if (newfd >= rlimit(RLIMIT_NOFILE))
> - return -EMFILE;
> + return -BADF;
Grrrrr... And testing would also be a good idea. EBADF, of course.
Al "I'll go and hide somewhere in shame now" Viro, with apologies
prev parent reply other threads:[~2012-10-31 3:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 2:18 dup2 return value mismatch Linliangjie
2012-10-31 3:00 ` Al Viro
2012-10-31 3:14 ` Linus Torvalds
2012-10-31 3:37 ` Al Viro
2012-10-31 3:39 ` Al Viro [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121031033907.GI2616@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=max.maxiansheng@huawei.com \
--cc=nagamani.mantha@huawei.com \
--cc=sanil.kumar@huawei.com \
--cc=shyju.pv@huawei.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.