8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.285 2004/10/16 22:52:49 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.286 2004/10/21 20:23:19 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
18
18
#include <sys/types.h>
19
19
#include <sys/stat.h>
20
20
#include <fcntl.h>
21
- #include <errno.h>
22
21
#include <ctype.h>
23
22
#include <time.h>
23
+ #include <unistd.h>
24
24
25
25
#ifndef HAVE_STRDUP
26
26
#include "strdup.h"
51
51
#include "libpq/ip.h"
52
52
#include "mb/pg_wchar.h"
53
53
54
+ #ifndef FD_CLOEXEC
55
+ #define FD_CLOEXEC 1
56
+ #endif
57
+
58
+
54
59
#define PGPASSFILE ".pgpass"
55
60
56
61
/* fall back options if they are not specified by arguments or defined
@@ -766,28 +771,6 @@ update_db_info(PGconn *conn)
766
771
#endif /* NOT_USED */
767
772
768
773
769
- /* ----------
770
- * connectMakeNonblocking -
771
- * Make a connection non-blocking.
772
- * Returns 1 if successful, 0 if not.
773
- * ----------
774
- */
775
- static int
776
- connectMakeNonblocking (PGconn * conn )
777
- {
778
- if (!set_noblock (conn -> sock ))
779
- {
780
- char sebuf [256 ];
781
-
782
- printfPQExpBuffer (& conn -> errorMessage ,
783
- libpq_gettext ("could not set socket to non-blocking mode: %s\n" ),
784
- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
785
- return 0 ;
786
- }
787
-
788
- return 1 ;
789
- }
790
-
791
774
/* ----------
792
775
* connectNoDelay -
793
776
* Sets the TCP_NODELAY socket option.
@@ -1201,8 +1184,8 @@ PQconnectPoll(PGconn *conn)
1201
1184
1202
1185
/*
1203
1186
* Select socket options: no delay of outgoing data
1204
- * for TCP sockets, and nonblock mode. Fail if this
1205
- * fails.
1187
+ * for TCP sockets, nonblock mode, close-on-exec.
1188
+ * Fail if any of this fails.
1206
1189
*/
1207
1190
if (!IS_AF_UNIX (addr_cur -> ai_family ))
1208
1191
{
@@ -1214,13 +1197,29 @@ PQconnectPoll(PGconn *conn)
1214
1197
continue ;
1215
1198
}
1216
1199
}
1217
- if (connectMakeNonblocking (conn ) == 0 )
1200
+ if (! set_noblock (conn -> sock ) )
1218
1201
{
1202
+ printfPQExpBuffer (& conn -> errorMessage ,
1203
+ libpq_gettext ("could not set socket to non-blocking mode: %s\n" ),
1204
+ SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1205
+ closesocket (conn -> sock );
1206
+ conn -> sock = -1 ;
1207
+ conn -> addr_cur = addr_cur -> ai_next ;
1208
+ continue ;
1209
+ }
1210
+
1211
+ #ifdef F_SETFD
1212
+ if (fcntl (conn -> sock , F_SETFD , FD_CLOEXEC ) == -1 )
1213
+ {
1214
+ printfPQExpBuffer (& conn -> errorMessage ,
1215
+ libpq_gettext ("could not set socket to close-on-exec mode: %s\n" ),
1216
+ SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1219
1217
closesocket (conn -> sock );
1220
1218
conn -> sock = -1 ;
1221
1219
conn -> addr_cur = addr_cur -> ai_next ;
1222
1220
continue ;
1223
1221
}
1222
+ #endif /* F_SETFD */
1224
1223
1225
1224
/*
1226
1225
* Start/make connection. This should not block,
0 commit comments