--- ray/src/rt/devcomm.c 2004/03/30 16:13:01 2.12 +++ ray/src/rt/devcomm.c 2011/10/05 17:20:55 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: devcomm.c,v 2.12 2004/03/30 16:13:01 schorsch Exp $"; +static const char RCSid[] = "$Id: devcomm.c,v 2.16 2011/10/05 17:20:55 greg Exp $"; #endif /* * devcomm.c - communication routines for separate drivers. @@ -10,8 +10,11 @@ static const char RCSid[] = "$Id: devcomm.c,v 2.12 200 #include "copyright.h" #include -#include /* XXX platform specific */ +#ifndef _WIN32 +#include +#endif +#include "paths.h" #include "platform.h" #include "standard.h" #include "driver.h" @@ -54,8 +57,10 @@ final_connect(void) /* verify and initialize connec getstate(); /* set error vectors */ erract[COMMAND].pf = comm_comout; + /* doesn't work with raypcalls.c if (erract[WARNING].pf != NULL) erract[WARNING].pf = comm_comout; + */ return(&comm_driver); } @@ -97,7 +102,7 @@ comm_init( /* set up and execute driver */ close(p2[0]); sprintf(pin, "%d", p1[0]); sprintf(pout, "%d", p2[1]); - execl(dvcname, dname, pin, pout, id, 0); + execl(dvcname, dname, pin, pout, id, NULL); perror(dvcname); _exit(127); } @@ -105,6 +110,12 @@ comm_init( /* set up and execute driver */ goto syserr; close(p1[0]); close(p2[1]); + /* + * Close write stream on exec to avoid multiprocessing deadlock. + * No use in read stream without it, so set flag there as well. + */ + fcntl(p1[1], F_SETFD, FD_CLOEXEC); + fcntl(p2[0], F_SETFD, FD_CLOEXEC); if ((devout = fdopen(p1[1], "w")) == NULL) goto syserr; if ((devin = fdopen(p2[0], "r")) == NULL) @@ -136,8 +147,10 @@ comm_close(void) /* done with driver */ fclose(devin); if (devchild < 0) return; +#ifndef _WIN32 while ((pid = wait(0)) != -1 && pid != devchild) ; +#endif }