Skip to content

Commit 6c72a28

Browse files
committed
Suppress -Wunused-result warnings about write(), again.
Adopt the same solution as in commit aa90e14, 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.
1 parent e1623c3 commit 6c72a28

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/bin/pg_dump/parallel.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,18 @@ static volatile DumpSignalInformation signal_info;
137137
static CRITICAL_SECTION signal_info_lock;
138138
#endif
139139

140-
/* Used from signal handlers, no buffering */
141-
#define write_stderr(str) write(fileno(stderr), str, strlen(str))
140+
/*
141+
* Write a simple string to stderr --- must be safe in a signal handler.
142+
* We ignore the write() result since there's not much we could do about it.
143+
* Certain compilers make that harder than it ought to be.
144+
*/
145+
#define write_stderr(str) \
146+
do { \
147+
const char *str_ = (str); \
148+
int rc_; \
149+
rc_ = write(fileno(stderr), str_, strlen(str_)); \
150+
(void) rc_; \
151+
} while (0)
142152

143153

144154
#ifdef WIN32

src/bin/psql/common.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,18 @@ static PGcancel *volatile cancelConn = NULL;
235235
static CRITICAL_SECTION cancelConnLock;
236236
#endif
237237

238-
/* Used from signal handlers, no buffering */
239-
#define write_stderr(str) write(fileno(stderr), str, strlen(str))
238+
/*
239+
* Write a simple string to stderr --- must be safe in a signal handler.
240+
* We ignore the write() result since there's not much we could do about it.
241+
* Certain compilers make that harder than it ought to be.
242+
*/
243+
#define write_stderr(str) \
244+
do { \
245+
const char *str_ = (str); \
246+
int rc_; \
247+
rc_ = write(fileno(stderr), str_, strlen(str_)); \
248+
(void) rc_; \
249+
} while (0)
240250

241251

242252
#ifndef WIN32
@@ -245,7 +255,6 @@ static void
245255
handle_sigint(SIGNAL_ARGS)
246256
{
247257
int save_errno = errno;
248-
int rc;
249258
char errbuf[256];
250259

251260
/* if we are waiting for input, longjmp out of it */
@@ -262,16 +271,11 @@ handle_sigint(SIGNAL_ARGS)
262271
if (cancelConn != NULL)
263272
{
264273
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
265-
{
266-
rc = write_stderr("Cancel request sent\n");
267-
(void) rc; /* ignore errors, nothing we can do here */
268-
}
274+
write_stderr("Cancel request sent\n");
269275
else
270276
{
271-
rc = write_stderr("Could not send cancel request: ");
272-
(void) rc; /* ignore errors, nothing we can do here */
273-
rc = write_stderr(errbuf);
274-
(void) rc; /* ignore errors, nothing we can do here */
277+
write_stderr("Could not send cancel request: ");
278+
write_stderr(errbuf);
275279
}
276280
}
277281

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy