diff options
Diffstat (limited to 'src/bin/pg_resetxlog/pg_resetxlog.c')
-rw-r--r-- | src/bin/pg_resetxlog/pg_resetxlog.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 28a4f191f34..af2cec7e932 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -821,8 +821,7 @@ FindEndOfXLOG(void) exit(1); } - errno = 0; - while ((xlde = readdir(xldir)) != NULL) + while (errno = 0, (xlde = readdir(xldir)) != NULL) { if (strlen(xlde->d_name) == 24 && strspn(xlde->d_name, "0123456789ABCDEF") == 24) @@ -844,25 +843,27 @@ FindEndOfXLOG(void) if (segno > newXlogSegNo) newXlogSegNo = segno; } - errno = 0; } #ifdef WIN32 - /* - * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in - * released version - */ + /* 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 from directory \"%s\": %s\n"), + fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"), + progname, XLOGDIR, strerror(errno)); + exit(1); + } + + if (closedir(xldir)) + { + fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"), progname, XLOGDIR, strerror(errno)); exit(1); } - closedir(xldir); /* * Finally, convert to new xlog seg size, and advance by one to ensure we @@ -892,8 +893,7 @@ KillExistingXLOG(void) exit(1); } - errno = 0; - while ((xlde = readdir(xldir)) != NULL) + while (errno = 0, (xlde = readdir(xldir)) != NULL) { if (strlen(xlde->d_name) == 24 && strspn(xlde->d_name, "0123456789ABCDEF") == 24) @@ -906,25 +906,27 @@ KillExistingXLOG(void) exit(1); } } - errno = 0; } #ifdef WIN32 - /* - * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in - * released version - */ + /* 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 from directory \"%s\": %s\n"), + fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"), + progname, XLOGDIR, strerror(errno)); + exit(1); + } + + if (closedir(xldir)) + { + fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"), progname, XLOGDIR, strerror(errno)); exit(1); } - closedir(xldir); } @@ -948,8 +950,7 @@ KillExistingArchiveStatus(void) exit(1); } - errno = 0; - while ((xlde = readdir(xldir)) != NULL) + while (errno = 0, (xlde = readdir(xldir)) != NULL) { if (strspn(xlde->d_name, "0123456789ABCDEF") == 24 && (strcmp(xlde->d_name + 24, ".ready") == 0 || @@ -963,25 +964,27 @@ KillExistingArchiveStatus(void) exit(1); } } - errno = 0; } #ifdef WIN32 - /* - * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in - * released version - */ + /* 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 from directory \"%s\": %s\n"), + fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"), + progname, ARCHSTATDIR, strerror(errno)); + exit(1); + } + + if (closedir(xldir)) + { + fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"), progname, ARCHSTATDIR, strerror(errno)); exit(1); } - closedir(xldir); } |