From cd3ab57f9b388f8b1abf601dc4d78ff82d83b75e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 26 Feb 2018 14:37:06 +1100 Subject: [PATCH] Hook up flock() compat code. Also a couple of minor changes: fail if we can't lock instead of silently succeeding, and apply a couple of minor style fixes. --- configure.ac | 1 + openbsd-compat/Makefile.in | 2 +- openbsd-compat/bsd-flock.c | 11 ++++++++--- openbsd-compat/bsd-misc.h | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index a70d40628..35e2e8d1d 100644 --- a/configure.ac +++ b/configure.ac @@ -1723,6 +1723,7 @@ AC_CHECK_FUNCS([ \ explicit_bzero \ fchmod \ fchown \ + flock \ freeaddrinfo \ freezero \ fstatfs \ diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 053f2ef2a..71fcdb127 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in @@ -16,7 +16,7 @@ LDFLAGS=-L. @LDFLAGS@ OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o reallocarray.o realpath.o recallocarray.o rresvport.o setenv.o setproctitle.o sha1.o sha2.o rmd160.o md5.o sigact.o strcasestr.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o explicit_bzero.o freezero.o -COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-malloc.o bsd-setres_id.o bsd-signal.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o +COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-flock.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-malloc.o bsd-setres_id.o bsd-signal.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-net.o port-uw.o diff --git a/openbsd-compat/bsd-flock.c b/openbsd-compat/bsd-flock.c index 4a51ebe13..bf4d8a658 100644 --- a/openbsd-compat/bsd-flock.c +++ b/openbsd-compat/bsd-flock.c @@ -34,13 +34,15 @@ * Otherwise, don't do locking; just pretend success. */ -#include "nbtool_config.h" +#include "includes.h" -#if !HAVE_FLOCK +#ifndef HAVE_FLOCK #include #include -int flock(int fd, int op) { +int +flock(int fd, int op) +{ int rc = 0; #if defined(F_SETLK) && defined(F_SETLKW) @@ -69,6 +71,9 @@ int flock(int fd, int op) { if (rc && (errno == EAGAIN)) errno = EWOULDBLOCK; +#else + rc = -1 + errno = ENOSYS; #endif return rc; diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index af2ccdae2..2a73ae45b 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -145,4 +145,12 @@ int raise(int); pid_t getsid(pid_t); #endif +#ifndef HAVE_FLOCK +# define LOCK_SH 0x01 +# define LOCK_EX 0x02 +# define LOCK_NB 0x04 +# define LOCK_UN 0x08 +int flock(int, int); +#endif + #endif /* _BSD_MISC_H */