This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
gethostby... broken when forked
- To: gnu-win32 at cygnus dot com
- Subject: gethostby... broken when forked
- From: Jeff Smart <jeff at dtv dot net>
- Date: Thu, 04 Dec 1997 14:01:13 +1000
- Organization: DTV.net
I have found the BSD calls gethostbyname and gethostbyaddr break when
they are used in a child process that was forked.
I compiled this snippet on Win95 using gnu-win32 b18 with the latest
coolview dll and lib dated 26Nov97.
The code will always return an exception violation:
STATUS_ACCESS_VIOLATION once gethostbyname is called.
If fork() is removed, then gethostbyname works..
It appears fork() is screwing these address lookup calls.
I do not have the latest sources to find this bug. Has anyone else
found this nasty ?
Cheers,
Jeff
[----------------- begin -----------------------]
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(argc, argv)
int argc;
char *argv[];
{
struct hostent *hostptr; /* Internet host struct from netdb.h */
char hostname[256];
int childpid;
strcpy(hostname, argv[1]);
printf("PARENT STARTED PID=%d\n", getpid());
if ((childpid = fork()) < 0) {
printf("fork failed\n");
exit(0);
} else if (childpid == 0) { /* start child process */
printf("CHILD STARTED PID=%d\n", getpid());
hostptr = gethostbyname(hostname); /* BOMBS HERE */
printf("hostptr = %p\n", hostptr);
exit(0);
}
}
[--------------------- end --------------------]
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".