This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

fork + dlls



I'm having a problem that when I manually load a dll with dlopen,
that after the fork the dll is not accessible from the child process.

There was an old thread on this topic that suggested that this should
work, but with the following code the child fails when calling dll1_func:

forkbug1.c:

	#include <stdio.h>
	#include <unistd.h>
	#include <sys/wait.h>
	#include <dlfcn.h>

	int main()
	{
	    int	child, pid, status;
	    void	*dll1_dll;
	    void	(*dll1_func)();

	    dll1_dll = dlopen("libdll1.dll", RTLD_LAZY);
	    dll1_func = dlsym(dll1_dll, "dll1_func");

	    if((child = fork()) == 0) {
		fprintf(stderr, "in child\n");
		dll1_func("child");
		exit(0);
	    }

	    pid = wait(&status);
	    fprintf(stderr, "pid=%d status=%d\n", pid, status);
	    dll1_func("parent");

	    return 0;
	}

libdll1.c:

	#include <stdio.h>

	#define DLLIMPORT __declspec (dllexport)

	DLLIMPORT int
	dll1_func(char *msg)
	{
	    fprintf(stderr, "dll1_func=%s\n", msg);
	    return 1;
	}

Makefile:

	CFLAGS	= -g -Wall
	LDFLAGS = -g

	all: libdll1.dll forkbug1

	forkbug1: forkbug1.o
		$(CC) $(LDFLAGS) -o forkbug1 forkbug1.o

	%.dll: %.o
		dllwrap --export-all --output-def $*.def \
			--output-lib $*.a -o $@ $<
output:
	in child
	[and a Win32 popup - "forkbug1.exe - Application Error" - Click OK]
	pid=3784 status=1280
	dll1_func=parent
	
I also tried RTLD_NOW and RTLD_GLOBAL, but the behavior is the same.
I'm using b20.1 and egcs-1.1.2.

I originally spotted this problem while using perl, and boiled down
the problem to this simple example.  

Thanks.

Eric Fifer

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]