Kevin Brown <[EMAIL PROTECTED]> 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;
}

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to