Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e23ab9

Browse files
committed
Add configure test to make sure fcntl(SETLK) is available,
and make backend/libpq/pqcomm.c only try to lock the socket file whenthe call exists. Also, change open-RDONLY to open-WRONLY; at leaston my platform, you can't get a write lock on a file you didn't openfor writing.
1 parent16c6545 commit9e23ab9

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.54 1998/09/10 04:07:59 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.55 1998/10/06 02:31:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -560,7 +560,8 @@ StreamServerPort(char *hostName, short portName, int *fdP)
560560
* If the socket exists but nobody has an advisory lock on it we
561561
* can safely delete the file.
562562
*/
563-
if ((lock_fd=open(sock_path,O_RDONLY |O_NONBLOCK,0666)) >=0)
563+
#ifdefHAVE_FCNTL_SETLK
564+
if ((lock_fd=open(sock_path,O_WRONLY |O_NONBLOCK,0666)) >=0)
564565
{
565566
structflocklck;
566567

@@ -575,6 +576,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
575576
TPRINTF(TRACE_VERBOSE,"flock failed for %s",sock_path);
576577
close(lock_fd);
577578
}
579+
#endif/* HAVE_FCNTL_SETLK */
578580
}
579581
else
580582
{
@@ -609,7 +611,8 @@ StreamServerPort(char *hostName, short portName, int *fdP)
609611
* Open the socket file and get an advisory lock on it. The
610612
* lock_fd is left open to keep the lock.
611613
*/
612-
if ((lock_fd=open(sock_path,O_RDONLY |O_NONBLOCK,0666)) >=0)
614+
#ifdefHAVE_FCNTL_SETLK
615+
if ((lock_fd=open(sock_path,O_WRONLY |O_NONBLOCK,0666)) >=0)
613616
{
614617
structflocklck;
615618

@@ -618,6 +621,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
618621
if (fcntl(lock_fd,F_SETLK,&lck)!=0)
619622
TPRINTF(TRACE_VERBOSE,"flock error for %s",sock_path);
620623
}
624+
#endif/* HAVE_FCNTL_SETLK */
621625
}
622626

623627
listen(fd,SOMAXCONN);

‎src/configure.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ AC_TRY_LINK([#include <sys/types.h>
526526
[AC_DEFINE(HAVE_UNION_SEMUN) AC_MSG_RESULT(yes)],
527527
AC_MSG_RESULT(no))
528528

529+
AC_MSG_CHECKING(for fcntl(F_SETLK))
530+
AC_TRY_LINK([#include <fcntl.h>],
531+
[struct flock lck;
532+
lck.l_whence = SEEK_SET; lck.l_start = lck.l_len = 0;
533+
lck.l_type = F_WRLCK;
534+
fcntl(0, F_SETLK, &lck);],
535+
[AC_DEFINE(HAVE_FCNTL_SETLK) AC_MSG_RESULT(yes)],
536+
AC_MSG_RESULT(no))
537+
529538
AC_MSG_CHECKING(for good DBL_MIN)
530539
AC_TRY_RUN([#include <stdlib.h>
531540
#include <math.h>

‎src/include/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ extern void srandom(int seed);
207207
/* Set to 1 if you have union semun */
208208
#undef HAVE_UNION_SEMUN
209209

210+
/* Set to 1 if you have F_SETLK option for fcntl() */
211+
#undef HAVE_FCNTL_SETLK
212+
210213
/* Set to 1 if you want to USE_LOCALE */
211214
#undef USE_LOCALE
212215

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp