Skip site navigation (1) Skip section navigation (2)

Re: Too-many-files errors on OS X

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kevin Brown <kevin(at)sysexperts(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Too-many-files errors on OS X
Date: 2004-02-23 04:00:31
Message-ID: 20640.1077508831@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Kevin Brown <kevin(at)sysexperts(dot)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() later on 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 ("Was able to use %d file descriptors after opening %d shared libs\n", n, na);
	return 0;
}

In response to

Responses

pgsql-hackers by date

Next:From: Claudio NatoliDate: 2004-02-23 04:04:34
Subject: Re: Too-many-files errors on OS X
Previous:From: Tom LaneDate: 2004-02-23 03:41:40
Subject: Re: Too-many-files errors on OS X

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group