www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/05/21/08:51:34

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <71E287AB0D94D111BBD600600849EC8185EDBD@POST>
From: "Fifer, Eric" <EFifer AT sanwaint DOT com>
To: "'cygwin AT sourceware DOT cygnus DOT com'" <cygwin AT sourceware DOT cygnus DOT com>
Subject: fork + dlls
Date: Fri, 21 May 1999 13:49:21 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2232.9)

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 AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019