Skip to content

Commit 9add9f9

Browse files
committed
Don't actively violate the system limit of maximum open files (RLIMIT_NOFILE).
This avoids irritating kernel logs (if system overstep violations are enabled) and also the grsecurity alert when starting PostgreSQL. original patch by Jacek Drobiecki References: http://archives.postgresql.org/pgsql-bugs/2004-05/msg00103.php http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=248967
1 parent a2e9de7 commit 9add9f9

File tree

1 file changed

+24
-1
lines changed
  • src/backend/storage/file

1 file changed

+24
-1
lines changed

src/backend/storage/file/fd.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.147 2009/01/12 05:10:44 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.148 2009/03/04 09:12:49 petere Exp $
1111
*
1212
* NOTES:
1313
*
@@ -45,6 +45,9 @@
4545
#include <sys/stat.h>
4646
#include <unistd.h>
4747
#include <fcntl.h>
48+
#ifdef HAVE_SYS_RESOURCE_H
49+
#include <sys/resource.h> /* for getrlimit */
50+
#endif
4851

4952
#include "miscadmin.h"
5053
#include "access/xact.h"
@@ -361,15 +364,35 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
361364
int used = 0;
362365
int highestfd = 0;
363366
int j;
367+
#ifdef HAVE_GETRLIMIT
368+
struct rlimit rlim;
369+
int getrlimit_status;
370+
#endif
364371

365372
size = 1024;
366373
fd = (int *) palloc(size * sizeof(int));
367374

375+
#ifdef HAVE_GETRLIMIT
376+
# ifdef RLIMIT_NOFILE /* most platforms use RLIMIT_NOFILE */
377+
getrlimit_status = getrlimit(RLIMIT_NOFILE, &rlim);
378+
# else /* but BSD doesn't ... */
379+
getrlimit_status = getrlimit(RLIMIT_OFILE, &rlim);
380+
# endif /* RLIMIT_NOFILE */
381+
if (getrlimit_status != 0)
382+
ereport(WARNING, (errmsg("getrlimit failed: %m")));
383+
#endif /* HAVE_GETRLIMIT */
384+
368385
/* dup until failure or probe limit reached */
369386
for (;;)
370387
{
371388
int thisfd;
372389

390+
#ifdef HAVE_GETRLIMIT
391+
/* don't go beyond RLIMIT_NOFILE; causes irritating kernel logs on some platforms */
392+
if (getrlimit_status == 0 && highestfd >= rlim.rlim_cur - 1)
393+
break;
394+
#endif
395+
373396
thisfd = dup(0);
374397
if (thisfd < 0)
375398
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy