{
int fd, operation, serrno, trunc;
struct stat sb, fsb;
+ struct flock lock;
mode_t mode;
#ifdef O_EXLOCK
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;
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);
#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 <errno.h>
+#include <unistd.h>
#ifndef HAVE_STRLCPY
#include "compat/strlcpy.h"
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;
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;
}