aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-06-03 11:29:20 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-06-03 11:29:20 -0400
commitec5622351208989620b6563b7890922e28e65e7b (patch)
tree4ab68b0c920e2b5b0c802cfc6d77d31659dd7afa /src
parent404429038896d914f38e1ee80d6d6905be0ad261 (diff)
downloadpostgresql-ec5622351208989620b6563b7890922e28e65e7b.tar.gz
postgresql-ec5622351208989620b6563b7890922e28e65e7b.zip
Suppress -Wunused-result warnings about write(), again.
Adopt the same solution as in commit aa90e148ca70a235, but this time let's put the ugliness inside the write_stderr() macro, instead of expecting each call site to deal with it. Back-port that decision into psql/common.c where I got the macro from in the first place. Per gripe from Peter Eisentraut.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/parallel.c14
-rw-r--r--src/bin/psql/common.c26
2 files changed, 27 insertions, 13 deletions
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index 03bf732f645..51a8eee369d 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -136,8 +136,18 @@ static volatile DumpSignalInformation signal_info;
static CRITICAL_SECTION signal_info_lock;
#endif
-/* Used from signal handlers, no buffering */
-#define write_stderr(str) write(fileno(stderr), str, strlen(str))
+/*
+ * Write a simple string to stderr --- must be safe in a signal handler.
+ * We ignore the write() result since there's not much we could do about it.
+ * Certain compilers make that harder than it ought to be.
+ */
+#define write_stderr(str) \
+ do { \
+ const char *str_ = (str); \
+ int rc_; \
+ rc_ = write(fileno(stderr), str_, strlen(str_)); \
+ (void) rc_; \
+ } while (0)
#ifdef WIN32
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index a287eeee195..39c88fce7de 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -175,8 +175,18 @@ static PGcancel *volatile cancelConn = NULL;
static CRITICAL_SECTION cancelConnLock;
#endif
-/* Used from signal handlers, no buffering */
-#define write_stderr(str) write(fileno(stderr), str, strlen(str))
+/*
+ * Write a simple string to stderr --- must be safe in a signal handler.
+ * We ignore the write() result since there's not much we could do about it.
+ * Certain compilers make that harder than it ought to be.
+ */
+#define write_stderr(str) \
+ do { \
+ const char *str_ = (str); \
+ int rc_; \
+ rc_ = write(fileno(stderr), str_, strlen(str_)); \
+ (void) rc_; \
+ } while (0)
#ifndef WIN32
@@ -185,7 +195,6 @@ static void
handle_sigint(SIGNAL_ARGS)
{
int save_errno = errno;
- int rc;
char errbuf[256];
/* if we are waiting for input, longjmp out of it */
@@ -202,16 +211,11 @@ handle_sigint(SIGNAL_ARGS)
if (cancelConn != NULL)
{
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
- {
- rc = write_stderr("Cancel request sent\n");
- (void) rc; /* ignore errors, nothing we can do here */
- }
+ write_stderr("Cancel request sent\n");
else
{
- rc = write_stderr("Could not send cancel request: ");
- (void) rc; /* ignore errors, nothing we can do here */
- rc = write_stderr(errbuf);
- (void) rc; /* ignore errors, nothing we can do here */
+ write_stderr("Could not send cancel request: ");
+ write_stderr(errbuf);
}
}