From: des Date: Mon, 30 Jul 2007 14:16:23 +0000 (+0000) Subject: Use fcntl(2)-style locks instead of non-portable flock(2)-style locks. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fd826d63b669cc5116edd2e1da2c39b4e52abb6;p=varnish Use fcntl(2)-style locks instead of non-portable flock(2)-style locks. Based on Theo Schlossnagle's Solaris portability patch. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1787 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvarnish/flopen.c b/varnish-cache/lib/libvarnish/flopen.c index 94f08d30..3ffe096c 100644 --- a/varnish-cache/lib/libvarnish/flopen.c +++ b/varnish-cache/lib/libvarnish/flopen.c @@ -44,6 +44,7 @@ flopen(const char *path, int flags, ...) { int fd, operation, serrno, trunc; struct stat sb, fsb; + struct flock lock; mode_t mode; #ifdef O_EXLOCK @@ -59,9 +60,11 @@ flopen(const char *path, int flags, ...) va_end(ap); } - operation = LOCK_EX; - if (flags & O_NONBLOCK) - operation |= LOCK_NB; + lock.l_type = (flags & O_WRONLY || flags & O_RDWR) ? F_WRLCK : F_RDLCK; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + lock.l_len = 0; + operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; trunc = (flags & O_TRUNC); flags &= ~O_TRUNC; @@ -70,7 +73,7 @@ flopen(const char *path, int flags, ...) if ((fd = open(path, flags, mode)) == -1) /* non-existent or no access */ return (-1); - if (flock(fd, operation) == -1) { + if (fcntl(fd, operation, &lock) == -1) { /* unsupported or interrupted */ serrno = errno; close(fd); diff --git a/varnish-cache/lib/libvarnish/vpf.c b/varnish-cache/lib/libvarnish/vpf.c index 857cc7c0..fa178747 100644 --- a/varnish-cache/lib/libvarnish/vpf.c +++ b/varnish-cache/lib/libvarnish/vpf.c @@ -32,12 +32,12 @@ #include #include +#include +#include #include #include -#include -#include #include -#include +#include #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" @@ -222,8 +222,14 @@ vpf_close(struct pidfh *pfh) static int _vpf_remove(struct pidfh *pfh, int freeit) { + struct flock lock; int error; + lock.l_type = F_UNLCK; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + lock.l_len = 0; + error = vpf_verify(pfh); if (error != 0) { errno = error; @@ -232,7 +238,7 @@ _vpf_remove(struct pidfh *pfh, int freeit) if (unlink(pfh->pf_path) == -1) error = errno; - if (flock(pfh->pf_fd, LOCK_UN) == -1) { + if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { if (error == 0) error = errno; }