Skip to content

Commit ec56223

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 4044290 commit ec56223

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
@@ -136,8 +136,18 @@ static volatile DumpSignalInformation signal_info;
136136
static CRITICAL_SECTION signal_info_lock;
137137
#endif
138138

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

142152

143153
#ifdef WIN32

src/bin/psql/common.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,18 @@ static PGcancel *volatile cancelConn = NULL;
175175
static CRITICAL_SECTION cancelConnLock;
176176
#endif
177177

178-
/* Used from signal handlers, no buffering */
179-
#define write_stderr(str) write(fileno(stderr), str, strlen(str))
178+
/*
179+
* Write a simple string to stderr --- must be safe in a signal handler.
180+
* We ignore the write() result since there's not much we could do about it.
181+
* Certain compilers make that harder than it ought to be.
182+
*/
183+
#define write_stderr(str) \
184+
do { \
185+
const char *str_ = (str); \
186+
int rc_; \
187+
rc_ = write(fileno(stderr), str_, strlen(str_)); \
188+
(void) rc_; \
189+
} while (0)
180190

181191

182192
#ifndef WIN32
@@ -185,7 +195,6 @@ static void
185195
handle_sigint(SIGNAL_ARGS)
186196
{
187197
int save_errno = errno;
188-
int rc;
189198
char errbuf[256];
190199

191200
/* if we are waiting for input, longjmp out of it */
@@ -202,16 +211,11 @@ handle_sigint(SIGNAL_ARGS)
202211
if (cancelConn != NULL)
203212
{
204213
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
205-
{
206-
rc = write_stderr("Cancel request sent\n");
207-
(void) rc; /* ignore errors, nothing we can do here */
208-
}
214+
write_stderr("Cancel request sent\n");
209215
else
210216
{
211-
rc = write_stderr("Could not send cancel request: ");
212-
(void) rc; /* ignore errors, nothing we can do here */
213-
rc = write_stderr(errbuf);
214-
(void) rc; /* ignore errors, nothing we can do here */
217+
write_stderr("Could not send cancel request: ");
218+
write_stderr(errbuf);
215219
}
216220
}
217221

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