Skip to content

Commit 856de3b

Browse files
committed
Add some missing exit() calls in error paths for various binaries
The following changes are done: - In pg_archivecleanup, the cleanup of older WAL segments would never fail immediately. - In pgbench, the initialization of a thread barrier would not fail hard. - In pg_recvlogical, a stat() failure never got the call. - In pg_basebackup, two chmod() reported a failure without exit()'ing when unpacking some tar data freshly received. It may be possible to continue writing some data even after this failure, but that could be confusing to the user at the end. These are arguably bugs, but they would happen for code paths where a failure is unlikely going to happen, so no backpatch is done. Reviewed-by: Robert Haas, Fabien Coelho Discussion: https://postgr.es/m/YQDMdB+B68yePFeT@paquier.xyz
1 parent 2ad98fd commit 856de3b

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/bin/pg_archivecleanup/pg_archivecleanup.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,30 @@ CleanupPriorWALFiles(void)
151151
{
152152
pg_log_error("could not remove file \"%s\": %m",
153153
WALFilePath);
154-
break;
154+
exit(1);
155155
}
156156
}
157157
}
158158

159159
if (errno)
160+
{
160161
pg_log_error("could not read archive location \"%s\": %m",
161162
archiveLocation);
163+
exit(1);
164+
}
162165
if (closedir(xldir))
166+
{
163167
pg_log_error("could not close archive location \"%s\": %m",
164168
archiveLocation);
169+
exit(1);
170+
}
165171
}
166172
else
173+
{
167174
pg_log_error("could not open archive location \"%s\": %m",
168175
archiveLocation);
176+
exit(1);
177+
}
169178
}
170179

171180
/*

src/bin/pg_basebackup/pg_basebackup.c

+6
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
16261626
}
16271627
#ifndef WIN32
16281628
if (chmod(state->filename, (mode_t) filemode))
1629+
{
16291630
pg_log_error("could not set permissions on directory \"%s\": %m",
16301631
state->filename);
1632+
exit(1);
1633+
}
16311634
#endif
16321635
}
16331636
else if (copybuf[156] == '2')
@@ -1676,8 +1679,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
16761679

16771680
#ifndef WIN32
16781681
if (chmod(state->filename, (mode_t) filemode))
1682+
{
16791683
pg_log_error("could not set permissions on file \"%s\": %m",
16801684
state->filename);
1685+
exit(1);
1686+
}
16811687
#endif
16821688

16831689
if (state->current_len_left == 0)

src/bin/pg_basebackup/pg_recvlogical.c

+3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ StreamLogicalLog(void)
341341
}
342342

343343
if (fstat(outfd, &statbuf) != 0)
344+
{
344345
pg_log_error("could not stat file \"%s\": %m", outfile);
346+
goto error;
347+
}
345348

346349
output_isfile = S_ISREG(statbuf.st_mode) && !isatty(outfd);
347350
}

src/bin/pgbench/pgbench.c

+3
Original file line numberDiff line numberDiff line change
@@ -6469,7 +6469,10 @@ main(int argc, char **argv)
64696469

64706470
errno = THREAD_BARRIER_INIT(&barrier, nthreads);
64716471
if (errno != 0)
6472+
{
64726473
pg_log_fatal("could not initialize barrier: %m");
6474+
exit(1);
6475+
}
64736476

64746477
#ifdef ENABLE_THREAD_SAFETY
64756478
/* start all threads but thread 0 which is executed directly later */

0 commit comments

Comments
 (0)