From: Michael Kerrisk <mtk.manpages@googlemail.com>
To: Kyle McMartin <kyle@infradead.org>
Cc: linux-arch@vger.kernel.org, Stefan Fritsch <sf@sfritsch.de>,
debian-hppa@lists.debian.org
Subject: Re: flock, FAGAIN, and FWOULDBLOCK
Date: Mon, 23 Feb 2009 16:20:53 +1300 [thread overview]
Message-ID: <cfd18e0f0902221920o3fafe56w73e3534dfe355abb@mail.gmail.com> (raw)
In-Reply-To: <20090223014224.GB13157@bombadil.infradead.org>
Hi Kyle,
On 2/23/09, Kyle McMartin <kyle@infradead.org> wrote:
> On Sun, Feb 22, 2009 at 05:49:24PM -0500, Kyle McMartin wrote:
>> > according to the flock(2) man page, flock should return EWOULDBLOCK
>> > when a file is locked and the LOCK_NB flag was selected. But on hppa,
>> > it seems to return EAGAIN which is not the same. Where is the bug
>> > here? In the kernel, glibc, or manpages-dev?
>> >
>> > This causes problems in apr since it only checks for EWOULDBLOCK.
>> >
>>
>> Ugh. Fail.
>>
>> EWOULDBLOCK is defined to be EAGAIN on every architecture but parisc,
>> since HPUX has different errno values for EAGAIN and EWOULDBLOCK.
>>
>> Definitely a kernel bug, if posix says it should return EWOULDBLOCK...
Note the following:
* POSIX has no specification of flock() (only fcntl() locking is
specified by POSIX.1).
* My understanding is that EAGAIN originated on System V, and was the
error returned instead of blocking for system calls performing I/O,
semaphore operations, message queue operations, and (fcntl()) file
locking. EWOULDBLOCK originated on BSD, and was returned by (flock())
file locking and socket-related system calls.
* flock() is a BSDism, and the associated error was EWOULDBLOCK.
* Generally POSIX requires that each error name must have distinct
associated value. EAGAIN and EWOULDBLOCK are one of the few
exceptions: POSIX permits, but does not require, that these error
constants have the same value. On most systems they of course do have
the same value. HP-UX is the most notable exception.
> This is really going to suck, it looks like a lot of the locking
> primitives used EAGAIN and EWOULDBLOCK interchangeably... The fcntl
> manpage says 'EAGAIN or EWOULDBLOCK'
Whoa -- that text in fcntl(2) relates to non-blocking I/O -- not file locking.
(There is a different mess for fcntl() file locking: if a non-blocking
log request is made (F_SETLK), then the call fails with the error
EACCES of EAGAIN -- POSIX explicitly allows this since there was
historical variation across systems.)
> so is flock(2) the only problem
> here? From a quick glance at posix, fcntl(2) returning EAGAIN is
> correct.
Returning EAGIN is correct, but returning EACCES is also permitted, as
noted above.
> My guess is, I'll be able to sort this out with a simple
Maybe. I suppose that it depends on what (broken) userland apps expect.
Cheers,
Michael
> diff --git a/arch/parisc/kernel/sys_parisc.c
> b/arch/parisc/kernel/sys_parisc.c
> index 71b3195..18e8542 100644
> --- a/arch/parisc/kernel/sys_parisc.c
> +++ b/arch/parisc/kernel/sys_parisc.c
> @@ -156,6 +156,17 @@ asmlinkage unsigned long sys_mmap(unsigned long addr,
> unsigned long len,
>
> /* Fucking broken ABI */
>
> +asmlinkage long parisc_flock(unsigned int fd, unsigned int cmd)
> +{
> + long ret;
> +
> + ret = sys_flock(fd, cmd);
> + if (ret == -EAGAIN)
> + ret = -EWOULDBLOCK; /* fuck you HPUX */
> +
> + return ret;
> +}
> +
> #ifdef CONFIG_64BIT
> asmlinkage long parisc_truncate64(const char __user * path,
> unsigned int high, unsigned int low)
> diff --git a/arch/parisc/kernel/syscall_table.S
> b/arch/parisc/kernel/syscall_table.S
> index 303d2b6..8c62951 100644
> --- a/arch/parisc/kernel/syscall_table.S
> +++ b/arch/parisc/kernel/syscall_table.S
> @@ -226,7 +226,7 @@
> /* it is POSSIBLE that select will be OK because even though fd_set
> * contains longs, the macros and sizes are clever. */
> ENTRY_COMP(select)
> - ENTRY_SAME(flock)
> + ENTRY_OURS(flock)
> ENTRY_SAME(msync)
> /* struct iovec contains pointers */
> ENTRY_COMP(readv) /* 145 */
>
> but somehow I suspect this interchangeable use of EAGAIN and EWOULDBLOCK
> is going to reveal latent problems in this part of the kernel I would
> rather not delve into...
>
> cheers, Kyle
> --
> To unsubscribe from this list: send the line "unsubscribe linux-arch" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
next prev parent reply other threads:[~2009-02-23 3:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200902222252.45051.sf@sfritsch.de>
[not found] ` <20090222224924.GA13157@bombadil.infradead.org>
2009-02-23 1:42 ` flock, FAGAIN, and FWOULDBLOCK Kyle McMartin
2009-02-23 2:43 ` Carlos O'Donell
2009-02-23 2:43 ` Carlos O'Donell
2009-02-23 2:54 ` Kyle McMartin
2009-02-23 3:00 ` Carlos O'Donell
2009-02-23 3:03 ` Matthew Wilcox
2009-02-23 3:55 ` Michael Kerrisk
2009-02-23 17:49 ` Helge Deller
2009-02-23 19:31 ` flock, EAGAIN, and EWOULDBLOCK Stefan Fritsch
2009-02-23 19:31 ` Stefan Fritsch
2009-02-23 3:31 ` flock, FAGAIN, and FWOULDBLOCK Michael Kerrisk
2009-02-23 3:20 ` Michael Kerrisk [this message]
2009-02-23 3:50 ` Kyle McMartin
2009-02-23 4:01 ` Michael Kerrisk
2009-02-23 8:23 ` Geert Uytterhoeven
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=cfd18e0f0902221920o3fafe56w73e3534dfe355abb@mail.gmail.com \
--to=mtk.manpages@googlemail.com \
--cc=debian-hppa@lists.debian.org \
--cc=kyle@infradead.org \
--cc=linux-arch@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=sf@sfritsch.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox