]> granicus.if.org Git - postgresql/commitdiff
Add configure test to make sure fcntl(SETLK) is available,
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 6 Oct 1998 02:31:42 +0000 (02:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 6 Oct 1998 02:31:42 +0000 (02:31 +0000)
and make backend/libpq/pqcomm.c only try to lock the socket file when
the call exists.  Also, change open-RDONLY to open-WRONLY; at least
on my platform, you can't get a write lock on a file you didn't open
for writing.

src/backend/libpq/pqcomm.c
src/configure.in
src/include/config.h.in

index cab6289d9e0e89ad746dfc568d581f9de05f6fb5..74f14516e5953826f30ec25a070bf0b6affe2604 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.54 1998/09/10 04:07:59 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.55 1998/10/06 02:31:39 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -560,7 +560,8 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                 * If the socket exists but nobody has an advisory lock on it we
                 * can safely delete the file.
                 */
-               if ((lock_fd = open(sock_path, O_RDONLY | O_NONBLOCK, 0666)) >= 0)
+#ifdef HAVE_FCNTL_SETLK
+               if ((lock_fd = open(sock_path, O_WRONLY | O_NONBLOCK, 0666)) >= 0)
                {
                        struct flock    lck;
                        
@@ -575,6 +576,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                                TPRINTF(TRACE_VERBOSE, "flock failed for %s", sock_path);
                        close(lock_fd);
                }
+#endif /* HAVE_FCNTL_SETLK */
        }
        else
        {
@@ -609,7 +611,8 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                 * Open the socket file and get an advisory lock on it. The
                 * lock_fd is left open to keep the lock.
                 */
-               if ((lock_fd = open(sock_path, O_RDONLY | O_NONBLOCK, 0666)) >= 0)
+#ifdef HAVE_FCNTL_SETLK
+               if ((lock_fd = open(sock_path, O_WRONLY | O_NONBLOCK, 0666)) >= 0)
                {
                        struct flock    lck;
                        
@@ -618,6 +621,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                        if (fcntl(lock_fd, F_SETLK, &lck) != 0)
                                TPRINTF(TRACE_VERBOSE, "flock error for %s", sock_path);
                }
+#endif /* HAVE_FCNTL_SETLK */
        }
 
        listen(fd, SOMAXCONN);
index 1410d4c09f5aca361194022e212fa73d43b1373c..7b299662305c4babfaba61373320870f24d03121 100644 (file)
@@ -526,6 +526,15 @@ AC_TRY_LINK([#include <sys/types.h>
            [AC_DEFINE(HAVE_UNION_SEMUN) AC_MSG_RESULT(yes)],
            AC_MSG_RESULT(no))
 
+AC_MSG_CHECKING(for fcntl(F_SETLK))
+AC_TRY_LINK([#include <fcntl.h>],
+           [struct flock lck;
+            lck.l_whence = SEEK_SET; lck.l_start = lck.l_len = 0;
+            lck.l_type = F_WRLCK;
+            fcntl(0, F_SETLK, &lck);],
+           [AC_DEFINE(HAVE_FCNTL_SETLK) AC_MSG_RESULT(yes)],
+           AC_MSG_RESULT(no))
+
 AC_MSG_CHECKING(for good DBL_MIN)
 AC_TRY_RUN([#include <stdlib.h>
 #include <math.h>
index 44752346b517a1a8ad7350afeac08f6c92215b50..10c415c3a34e6e0176a96538ecb504cb1429c5c8 100644 (file)
@@ -207,6 +207,9 @@ extern void srandom(int seed);
 /* Set to 1 if you have union semun */
 #undef HAVE_UNION_SEMUN
 
+/* Set to 1 if you have F_SETLK option for fcntl() */
+#undef HAVE_FCNTL_SETLK
+
 /* Set to 1 if you want to USE_LOCALE */
 #undef USE_LOCALE