ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/process.c
(Generate patch)

Comparing ray/src/common/process.c (file contents):
Revision 2.3 by greg, Thu Apr 1 11:08:05 1993 UTC vs.
Revision 2.7 by schorsch, Thu Jun 26 00:58:09 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines to communicate with separate process via dual pipes
6 + *
7 + * External symbols declared in standard.h
8   */
9  
10 <                                /* find pipe buffer limit */
12 < #include  <sys/param.h>
10 > #include "copyright.h"
11  
12 < #ifndef PIPE_BUF
15 < #ifdef PIPSIZ
16 < #define PIPE_BUF        PIPSIZ
17 < #else
18 < #ifdef PIPE_MAX
19 < #define PIPE_BUF        PIPE_MAX
20 < #else
21 < #define PIPE_BUF        512             /* hyperconservative */
22 < #endif
23 < #endif
24 < #endif
12 > #include "rtprocess.h"
13  
14 < #include  "vfork.h"
14 > /*
15  
16 + The functions open_process() and close_process() exist in
17 + (currently) two versions, which are found in the files:
18  
19 < int
20 < open_process(pd, av)            /* open communication to separate process */
31 < int     pd[3];
32 < char    *av[];
33 < {
34 <        extern char     *getpath(), *getenv();
35 <        char    *compath;
36 <        int     p0[2], p1[2];
37 <                                        /* find executable */
38 <        compath = getpath(av[0], getenv("PATH"), 1);
39 <        if (compath == 0)
40 <                return(0);
41 <        if (pipe(p0) < 0 || pipe(p1) < 0)
42 <                return(-1);
43 <        if ((pd[2] = vfork()) == 0) {           /* if child */
44 <                close(p0[1]);
45 <                close(p1[0]);
46 <                if (p0[0] != 0) {       /* connect p0 to stdin */
47 <                        dup2(p0[0], 0);
48 <                        close(p0[0]);
49 <                }
50 <                if (p1[1] != 1) {       /* connect p1 to stdout */
51 <                        dup2(p1[1], 1);
52 <                        close(p1[1]);
53 <                }
54 <                execv(compath, av);     /* exec command */
55 <                perror(compath);
56 <                _exit(127);
57 <        }
58 <        if (pd[2] == -1)
59 <                return(-1);
60 <        close(p0[0]);
61 <        close(p1[1]);
62 <        pd[0] = p1[0];
63 <        pd[1] = p0[1];
64 <        return(PIPE_BUF);
65 < }
19 >        win_process.c
20 >        unix_process.c
21  
22 + */
23  
24   int
25 < process(pd, recvbuf, sendbuf, nbr, nbs)         /* process data through pd */
26 < int     pd[3];
27 < char    *recvbuf, *sendbuf;
28 < int     nbr, nbs;
25 > process(                /* process data through pd */
26 > SUBPROC *pd,
27 > char    *recvbuf, char *sendbuf,
28 > int     nbr, int nbs
29 > )
30   {
31          if (nbs > PIPE_BUF)
32                  return(-1);
33 <        if (writebuf(pd[1], sendbuf, nbs) < nbs)
33 >        if (writebuf(pd->w, sendbuf, nbs) < nbs)
34                  return(-1);
35 <        return(readbuf(pd[0], recvbuf, nbr));
35 >        return(readbuf(pd->r, recvbuf, nbr));
36   }
37  
38  
82 int
83 close_process(pd)               /* close pipes and wait for process */
84 int     pd[3];
85 {
86        int     pid, status;
39  
88        close(pd[1]);
89        close(pd[0]);
90        while ((pid = wait(&status)) != -1)
91                if (pid == pd[2])
92                        return(status>>8 & 0xff);
93        return(-1);             /* ? unknown status */
94 }
95
96
40   int
41 < readbuf(fd, bpos, siz)          /* read all of requested buffer */
42 < int     fd;
43 < char    *bpos;
44 < int     siz;
41 > readbuf(                /* read all of requested buffer */
42 > int     fd,
43 > char    *bpos,
44 > int     siz
45 > )
46   {
47          register int    cc = 0, nrem = siz;
48 <
48 > retry:
49          while (nrem > 0 && (cc = read(fd, bpos, nrem)) > 0) {
50                  bpos += cc;
51                  nrem -= cc;
52          }
53 <        if (cc < 0)
53 >        if (cc < 0) {
54 > #ifndef BSD
55 >                if (errno == EINTR)     /* we were interrupted! */
56 >                        goto retry;
57 > #endif
58                  return(cc);
59 +        }
60          return(siz-nrem);
61   }
62  
63  
64   int
65 < writebuf(fd, bpos, siz)         /* write all of requested buffer */
66 < int     fd;
67 < char    *bpos;
68 < int     siz;
65 > writebuf(               /* write all of requested buffer */
66 > int     fd,
67 > char    *bpos,
68 > int     siz
69 > )
70   {
71          register int    cc = 0, nrem = siz;
72 <
72 > retry:
73          while (nrem > 0 && (cc = write(fd, bpos, nrem)) > 0) {
74                  bpos += cc;
75                  nrem -= cc;
76          }
77 <        if (cc < 0)
77 >        if (cc < 0) {
78 > #ifndef BSD
79 >                if (errno == EINTR)     /* we were interrupted! */
80 >                        goto retry;
81 > #endif
82                  return(cc);
83 +        }
84          return(siz-nrem);
85   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines