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.4 by greg, Fri Apr 16 10:26:45 1993 UTC vs.
Revision 2.8 by greg, Fri Sep 17 21:43:49 2004 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 < #ifndef BSD
17 < #include  <errno.h>
30 < #endif
16 > The functions open_process() and close_process() exist in
17 > (currently) two versions, which are found in the files:
18  
19 +        win_process.c
20 +        unix_process.c
21  
22 < int
34 < open_process(pd, av)            /* open communication to separate process */
35 < int     pd[3];
36 < char    *av[];
37 < {
38 <        extern char     *getpath(), *getenv();
39 <        char    *compath;
40 <        int     p0[2], p1[2];
41 <                                        /* find executable */
42 <        compath = getpath(av[0], getenv("PATH"), 1);
43 <        if (compath == 0)
44 <                return(0);
45 <        if (pipe(p0) < 0 || pipe(p1) < 0)
46 <                return(-1);
47 <        if ((pd[2] = vfork()) == 0) {           /* if child */
48 <                close(p0[1]);
49 <                close(p1[0]);
50 <                if (p0[0] != 0) {       /* connect p0 to stdin */
51 <                        dup2(p0[0], 0);
52 <                        close(p0[0]);
53 <                }
54 <                if (p1[1] != 1) {       /* connect p1 to stdout */
55 <                        dup2(p1[1], 1);
56 <                        close(p1[1]);
57 <                }
58 <                execv(compath, av);     /* exec command */
59 <                perror(compath);
60 <                _exit(127);
61 <        }
62 <        if (pd[2] == -1)
63 <                return(-1);
64 <        close(p0[0]);
65 <        close(p1[1]);
66 <        pd[0] = p1[0];
67 <        pd[1] = p0[1];
68 <        return(PIPE_BUF);
69 < }
22 > */
23  
71
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 (!pd->running)
34                  return(-1);
35 <        return(readbuf(pd[0], recvbuf, nbr));
35 >        if (writebuf(pd->w, sendbuf, nbs) < nbs)
36 >                return(-1);
37 >        return(readbuf(pd->r, recvbuf, nbr));
38   }
39  
40  
86 int
87 close_process(pd)               /* close pipes and wait for process */
88 int     pd[3];
89 {
90        int     pid, status;
41  
92        close(pd[1]);
93        close(pd[0]);
94        while ((pid = wait(&status)) != -1)
95                if (pid == pd[2])
96                        return(status>>8 & 0xff);
97        return(-1);             /* ? unknown status */
98 }
99
100
42   int
43 < readbuf(fd, bpos, siz)          /* read all of requested buffer */
44 < int     fd;
45 < char    *bpos;
46 < int     siz;
43 > readbuf(                /* read all of requested buffer */
44 > int     fd,
45 > char    *bpos,
46 > int     siz
47 > )
48   {
49          register int    cc = 0, nrem = siz;
50   retry:
# Line 122 | Line 64 | retry:
64  
65  
66   int
67 < writebuf(fd, bpos, siz)         /* write all of requested buffer */
68 < int     fd;
69 < char    *bpos;
70 < int     siz;
67 > writebuf(               /* write all of requested buffer */
68 > int     fd,
69 > char    *bpos,
70 > int     siz
71 > )
72   {
73          register int    cc = 0, nrem = siz;
74   retry:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines