--- ray/src/rt/persist.c 2004/03/30 16:13:01 2.34 +++ ray/src/rt/persist.c 2013/11/08 18:08:07 2.43 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: persist.c,v 2.34 2004/03/30 16:13:01 schorsch Exp $"; +static const char RCSid[] = "$Id: persist.c,v 2.43 2013/11/08 18:08:07 greg Exp $"; #endif /* * Routines for persistent rtrace and rpict processes. @@ -12,8 +12,13 @@ static const char RCSid[] = "$Id: persist.c,v 2.34 200 #include #include #include +#include #include "platform.h" +#ifndef NON_POSIX /* XXX need abstraction for process management */ + #include +#endif + #include "rtprocess.h" /* getpid() */ #include "standard.h" #include "random.h" @@ -34,12 +39,12 @@ static char *persistfname = NULL; /* persist file name static int persistfd = -1; /* persist file descriptor */ static char inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1]; -typedef void (sighandler_t)(int); -static sighandler_t sig_io; -static sighandler_t sig_alrm; +typedef void (rsighandler_t)(int); +static rsighandler_t sig_io; +static rsighandler_t sig_alrm; -extern void +void pfdetach(void) /* release persist (and header) resources */ { if (persistfd >= 0) @@ -53,7 +58,7 @@ pfdetach(void) /* release persist (and header) resour } -extern void +void pfclean(void) /* clean up persist files */ { if (persistfd >= 0) @@ -69,7 +74,7 @@ pfclean(void) /* clean up persist files */ } -extern void +void pflock( /* place or release exclusive lock on file */ int lf ) @@ -85,7 +90,7 @@ pflock( /* place or release exclusive lock on file */ } -extern void +void persistfile( /* open persist file and lock it */ char *pfn ) @@ -114,17 +119,17 @@ static void sig_io(int i) { got_io++; } static void sig_alrm(int i) { quit(0); } -extern void +void pfhold(void) /* holding pattern for idle rendering process */ { - sighandler_t *oldalrm; + rsighandler_t *oldalrm; char buf[512]; - register int n; + int n; /* close input and output descriptors */ - close(fileno(stdin)); - close(fileno(stdout)); + close(0); + close(1); if (errfile == NULL) - close(fileno(stderr)); + close(2); /* create named pipes for input and output */ if (mkfifo(mktemp(strcpy(inpname,TEMPLATE)), 0600) < 0) goto createrr; @@ -152,12 +157,6 @@ pfhold(void) /* holding pattern for idle rendering pr signal(SIGIO, SIG_DFL); pflock(1); /* grab persist file back */ /* someone wants us; reopen stdin and stdout */ - /* - if (freopen(inpname, "r", stdin) == NULL) - goto openerr; - if (freopen(outpname, "w", stdout) == NULL) - goto openerr; - */ close(0); if (open(inpname, O_RDONLY) != 0) error(INTERNAL, "unexpected stdin file number"); @@ -180,16 +179,14 @@ pfhold(void) /* holding pattern for idle rendering pr return; createrr: error(SYSTEM, "cannot create named pipes in pfhold"); -openerr: - error(SYSTEM, "cannot open named pipes in pfhold"); } -extern void +void io_process(void) /* just act as go-between for actual process */ { - register char *cp; - register int nr, n; + char *cp; + int nr, n; char buf[BUFSIZ], *pfin, *pfout, *pferr; int pid, nfds; int fdout, fderr = -1; @@ -300,7 +297,7 @@ io_process(void) /* just act as go-between for actual if (!strncmp(cp, progname, n) && cp[n++] == ':' && cp[n++] == ' ') { - register struct erract *ep; + struct erract *ep; for (ep = erract; ep < erract+NERRS; ep++) if (ep->pre[0] && @@ -335,7 +332,8 @@ io_process(void) /* just act as go-between for actual } while ((nr -= n) > 0); } } - wait(0); /* wait for feeder process */ /* XXX platform */ + kill(pid, SIGTERM); /* no more process to feed, so... */ + waitpid(pid, 0, 0); /* wait for feeder process */ _exit(status); formerr: error(USER, "format error in persist file"); @@ -347,6 +345,6 @@ writerr: #else -extern void pfclean(void) {} +void pfclean(void) {} #endif