Re: Too-many-files errors on OS X - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Too-many-files errors on OS X
Date
Msg-id 20640.1077508831@sss.pgh.pa.us
Whole thread Raw
In response to Re: Too-many-files errors on OS X  (Kevin Brown <kevin@sysexperts.com>)
Responses Re: Too-many-files errors on OS X  (Joe Conway <mail@joeconway.com>)
Re: Too-many-files errors on OS X  (Larry Rosenman <ler@lerctr.org>)
List pgsql-hackers
Kevin Brown <kevin@sysexperts.com> writes:
> I wasn't able to test on HP-UX

I get the same result on HPUX, after whacking the test program around
a bit: no change in the number of files we can open.  Confirmations on
other platforms please, anyone?

For anyone else who has problems getting it to compile, try copying
the relevant version of pg_dlopen from src/backend/port/dynloader/.
I attach the code I actually ran on HPUX.
        regards, tom lane


#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
//#include <dlfcn.h>
// these seem to be needed on HPUX:
#include <a.out.h>
#include <dl.h>

int *fd;
int size = 1024;

void *
pg_dlopen(char *filename)
{/* * Use BIND_IMMEDIATE so that undefined symbols cause a failure return * from shl_load(), rather than an abort()
lateron when we attempt to * call the library! */shl_t        handle = shl_load(filename,
BIND_IMMEDIATE| BIND_VERBOSE | DYNAMIC_PATH,                              0L);
 
return (void *) handle;
}


int eatallfds(void) {int i = 0;int j, myfd;
while (1) {    myfd = dup(0);    if (myfd < 0) {        fprintf (stderr, "dup() failed: %s\n", strerror(errno));
break;   }    fd[i++] = myfd;    if (i >= size) {        size *= 2;        fd = realloc(fd, size);        if (fd ==
NULL){            fprintf (stderr, "Can't allocate: %s\n",                    strerror(errno));            fprintf
(stderr,"Had used %d descriptors\n",                    i);            exit(1);        }    }}for (j = 0 ; j < i ; ++j)
{   close(fd[j]);}return i;
 
}


int main (int argc, char *argv[]) {int n, na;int i;void *addr;
size = 1024;fd = malloc(size * sizeof(*fd));if (fd == NULL) {    fprintf (stderr, "Can't allocate: %s\n",
strerror(errno));   return 1;}n = eatallfds();printf ("Was able to use %d file descriptors\n", n);
 
na = 0;for (i = 1 ; i < argc ; ++i) {    addr = pg_dlopen(argv[i]);    if (addr != NULL) na++;}n = eatallfds();printf
("Wasable to use %d file descriptors after opening %d shared libs\n", n, na);return 0;
 
}


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Too-many-files errors on OS X
Next
From: Claudio Natoli
Date:
Subject: Re: Too-many-files errors on OS X