--- ray/src/common/process.c 1991/11/12 16:56:02 2.1 +++ ray/src/common/process.c 2003/06/26 00:58:09 2.7 @@ -1,132 +1,85 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: process.c,v 2.7 2003/06/26 00:58:09 schorsch Exp $"; #endif - /* * Routines to communicate with separate process via dual pipes + * + * External symbols declared in standard.h */ - /* find pipe buffer limit */ -#include +#include "copyright.h" -#ifndef PIPE_BUF -#ifdef PIPSIZ -#define PIPE_BUF PIPSIZ -#else -#ifdef PIPE_MAX -#define PIPE_BUF PIPE_MAX -#else -#define PIPE_BUF 512 /* hyperconservative */ -#endif -#endif -#endif +#include "rtprocess.h" -#ifndef BSD -#define vfork fork -#endif +/* +The functions open_process() and close_process() exist in +(currently) two versions, which are found in the files: -int -open_process(pd, av) /* open communication to separate process */ -int pd[3]; -char *av[]; -{ - extern char *getpath(), *getenv(); - char *compath; - int p0[2], p1[2]; - /* find executable */ - compath = getpath(av[0], getenv("PATH"), 1); - if (compath == 0) - return(0); - if (pipe(p0) < 0 || pipe(p1) < 0) - return(-1); - if ((pd[2] = vfork()) == 0) { /* if child */ - close(p0[1]); - close(p1[0]); - if (p0[0] != 0) { /* connect p0 to stdin */ - dup2(p0[0], 0); - close(p0[0]); - } - if (p1[1] != 1) { /* connect p1 to stdout */ - dup2(p1[1], 1); - close(p1[1]); - } - execv(compath, av); /* exec command */ - perror(compath); - _exit(127); - } - if (pd[2] == -1) - return(-1); - close(p0[0]); - close(p1[1]); - pd[0] = p1[0]; - pd[1] = p0[1]; - return(PIPE_BUF); -} + win_process.c + unix_process.c +*/ int -process(pd, recvbuf, sendbuf, nbr, nbs) /* process data through pd */ -int pd[3]; -char *recvbuf, *sendbuf; -int nbr, nbs; +process( /* process data through pd */ +SUBPROC *pd, +char *recvbuf, char *sendbuf, +int nbr, int nbs +) { if (nbs > PIPE_BUF) return(-1); - if (writebuf(pd[1], sendbuf, nbs) < nbs) + if (writebuf(pd->w, sendbuf, nbs) < nbs) return(-1); - return(readbuf(pd[0], recvbuf, nbr)); + return(readbuf(pd->r, recvbuf, nbr)); } -int -close_process(pd) /* close pipes and wait for process */ -int pd[3]; -{ - int pid, status; - close(pd[1]); - close(pd[0]); - while ((pid = wait(&status)) != -1) - if (pid == pd[2]) - return(status>>8 & 0xff); - return(-1); /* ? unknown status */ -} - - int -readbuf(fd, bpos, siz) /* read all of requested buffer */ -int fd; -char *bpos; -int siz; +readbuf( /* read all of requested buffer */ +int fd, +char *bpos, +int siz +) { - register int cc, nrem = siz; - + register int cc = 0, nrem = siz; +retry: while (nrem > 0 && (cc = read(fd, bpos, nrem)) > 0) { bpos += cc; nrem -= cc; } - if (cc < 0) + if (cc < 0) { +#ifndef BSD + if (errno == EINTR) /* we were interrupted! */ + goto retry; +#endif return(cc); + } return(siz-nrem); } int -writebuf(fd, bpos, siz) /* write all of requested buffer */ -int fd; -char *bpos; -int siz; +writebuf( /* write all of requested buffer */ +int fd, +char *bpos, +int siz +) { - register int cc, nrem = siz; - + register int cc = 0, nrem = siz; +retry: while (nrem > 0 && (cc = write(fd, bpos, nrem)) > 0) { bpos += cc; nrem -= cc; } - if (cc < 0) + if (cc < 0) { +#ifndef BSD + if (errno == EINTR) /* we were interrupted! */ + goto retry; +#endif return(cc); + } return(siz-nrem); }