diff options
author | Bruce Momjian <bruce@momjian.us> | 2014-03-21 13:45:11 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2014-03-21 13:45:11 -0400 |
commit | 6f03927fce038096f53ca67eeab9adb24938f8a6 (patch) | |
tree | e6ebc4031e1ec37c0766e1ae6baa83f39b0da227 /src/bin/pg_basebackup/pg_receivexlog.c | |
parent | 68a2e52bbaf98f136a96b3a0d734ca52ca440a95 (diff) | |
download | postgresql-6f03927fce038096f53ca67eeab9adb24938f8a6.tar.gz postgresql-6f03927fce038096f53ca67eeab9adb24938f8a6.zip |
Properly check for readdir/closedir() failures
Clear errno before calling readdir() and handle old MinGW errno bug
while adding full test coverage for readdir/closedir failures.
Backpatch through 8.4.
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivexlog.c')
-rw-r--r-- | src/bin/pg_basebackup/pg_receivexlog.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index c233779b89c..1eda4b6b002 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -139,7 +139,7 @@ FindStreamingStart(uint32 *tli) disconnect_and_exit(1); } - while ((dirent = readdir(dir)) != NULL) + while (errno = 0, (dirent = readdir(dir)) != NULL) { uint32 tli; XLogSegNo segno; @@ -209,7 +209,25 @@ FindStreamingStart(uint32 *tli) } } - closedir(dir); +#ifdef WIN32 + /* Bug in old Mingw dirent.c; fixed in mingw-runtime-3.2, 2003-10-10 */ + if (GetLastError() == ERROR_NO_MORE_FILES) + errno = 0; +#endif + + if (errno) + { + fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"), + progname, basedir, strerror(errno)); + disconnect_and_exit(1); + } + + if (closedir(dir)) + { + fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"), + progname, basedir, strerror(errno)); + disconnect_and_exit(1); + } if (high_segno > 0) { |