Skip to content

Commit 4a21c6f

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 5c97243 commit 4a21c6f

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
@@ -156,8 +156,18 @@ static PGcancel *volatile cancelConn = NULL;
156156
static CRITICAL_SECTION cancelConnLock;
157157
#endif
158158

159-
/* Used from signal handlers, no buffering */
160-
#define write_stderr(str) write(fileno(stderr), str, strlen(str))
159+
/*
160+
* Write a simple string to stderr --- must be safe in a signal handler.
161+
* We ignore the write() result since there's not much we could do about it.
162+
* Certain compilers make that harder than it ought to be.
163+
*/
164+
#define write_stderr(str) \
165+
do { \
166+
const char *str_ = (str); \
167+
int rc_; \
168+
rc_ = write(fileno(stderr), str_, strlen(str_)); \
169+
(void) rc_; \
170+
} while (0)
161171

162172

163173
#ifndef WIN32
@@ -166,7 +176,6 @@ static void
166176
handle_sigint(SIGNAL_ARGS)
167177
{
168178
int save_errno = errno;
169-
int rc;
170179
char errbuf[256];
171180

172181
/* if we are waiting for input, longjmp out of it */
@@ -183,16 +192,11 @@ handle_sigint(SIGNAL_ARGS)
183192
if (cancelConn != NULL)
184193
{
185194
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
186-
{
187-
rc = write_stderr("Cancel request sent\n");
188-
(void) rc; /* ignore errors, nothing we can do here */
189-
}
195+
write_stderr("Cancel request sent\n");
190196
else
191197
{
192-
rc = write_stderr("Could not send cancel request: ");
193-
(void) rc; /* ignore errors, nothing we can do here */
194-
rc = write_stderr(errbuf);
195-
(void) rc; /* ignore errors, nothing we can do here */
198+
write_stderr("Could not send cancel request: ");
199+
write_stderr(errbuf);
196200
}
197201
}
198202

0 commit comments

Comments
 (0)