summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_util.c
diff options
context:
space:
mode:
authorFilip Hajny <filip@hajny.net>2018-02-01 14:28:45 +0100
committerFilip Hajny <filip@hajny.net>2018-02-01 14:28:45 +0100
commitf56e8905712eaf17a9dde9f61436eaec21c8a108 (patch)
tree9f1bc22ed3dd1dcf7fc9da563d16fe014dfe529e /src/lua/lua_util.c
parent182ea66988a3bac64de927c138c3aac9b6009f32 (diff)
downloadrspamd-f56e8905712eaf17a9dde9f61436eaec21c8a108.tar.gz
rspamd-f56e8905712eaf17a9dde9f61436eaec21c8a108.zip
Provide optional fcntl support for flock-less platforms like earlier SunOS.
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r--src/lua/lua_util.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index cb8d17849..222a48f35 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -1614,6 +1614,15 @@ lua_util_lock_file (lua_State *L)
gint fd = -1;
gboolean own = FALSE;
+#if !HAVE_FLOCK
+ struct flock fl = {
+ .l_type = F_WRLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 0,
+ .l_len = 0
+ };
+#endif
+
fpath = luaL_checkstring (L, 1);
if (fpath) {
@@ -1632,7 +1641,11 @@ lua_util_lock_file (lua_State *L)
return 2;
}
+#if HAVE_FLOCK
if (flock (fd, LOCK_EX) == -1) {
+#else
+ if (fcntl (fd, F_SETLKW, &fl) == -1) {
+#endif
lua_pushnil (L);
lua_pushstring (L, strerror (errno));
@@ -1658,6 +1671,15 @@ lua_util_unlock_file (lua_State *L)
gint fd = -1, ret, serrno;
gboolean do_close = TRUE;
+#if !HAVE_FLOCK
+ struct flock fl = {
+ .l_type = F_UNLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 0,
+ .l_len = 0
+ };
+#endif
+
if (lua_isnumber (L, 1)) {
fd = lua_tonumber (L, 1);
@@ -1665,7 +1687,11 @@ lua_util_unlock_file (lua_State *L)
do_close = lua_toboolean (L, 2);
}
+#if HAVE_FLOCK
ret = flock (fd, LOCK_UN);
+#else
+ ret = fcntl (fd, F_SETLKW, &fl);
+#endif
if (do_close) {
serrno = errno;