diff options
author | des <des@FreeBSD.org> | 2007-08-03 09:20:28 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2007-08-03 09:20:28 +0000 |
commit | 28682dd29a203866286fd1a424a556fb67961e21 (patch) | |
tree | 365e862f83ff44d36c30869e51148e9c45df2402 /lib | |
parent | 3cfbe77a3e1ea4ec1530405c1d7a6192a03a46af (diff) | |
download | FreeBSD-src-28682dd29a203866286fd1a424a556fb67961e21.zip FreeBSD-src-28682dd29a203866286fd1a424a556fb67961e21.tar.gz |
Back out previous commit until I figure out why my regression test fails.
Approved by: re (kensmith)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/flopen.3 | 15 | ||||
-rw-r--r-- | lib/libutil/flopen.c | 11 | ||||
-rw-r--r-- | lib/libutil/pidfile.c | 14 |
3 files changed, 17 insertions, 23 deletions
diff --git a/lib/libutil/flopen.3 b/lib/libutil/flopen.3 index 78792fc..9025d65 100644 --- a/lib/libutil/flopen.3 +++ b/lib/libutil/flopen.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 30, 2007 +.Dd May 10, 2007 .Dt FLOPEN 3 .Os .Sh NAME @@ -46,9 +46,12 @@ The function opens or creates a file and acquires an exclusive lock on it. It is essentially equivalent with calling .Fn open -with the same parameters and then acquiring a lock on the entire file -using -.Fn fcntl "F_SETLK" , +with the same parameters followed by +.Fn flock +with an +.Va operation +argument of +.Dv LOCK_EX , except that .Fn flopen will attempt to detect and handle races that may occur between opening @@ -83,12 +86,12 @@ returns a valid file descriptor. Otherwise, it returns -1, and sets .Va errno as described in -.Xr fcntl 2 +.Xr flock 2 and .Xr open 2 . .Sh SEE ALSO .Xr errno 2 , -.Xr fcntl 2 , +.Xr flock 2 , .Xr open 2 .Sh AUTHORS .An -nosplit diff --git a/lib/libutil/flopen.c b/lib/libutil/flopen.c index f285ac5..23742f7 100644 --- a/lib/libutil/flopen.c +++ b/lib/libutil/flopen.c @@ -43,7 +43,6 @@ 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,11 +58,9 @@ flopen(const char *path, int flags, ...) va_end(ap); } - lock.l_type = (flags & O_RDONLY) ? F_RDLCK : F_WRLCK; - lock.l_start = 0; - lock.l_whence = SEEK_SET; - lock.l_len = 0; - operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; + operation = LOCK_EX; + if (flags & O_NONBLOCK) + operation |= LOCK_NB; trunc = (flags & O_TRUNC); flags &= ~O_TRUNC; @@ -72,7 +69,7 @@ flopen(const char *path, int flags, ...) if ((fd = open(path, flags, mode)) == -1) /* non-existent or no access */ return (-1); - if (fcntl(fd, operation, &lock) == -1) { + if (flock(fd, operation) == -1) { /* unsupported or interrupted */ serrno = errno; close(fd); diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index c572551..983d103 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -31,13 +31,13 @@ __FBSDID("$FreeBSD$"); #include <sys/file.h> #include <sys/stat.h> -#include <errno.h> -#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <fcntl.h> #include <string.h> - +#include <err.h> +#include <errno.h> #include <libutil.h> static int _pidfile_remove(struct pidfh *pfh, int freeit); @@ -207,14 +207,8 @@ pidfile_close(struct pidfh *pfh) static int _pidfile_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 = pidfile_verify(pfh); if (error != 0) { errno = error; @@ -223,7 +217,7 @@ _pidfile_remove(struct pidfh *pfh, int freeit) if (unlink(pfh->pf_path) == -1) error = errno; - if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { + if (flock(pfh->pf_fd, LOCK_UN) == -1) { if (error == 0) error = errno; } |