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.13 by greg, Mon Nov 10 16:52:24 2003 UTC vs.
Revision 2.17 by greg, Mon Mar 15 21:31:50 2010 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
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"
# Line 30 | Line 32 | static int     maxfd;          /* maximum assigned descriptor */
32  
33   extern char     *remsh;         /* externally defined remote shell program */
34  
35 + static int readerrs(int fd);
36 + static void wait4end(void);
37 + static int finishjob(PSERVER    *ps, int        pn, int status);
38  
39 < PSERVER *
40 < addpserver(host, dir, usr, np)          /* add a new process server */
41 < char    *host, *dir, *usr;
42 < int     np;
39 >
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 */
# Line 103 | 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 127 | 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 144 | 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 172 | 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 185 | Line 198 | int    (*compf)();
198                          if (ps->username[0]) {          /* different user */
199                                  av[++i] = "-l";
200                                  av[++i] = ps->username;
201 <                                av[++i] = "cd";
202 <                                udirt[0] = '~';
203 <                                strcpy(udirt+1, ouruser);
204 <                                av[++i] = udirt;
205 <                                av[++i] = ";";
201 >                                if (ps->directory[0] != '/') {
202 >                                        av[++i] = "cd";
203 >                                        udirt[0] = '~';
204 >                                        strcpy(udirt+1, ouruser);
205 >                                        av[++i] = udirt;
206 >                                        av[++i] = ";";
207 >                                }
208                          }
209                          if (ps->directory[0]) {         /* change directory */
210                                  av[++i] = "cd";
# Line 216 | Line 231 | int    (*compf)();
231          ps->proc[i].pid = pid;
232          close(pfd[1]);                  /* get piped stderr file descriptor */
233          ps->proc[i].efd = pfd[0];
234 <        fcntl(pfd[0], F_SETFD, 1);      /* set close on exec flag */
234 >        fcntl(pfd[0], F_SETFD, FD_CLOEXEC);     /* set close on exec flag */
235          pindex[pfd[0]] = ps->proc + i;  /* assign error fd index */
236          FD_SET(pfd[0], &errdesc);       /* add to select call parameter */
237          if (pfd[0] > maxfd)
# Line 226 | Line 241 | int    (*compf)();
241  
242  
243   static int
244 < readerrs(fd)                    /* read error output from fd */
245 < int     fd;
244 > readerrs(                       /* read error output from fd */
245 >        int     fd
246 > )
247   {
248          char    errbuf[BUFSIZ];
249          int     nr;
# Line 257 | Line 273 | int    fd;
273   }
274  
275  
276 < static
277 < wait4end()                      /* read error streams until someone is done */
276 > static void
277 > wait4end(void)                  /* read error streams until someone is done */
278   {
279          fd_set  readfds, excepfds;
280          register int    i;
# Line 280 | Line 296 | wait4end()                     /* read error streams until someone is do
296  
297  
298   static int
299 < finishjob(ps, pn, status)       /* clean up finished process */
300 < PSERVER *ps;
301 < int     pn;
302 < int     status;
299 > finishjob(      /* clean up finished process */
300 >        PSERVER *ps,
301 >        int     pn,
302 >        int     status
303 > )
304   {
305          register NETPROC        *pp;
306  
# Line 304 | Line 321 | int    status;
321   }
322  
323  
324 < int
325 < wait4job(ps, pid)               /* wait for process to finish */
326 < PSERVER *ps;
327 < int     pid;
324 > extern int
325 > wait4job(               /* wait for process to finish */
326 >        PSERVER *ps,
327 >        int     pid
328 > )
329   {
330          int     status, psn, psn2;
331          PSERVER *ps2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines