aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/port/unix_latch.c4
-rw-r--r--src/backend/postmaster/postmaster.c4
-rw-r--r--src/bin/pg_test_fsync/pg_test_fsync.c1
-rw-r--r--src/port/noblock.c24
4 files changed, 25 insertions, 8 deletions
diff --git a/src/backend/port/unix_latch.c b/src/backend/port/unix_latch.c
index 90ec4f81d9e..60a2d72a3ad 100644
--- a/src/backend/port/unix_latch.c
+++ b/src/backend/port/unix_latch.c
@@ -90,9 +90,9 @@ InitializeLatchSupport(void)
*/
if (pipe(pipefd) < 0)
elog(FATAL, "pipe() failed: %m");
- if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) == -1)
elog(FATAL, "fcntl() failed on read-end of self-pipe: %m");
- if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) == -1)
elog(FATAL, "fcntl() failed on write-end of self-pipe: %m");
selfpipe_readfd = pipefd[0];
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index e179430945c..d776e3f6c3c 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -6174,7 +6174,7 @@ InitPostmasterDeathWatchHandle(void)
* write fd. That is taken care of in ClosePostmasterPorts().
*/
Assert(MyProcPid == PostmasterPid);
- if (pipe(postmaster_alive_fds))
+ if (pipe(postmaster_alive_fds) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg_internal("could not create pipe to monitor postmaster death: %m")));
@@ -6183,7 +6183,7 @@ InitPostmasterDeathWatchHandle(void)
* Set O_NONBLOCK to allow testing for the fd's presence with a read()
* call.
*/
- if (fcntl(postmaster_alive_fds[POSTMASTER_FD_WATCH], F_SETFL, O_NONBLOCK))
+ if (fcntl(postmaster_alive_fds[POSTMASTER_FD_WATCH], F_SETFL, O_NONBLOCK) == -1)
ereport(FATAL,
(errcode_for_socket_access(),
errmsg_internal("could not set postmaster death monitoring pipe to nonblocking mode: %m")));
diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c
index c8427623d20..b4f3551b94a 100644
--- a/src/bin/pg_test_fsync/pg_test_fsync.c
+++ b/src/bin/pg_test_fsync/pg_test_fsync.c
@@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <sys/time.h>
+#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
diff --git a/src/port/noblock.c b/src/port/noblock.c
index 863c4107da2..2c8f4185e79 100644
--- a/src/port/noblock.c
+++ b/src/port/noblock.c
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* noblock.c
- * set a file descriptor as non-blocking
+ * set a file descriptor as blocking or non-blocking
*
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
@@ -17,11 +17,22 @@
#include <fcntl.h>
+/*
+ * Put socket into nonblock mode.
+ * Returns true on success, false on failure.
+ */
bool
pg_set_noblock(pgsocket sock)
{
#if !defined(WIN32)
- return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
+ int flags;
+
+ flags = fcntl(sock, F_GETFL);
+ if (flags < 0)
+ return false;
+ if (fcntl(sock, F_SETFL, (flags | O_NONBLOCK)) == -1)
+ return false;
+ return true;
#else
unsigned long ioctlsocket_ret = 1;
@@ -30,7 +41,10 @@ pg_set_noblock(pgsocket sock)
#endif
}
-
+/*
+ * Put socket into blocking mode.
+ * Returns true on success, false on failure.
+ */
bool
pg_set_block(pgsocket sock)
{
@@ -38,7 +52,9 @@ pg_set_block(pgsocket sock)
int flags;
flags = fcntl(sock, F_GETFL);
- if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
+ if (flags < 0)
+ return false;
+ if (fcntl(sock, F_SETFL, (flags & ~O_NONBLOCK)) == -1)
return false;
return true;
#else