]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Provide optional fcntl support for flock-less platforms like earlier SunOS.
authorFilip Hajny <filip@hajny.net>
Thu, 1 Feb 2018 13:28:45 +0000 (14:28 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Sat, 10 Feb 2018 17:07:55 +0000 (19:07 +0200)
src/lua/lua_util.c

index 30d0f90d5de1dd6720e9047efc97f4bd4aaf7059..d6370c2e9ad4fffc100f680928f2c0df353cb75e 100644 (file)
@@ -1563,6 +1563,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) {
@@ -1581,7 +1590,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));
 
@@ -1607,6 +1620,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);
 
@@ -1614,7 +1636,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;