]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Always use fcntl for file locking
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 2 Dec 2012 20:57:34 +0000 (20:57 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 2 Dec 2012 21:10:01 +0000 (21:10 +0000)
configure
configure.in
src/lib/misc.c

index 0d8a4c7c42c2e1037374ddc194b14faccf10aef4..d2a0f69212200917cdb127aa6a405280755fb7a4 100755 (executable)
--- a/configure
+++ b/configure
@@ -17605,7 +17605,7 @@ fi
 
 for ac_func in \
        getopt_long \
-       lockf \
+       fcntl \
        strsignal \
        sigaction \
        sigprocmask \
index d80978dd60d5352fcdd8fc6f6f4631fd04f58e94..1d0e24ddda475a440ab8ee9127dbcd72024c5df6 100644 (file)
@@ -933,7 +933,7 @@ dnl #
 dnl #############################################################
 AC_CHECK_FUNCS( \
        getopt_long \
-       lockf \
+       fcntl \
        strsignal \
        sigaction \
        sigprocmask \
index a7e059f880c40acaf454b3a3d7d61ec7a91274dc..868cf4cd5481dadf8ae9d2807a2eea5e884d535d 100644 (file)
@@ -49,29 +49,26 @@ const char *ip_ntoa(char *buffer, uint32_t ipaddr)
        return buffer;
 }
 
-#undef F_LOCK
-
 /*
  *     Internal wrapper for locking, to minimize the number of ifdef's
  *
- *     Lock an fd, prefer lockf() over flock()
+ *     Use fcntl or error
  */
 int rad_lockfd(int fd, int lock_len)
 {
-#if defined(F_LOCK)
-       return lockf(fd, F_LOCK, lock_len);
-#elif defined(LOCK_EX)
-       lock_len = lock_len;    /* -Wunused */
-       return flock(fd, LOCK_EX);
-#elif defined(F_WRLCK)
+#ifdef F_WRLCK
        struct flock fl;
+       
        fl.l_start = 0;
        fl.l_len = lock_len;
        fl.l_pid = getpid();
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_CUR;
+       
        return fcntl(fd, F_SETLKW, (void *)&fl);
 #else
+#error "missing definition for F_WRLCK, all file locks will fail"
+       
        return -1;
 #endif
 }
@@ -84,20 +81,19 @@ int rad_lockfd(int fd, int lock_len)
  */
 int rad_lockfd_nonblock(int fd, int lock_len)
 {
-#if defined(F_LOCK) && !defined(BSD)
-       return lockf(fd, F_TLOCK, lock_len);
-#elif defined(LOCK_EX)
-       lock_len = lock_len;    /* -Wunused */
-       return flock(fd, LOCK_EX | LOCK_NB);
-#elif defined(F_WRLCK)
+#ifdef F_WRLCK
        struct flock fl;
+       
        fl.l_start = 0;
        fl.l_len = lock_len;
        fl.l_pid = getpid();
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_CUR;
+       
        return fcntl(fd, F_SETLK, (void *)&fl);
 #else
+#error "missing definition for F_WRLCK, all file locks will fail"
+
        return -1;
 #endif
 }
@@ -110,20 +106,19 @@ int rad_lockfd_nonblock(int fd, int lock_len)
  */
 int rad_unlockfd(int fd, int lock_len)
 {
-#if defined(F_LOCK) && !defined(BSD)
-       return lockf(fd, F_ULOCK, lock_len);
-#elif defined(LOCK_EX)
-       lock_len = lock_len;    /* -Wunused */
-       return flock(fd, LOCK_UN);
-#elif defined(F_WRLCK)
+#ifdef F_WRLCK
        struct flock fl;
+       
        fl.l_start = 0;
        fl.l_len = lock_len;
        fl.l_pid = getpid();
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_CUR;
+
        return fcntl(fd, F_UNLCK, (void *)&fl);
 #else
+#error "missing definition for F_WRLCK, all file locks will fail"
+
        return -1;
 #endif
 }