From: Jan Dubois Date: Fri, 13 Nov 2009 01:14:59 +0000 (-0800) Subject: flock() should return EWOULDBLOCK instead of EAGAIN. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd9e8b45c89ee5d36539a3655dae7737fb78c21e;p=p5sagit%2Fp5-mst-13.2.git flock() should return EWOULDBLOCK instead of EAGAIN. POSIX requires fcntl() to return EAGAIN or EACCES, whereas BSD requires flock() to return EWOULDBLOCK. On most systems EAGAIN and EWOULDBLOCK use the same number, but on some (e.g. Linux on PA-RISC) they do not. --- diff --git a/pp_sys.c b/pp_sys.c index a985d65..bea4b7d 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -5579,6 +5579,7 @@ PP(pp_syscall) static int fcntl_emulate_flock(int fd, int operation) { + int res; struct flock flock; switch (operation & ~LOCK_NB) { @@ -5598,7 +5599,10 @@ fcntl_emulate_flock(int fd, int operation) flock.l_whence = SEEK_SET; flock.l_start = flock.l_len = (Off_t)0; - return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock); + res = fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock); + if (res == -1 && ((errno == EAGAIN) || (errno == EACCES))) + errno = EWOULDBLOCK; + return res; } #endif /* FCNTL_EMULATE_FLOCK */