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

Comparing ray/src/util/netproc.c (file contents):
Revision 2.11 by schorsch, Mon Jun 30 14:59:13 2003 UTC vs.
Revision 2.16 by greg, Mon Sep 20 16:26:58 2004 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Parallel network process handling routines
6   */
7  
8 + #include <stdlib.h>
9   #include <stdio.h>
10 + #include <string.h>
11   #include <signal.h>
12   #include <fcntl.h>
13   #include <unistd.h>
14 + #include <sys/wait.h>
15  
16 + #include "rtmisc.h"
17   #include "selcall.h"
18   #include "netproc.h"
19   #include "paths.h"
16 #include "vfork.h"
20  
21   PSERVER *pslist = NULL;         /* global process server list */
22  
23 < static PROC     *pindex[FD_SETSIZE];    /* process index table */
23 > static NETPROC  *pindex[FD_SETSIZE];    /* process index table */
24  
25   static char     ourhost[64];    /* this host name */
26   static char     ourdir[PATH_MAX];       /* our working directory */
# Line 29 | Line 32 | static int     maxfd;          /* maximum assigned descriptor */
32  
33   extern char     *remsh;         /* externally defined remote shell program */
34  
35 < extern char     *getenv();
35 > static int readerrs(int fd);
36 > static void wait4end(void);
37 > static int finishjob(PSERVER    *ps, int        pn, int status);
38  
39  
40 < PSERVER *
41 < addpserver(host, dir, usr, np)          /* add a new process server */
42 < char    *host, *dir, *usr;
43 < int     np;
40 > extern PSERVER *
41 > addpserver(             /* add a new process server */
42 >        char    *host,
43 >        char    *dir,
44 >        char    *usr,
45 >        int     np
46 > )
47   {
48          register PSERVER        *ps;
49                                          /* allocate the struct */
50          if (np < 1)
51                  return(NULL);
52 <        ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(PROC));
52 >        ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(NETPROC));
53          if (ps == NULL)
54                  return(NULL);
55          if (!ourhost[0]) {              /* initialize */
# Line 104 | Line 112 | int    np;
112   }
113  
114  
115 < delpserver(ps)                          /* delete a process server */
116 < PSERVER *ps;
115 > extern void
116 > delpserver(                             /* delete a process server */
117 >        PSERVER *ps
118 > )
119   {
120          PSERVER pstart;
121          register PSERVER        *psp;
# Line 128 | Line 138 | PSERVER        *ps;
138   }
139  
140  
141 < PSERVER *
142 < findjob(pnp)                    /* find out where process is running */
143 < register int    *pnp;   /* modified */
141 > extern PSERVER *
142 > findjob(                        /* find out where process is running */
143 >        register int    *pnp    /* modified */
144 > )
145   {
146          register PSERVER        *ps;
147          register int    i;
# Line 145 | Line 156 | register int   *pnp;   /* modified */
156   }
157  
158  
159 < int
160 < startjob(ps, command, compf)    /* start a job on a process server */
161 < register PSERVER        *ps;
162 < char    *command;
163 < int     (*compf)();
159 > extern int
160 > startjob(       /* start a job on a process server */
161 >        register PSERVER        *ps,
162 >        char    *command,
163 >        pscompfunc *compf
164 > )
165   {
166          char    udirt[PATH_MAX];
167          char    *av[16];
# Line 173 | Line 185 | int    (*compf)();
185                  exit(1);
186          }
187                                          /* start child process */
188 <        if ((pid = vfork()) == 0) {
188 >        if ((pid = fork()) == 0) {
189                  close(pfd[0]);                  /* connect stderr to pipe */
190                  if (pfd[1] != 2) {
191                          dup2(pfd[1], 2);
# Line 217 | Line 229 | int    (*compf)();
229          ps->proc[i].pid = pid;
230          close(pfd[1]);                  /* get piped stderr file descriptor */
231          ps->proc[i].efd = pfd[0];
232 <        fcntl(pfd[0], F_SETFD, 1);      /* set close on exec flag */
232 >        fcntl(pfd[0], F_SETFD, FD_CLOEXEC);     /* set close on exec flag */
233          pindex[pfd[0]] = ps->proc + i;  /* assign error fd index */
234          FD_SET(pfd[0], &errdesc);       /* add to select call parameter */
235          if (pfd[0] > maxfd)
# Line 227 | Line 239 | int    (*compf)();
239  
240  
241   static int
242 < readerrs(fd)                    /* read error output from fd */
243 < int     fd;
242 > readerrs(                       /* read error output from fd */
243 >        int     fd
244 > )
245   {
246          char    errbuf[BUFSIZ];
247          int     nr;
248 <        register PROC   *pp;
248 >        register NETPROC        *pp;
249                                  /* look up associated process */
250          if ((pp = pindex[fd]) == NULL)
251                  abort();                /* serious consistency error */
# Line 258 | Line 271 | int    fd;
271   }
272  
273  
274 < static
275 < wait4end()                      /* read error streams until someone is done */
274 > static void
275 > wait4end(void)                  /* read error streams until someone is done */
276   {
277          fd_set  readfds, excepfds;
278          register int    i;
# Line 281 | Line 294 | wait4end()                     /* read error streams until someone is do
294  
295  
296   static int
297 < finishjob(ps, pn, status)       /* clean up finished process */
298 < PSERVER *ps;
299 < int     pn;
300 < int     status;
297 > finishjob(      /* clean up finished process */
298 >        PSERVER *ps,
299 >        int     pn,
300 >        int     status
301 > )
302   {
303 <        register PROC   *pp;
303 >        register NETPROC        *pp;
304  
305          pp = ps->proc + pn;
306          if (pp->cf != NULL)                     /* client cleanup */
# Line 305 | Line 319 | int    status;
319   }
320  
321  
322 < int
323 < wait4job(ps, pid)               /* wait for process to finish */
324 < PSERVER *ps;
325 < int     pid;
322 > extern int
323 > wait4job(               /* wait for process to finish */
324 >        PSERVER *ps,
325 >        int     pid
326 > )
327   {
328          int     status, psn, psn2;
329          PSERVER *ps2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines