gethostby... broken when forked
Jeff Smart
jeff@dtv.net
Wed Dec 3 23:14:00 GMT 1997
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".
More information about the Cygwin
mailing list