From b3028a9fb8110fd37f60e9d66dad3cde6e7b062b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 21 Apr 2017 21:57:50 -0700 Subject: [PATCH] util: Workaround lack of flock on Solaris v2: Replace autoconf check for flock() with meson check Signed-off-by: Alan Coopersmith Acked-by: Eric Engestrom --- meson.build | 2 +- src/util/disk_cache.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c96f1ed0f7b..e1ca9559b56 100644 --- a/meson.build +++ b/meson.build @@ -1144,7 +1144,7 @@ foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h', 'endian.h', 'dlfcn.h' endif endforeach -foreach f : ['strtof', 'mkostemp', 'timespec_get', 'memfd_create', 'random_r'] +foreach f : ['strtof', 'mkostemp', 'timespec_get', 'memfd_create', 'random_r', 'flock'] if cc.has_function(f) pre_args += '-DHAVE_@0@'.format(f.to_upper()) endif diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 9272e9c5471..77af64ed3b0 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -907,7 +907,17 @@ cache_put(void *job, int thread_index) * open with the flock held. So just let that file be responsible * for writing the file. */ +#ifdef HAVE_FLOCK err = flock(fd, LOCK_EX | LOCK_NB); +#else + struct flock lock = { + .l_start = 0, + .l_len = 0, /* entire file */ + .l_type = F_WRLCK, + .l_whence = SEEK_SET + }; + err = fcntl(fd, F_SETLK, &lock); +#endif if (err == -1) goto done; -- 2.30.2