--- ray/src/rt/persist.c 2003/02/22 02:07:29 2.26 +++ ray/src/rt/persist.c 2004/09/19 07:24:37 2.36 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: persist.c,v 2.26 2003/02/22 02:07:29 greg Exp $"; +static const char RCSid[] = "$Id: persist.c,v 2.36 2004/09/19 07:24:37 greg Exp $"; #endif /* * Routines for persistent rtrace and rpict processes. @@ -7,96 +7,40 @@ static const char RCSid[] = "$Id: persist.c,v 2.26 200 * External symbols declared in ray.h */ -/* ==================================================================== - * The Radiance Software License, Version 1.0 - * - * Copyright (c) 1990 - 2002 The Regents of the University of California, - * through Lawrence Berkeley National Laboratory. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes Radiance software - * (http://radsite.lbl.gov/) - * developed by the Lawrence Berkeley National Laboratory - * (http://www.lbl.gov/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" - * and "The Regents of the University of California" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact radiance@radsite.lbl.gov. - * - * 5. Products derived from this software may not be called "Radiance", - * nor may "Radiance" appear in their name, without prior written - * permission of Lawrence Berkeley National Laboratory. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of Lawrence Berkeley National Laboratory. For more - * information on Lawrence Berkeley National Laboratory, please see - * . - */ +#include "copyright.h" +#include +#include +#include + +#include "platform.h" +#include "rtprocess.h" /* getpid() */ #include "standard.h" #include "random.h" +#include "ray.h" #ifdef F_SETLKW #include "paths.h" #include "selcall.h" -#include -#include #ifndef TIMELIM #define TIMELIM (8*3600) /* time limit for holding pattern */ #endif -#ifndef freebsd -#define mkfifo(fn,md) mknod(fn, S_IFIFO|(md), 0) -#endif - -extern void io_process(); - extern int headismine; /* boolean true if header belongs to me */ - extern char *progname; /* global program name */ - extern char *errfile; /* global error file name */ - 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; -void -pfdetach() /* release persist (and header) resources */ + +extern void +pfdetach(void) /* release persist (and header) resources */ { if (persistfd >= 0) close(persistfd); @@ -109,8 +53,8 @@ pfdetach() /* release persist (and header) resources } -void -pfclean() /* clean up persist files */ +extern void +pfclean(void) /* clean up persist files */ { if (persistfd >= 0) close(persistfd); @@ -125,9 +69,10 @@ pfclean() /* clean up persist files */ } -void -pflock(lf) /* place or release exclusive lock on file */ -int lf; +extern void +pflock( /* place or release exclusive lock on file */ + int lf +) { struct flock fls; @@ -140,8 +85,10 @@ int lf; } -persistfile(pfn) /* open persist file and lock it */ -char *pfn; +extern void +persistfile( /* open persist file and lock it */ + char *pfn +) { persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644); if (persistfd >= 0) { @@ -162,15 +109,15 @@ char *pfn; static int got_io; -static void sig_io() { got_io++; } +static void sig_io(int i) { got_io++; } -static void sig_alrm() { quit(0); } +static void sig_alrm(int i) { quit(0); } -void -pfhold() /* holding pattern for idle rendering process */ +extern void +pfhold(void) /* holding pattern for idle rendering process */ { - void (*oldalrm)(); + sighandler_t *oldalrm; char buf[512]; register int n; /* close input and output descriptors */ @@ -191,11 +138,11 @@ pfhold() /* holding pattern for idle rendering proces n = strlen(buf); if (write(persistfd, buf, n) < n) error(SYSTEM, "error writing persist file"); - lseek(persistfd, (off_t)0L, 0); + lseek(persistfd, (off_t)0, SEEK_SET); /* wait TIMELIM for someone to signal us */ got_io = 0; signal(SIGIO, sig_io); - oldalrm = (void (*)())signal(SIGALRM, sig_alrm); + oldalrm = signal(SIGALRM, sig_alrm); alarm(TIMELIM); pflock(0); /* unlock persist file for attach */ while (!got_io) @@ -238,8 +185,8 @@ openerr: } -void -io_process() /* just act as go-between for actual process */ +extern void +io_process(void) /* just act as go-between for actual process */ { register char *cp; register int nr, n; @@ -259,26 +206,28 @@ io_process() /* just act as go-between for actual pro } if (nr < 0) error(SYSTEM, "error reading persist file"); +#ifndef _WIN32 /* XXX we need a replacement for that one */ ftruncate(persistfd, (off_t)0L); /* truncate persist file */ +#endif pfdetach(); /* close & release persist file */ buf[nr] = '\0'; /* parse what we got */ - if ((cp = index(buf, ' ')) == NULL) + if ((cp = strchr(buf, ' ')) == NULL) goto formerr; *cp++ = '\0'; if ((pid = atoi(cp)) <= 0) goto formerr; - if ((cp = index(cp, '\n')) == NULL) + if ((cp = strchr(cp, '\n')) == NULL) goto formerr; pfin = ++cp; - if ((cp = index(cp, '\n')) == NULL) + if ((cp = strchr(cp, '\n')) == NULL) goto formerr; *cp++ = '\0'; pfout = cp; - if ((cp = index(cp, '\n')) == NULL) + if ((cp = strchr(cp, '\n')) == NULL) goto formerr; *cp++ = '\0'; pferr = cp; - if ((cp = index(cp, '\n')) == NULL) + if ((cp = strchr(cp, '\n')) == NULL) goto formerr; *cp++ = '\0'; if (cp-buf != nr) @@ -386,7 +335,8 @@ io_process() /* just act as go-between for actual pro } while ((nr -= n) > 0); } } - wait(0); /* wait for feeder process */ + 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"); @@ -398,6 +348,6 @@ writerr: #else -void pfclean() {} +extern void pfclean(void) {} #endif