1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Replace opendir/closedir calls throughout the backend with AllocateDir

and FreeDir routines modeled on the existing AllocateFile/FreeFile.
Like the latter, these routines will avoid failing on EMFILE/ENFILE
conditions whenever possible, and will prevent leakage of directory
descriptors if an elog() occurs while one is open.
Also, reduce PANIC to ERROR in MoveOfflineLogs() --- this is not
critical code and there is no reason to force a DB restart on failure.
All per recent trouble report from Olivier Hubaut.
This commit is contained in:
Tom Lane
2004-02-23 23:03:10 +00:00
parent 4f571319d3
commit 7a57a67278
6 changed files with 138 additions and 41 deletions

View File

@ -1,16 +1,15 @@
#include "postgres.h"
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "commands/dbcommands.h"
#include "fmgr.h"
#include "storage/fd.h"
#include "utils/builtins.h"
@ -58,7 +57,7 @@ database_size(PG_FUNCTION_ARGS)
dbpath = GetDatabasePath(dbid);
dirdesc = opendir(dbpath);
dirdesc = AllocateDir(dbpath);
if (!dirdesc)
ereport(ERROR,
(errcode_for_file_access(),
@ -93,7 +92,7 @@ database_size(PG_FUNCTION_ARGS)
pfree(fullname);
}
closedir(dirdesc);
FreeDir(dirdesc);
PG_RETURN_INT64(totalsize);
}