Add some missing exit() calls in error paths for various binaries
authorMichael Paquier <michael@paquier.xyz>
Thu, 29 Jul 2021 02:42:58 +0000 (11:42 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 29 Jul 2021 02:42:58 +0000 (11:42 +0900)
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

src/bin/pg_archivecleanup/pg_archivecleanup.c
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pgbench/pgbench.c

index 12338e3bb2c26d83b1c507b515dfde659f3f5dbe..6c3e7f4e010c7683bf94eb1090d70b371d6c1580 100644 (file)
@@ -151,21 +151,30 @@ CleanupPriorWALFiles(void)
                                {
                                        pg_log_error("could not remove file \"%s\": %m",
                                                                 WALFilePath);
-                                       break;
+                                       exit(1);
                                }
                        }
                }
 
                if (errno)
+               {
                        pg_log_error("could not read archive location \"%s\": %m",
                                                 archiveLocation);
+                       exit(1);
+               }
                if (closedir(xldir))
+               {
                        pg_log_error("could not close archive location \"%s\": %m",
                                                 archiveLocation);
+                       exit(1);
+               }
        }
        else
+       {
                pg_log_error("could not open archive location \"%s\": %m",
                                         archiveLocation);
+               exit(1);
+       }
 }
 
 /*
index 8f69c573804f2773d1369edd932dffbffc1f262b..7296eb97d01c1b94db51cc9949b8c7fa9c0d6f5c 100644 (file)
@@ -1626,8 +1626,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
                                }
 #ifndef WIN32
                                if (chmod(state->filename, (mode_t) filemode))
+                               {
                                        pg_log_error("could not set permissions on directory \"%s\": %m",
                                                                 state->filename);
+                                       exit(1);
+                               }
 #endif
                        }
                        else if (copybuf[156] == '2')
@@ -1676,8 +1679,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
 
 #ifndef WIN32
                if (chmod(state->filename, (mode_t) filemode))
+               {
                        pg_log_error("could not set permissions on file \"%s\": %m",
                                                 state->filename);
+                       exit(1);
+               }
 #endif
 
                if (state->current_len_left == 0)
index 1d59bf37440a1c9f7c473ee41ac5c2ec1fdeeb09..ebeb12d497c5eb348c75f655cbca4b4bf1472f28 100644 (file)
@@ -341,7 +341,10 @@ StreamLogicalLog(void)
                        }
 
                        if (fstat(outfd, &statbuf) != 0)
+                       {
                                pg_log_error("could not stat file \"%s\": %m", outfile);
+                               goto error;
+                       }
 
                        output_isfile = S_ISREG(statbuf.st_mode) && !isatty(outfd);
                }
index c51ebb8e31d31638981f5d2e3fec6d0bfd19e131..55d14604c020723f1b67f9b4ec7e759b9324546d 100644 (file)
@@ -6469,7 +6469,10 @@ main(int argc, char **argv)
 
        errno = THREAD_BARRIER_INIT(&barrier, nthreads);
        if (errno != 0)
+       {
                pg_log_fatal("could not initialize barrier: %m");
+               exit(1);
+       }
 
 #ifdef ENABLE_THREAD_SAFETY
        /* start all threads but thread 0 which is executed directly later */