diff -ruN postgresql-7.4.2-old/src/backend/storage/file/fd.c postgresql-7.4.2/src/backend/storage/file/fd.c --- postgresql-7.4.2-old/src/backend/storage/file/fd.c 2004-02-24 00:03:43.000000000 +0100 +++ postgresql-7.4.2/src/backend/storage/file/fd.c 2004-05-17 13:31:44.000000000 +0200 @@ -50,6 +50,9 @@ #include "storage/fd.h" #include "storage/ipc.h" +#ifdef CHECK_RLIMIT_NOFILE +#include +#endif /* Filename components for OpenTemporaryFile */ #define PG_TEMP_FILES_DIR "pgsql_tmp" @@ -272,15 +275,28 @@ int used = 0; int highestfd = 0; int j; +#ifdef CHECK_RLIMIT_NOFILE + struct rlimit rlim; +#endif size = 1024; fd = (int *) palloc(size * sizeof(int)); +#ifdef CHECK_RLIMIT_NOFILE + getrlimit(RLIMIT_NOFILE, &rlim); +#endif + /* dup until failure ... */ for (;;) { int thisfd; +#ifdef CHECK_RLIMIT_NOFILE + /* Don't go beyond RLIMIT_NOFILE */ + if (highestfd >= rlim.rlim_cur - 1) + break; +#endif + thisfd = dup(0); if (thisfd < 0) {