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.8 by gregl, Tue Oct 28 14:01:39 1997 UTC vs.
Revision 2.17 by greg, Mon Mar 15 21:31:50 2010 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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   * 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"
17 #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[MAXPATH];        /* our working directory */
26 > static char     ourdir[PATH_MAX];       /* our working directory */
27   static char     ouruser[32];    /* our user name */
28   static char     *ourshell;      /* our user's shell */
29  
# Line 30 | Line 32 | static int     maxfd;          /* maximum assigned descriptor */
32  
33   extern char     *remsh;         /* externally defined remote shell program */
34  
35 < extern char     *malloc(), *realloc();
36 < 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 */
56 <                char    dirtmp[MAXPATH];
56 >                char    dirtmp[PATH_MAX];
57                  register char   *cp;
58                  register int    len;
59  
60                  strcpy(ourhost, myhostname());
61 <                getwd(dirtmp);
61 >                getcwd(dirtmp, sizeof(dirtmp));
62                  if ((cp = getenv("HOME")) != NULL) {
63                          if (!strcmp(cp, dirtmp))
64                                  ourdir[0] = '\0';
# Line 106 | 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 126 | Line 134 | PSERVER        *ps;
134                                          /* remove server from list */
135          psp->next = ps->next;
136          pslist = pstart.next;
137 <        free((char *)ps);               /* free associated memory */
137 >        free((void *)ps);               /* free associated memory */
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 147 | 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[MAXPATH];
166 >        char    udirt[PATH_MAX];
167          char    *av[16];
168          int     pfd[2], pid;
169          register int    i;
# Line 175 | 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 188 | 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 219 | 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 229 | 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;
250 <        register PROC   *pp;
250 >        register NETPROC        *pp;
251                                  /* look up associated process */
252          if ((pp = pindex[fd]) == NULL)
253                  abort();                /* serious consistency error */
# Line 249 | Line 262 | int    fd;
262          if (pp->elen == 0)
263                  pp->errs = (char *)malloc(nr+1);
264          else
265 <                pp->errs = (char *)realloc(pp->errs, pp->elen+nr+1);
265 >                pp->errs = (char *)realloc((void *)pp->errs, pp->elen+nr+1);
266          if (pp->errs == NULL) {
267                  perror("malloc failed");
268                  exit(1);
# Line 260 | 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 283 | 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 PROC   *pp;
305 >        register NETPROC        *pp;
306  
307          pp = ps->proc + pn;
308          if (pp->cf != NULL)                     /* client cleanup */
# Line 296 | Line 310 | int    status;
310          close(pp->efd);                         /* close error stream */
311          pindex[pp->efd] = NULL;
312          FD_CLR(pp->efd, &errdesc);
313 <        free((char *)pp->errs);
313 >        free((void *)pp->errs);
314          pp->com = NULL;                         /* clear settings */
315          pp->pid = -1;
316          pp->efd = -1;
# Line 307 | 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