mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
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.
This commit is contained in:
@ -106,7 +106,7 @@ CleanupPriorWALFiles(void)
|
||||
|
||||
if ((xldir = opendir(archiveLocation)) != NULL)
|
||||
{
|
||||
while ((xlde = readdir(xldir)) != NULL)
|
||||
while (errno = 0, (xlde = readdir(xldir)) != NULL)
|
||||
{
|
||||
strncpy(walfile, xlde->d_name, MAXPGPATH);
|
||||
TrimExtension(walfile, additional_ext);
|
||||
@ -164,7 +164,19 @@ CleanupPriorWALFiles(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(xldir);
|
||||
|
||||
#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 archive location \"%s\": %s\n",
|
||||
progname, archiveLocation, strerror(errno));
|
||||
if (closedir(xldir))
|
||||
fprintf(stderr, "%s: could not close archive location \"%s\": %s\n",
|
||||
progname, archiveLocation, strerror(errno));
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "%s: could not open archive location \"%s\": %s\n",
|
||||
|
@ -245,7 +245,7 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
*/
|
||||
if ((xldir = opendir(archiveLocation)) != NULL)
|
||||
{
|
||||
while ((xlde = readdir(xldir)) != NULL)
|
||||
while (errno = 0, (xlde = readdir(xldir)) != NULL)
|
||||
{
|
||||
/*
|
||||
* We ignore the timeline part of the XLOG segment identifiers
|
||||
@ -283,6 +283,16 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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 archive location \"%s\": %s\n",
|
||||
progname, archiveLocation, strerror(errno));
|
||||
if (debug)
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@ -290,7 +300,10 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
fprintf(stderr, "%s: could not open archive location \"%s\": %s\n",
|
||||
progname, archiveLocation, strerror(errno));
|
||||
|
||||
closedir(xldir);
|
||||
if (closedir(xldir))
|
||||
fprintf(stderr, "%s: could not close archive location \"%s\": %s\n",
|
||||
progname, archiveLocation, strerror(errno));
|
||||
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user