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.2 by greg, Wed Feb 7 16:42:45 1996 UTC vs.
Revision 2.16 by greg, Mon Sep 20 16:26:58 2004 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 <sys/types.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 "vfork.h"
17 <                                        /* Remote shell location */
18 < #ifdef sgi
19 < #define RSH             "/usr/bsd/rsh"
20 < #endif
21 < #ifdef _AUX_SOURCE
22 < #define RSH             "/usr/bin/remsh"
23 < #endif
24 < #ifndef RSH
25 < #define RSH             "/usr/ucb/rsh"
26 < #endif
27 <                                        /* select call compatibility stuff */
28 < #ifndef FD_SETSIZE
29 < #include <sys/param.h>
30 < #define FD_SETSIZE      NOFILE          /* maximum # select file descriptors */
31 < #endif
32 < #ifndef FD_SET
33 < #ifndef NFDBITS
34 < #define NFDBITS         (8*sizeof(int)) /* number of bits per fd_mask */
35 < #endif
36 < #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
37 < #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
38 < #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
39 < #ifndef BSD
40 < #define bzero(d,n)      (void)memset(d,0,n)
41 < #endif
42 < #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
43 < #endif
19 > #include "paths.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[128];    /* 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  
30   static fd_set   errdesc;        /* error file descriptors */
31   static int      maxfd;          /* maximum assigned descriptor */
32  
33 < extern char     *malloc(), *realloc();
58 < extern char     *getenv();
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 */
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[128];
56 >                char    dirtmp[PATH_MAX];
57                  register char   *cp;
58                  register int    len;
59  
# Line 130 | 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 150 | 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 171 | 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    *av[12];
166 >        char    udirt[PATH_MAX];
167 >        char    *av[16];
168          int     pfd[2], pid;
169          register int    i;
170  
# Line 198 | 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);
192                          close(pfd[1]);
193                  }
194                  if (ps->hostname[0]) {          /* rsh command */
195 <                        av[i=0] = RSH;
195 >                        av[i=0] = remsh;
196                          av[++i] = ps->hostname;
197 <                        av[++i] = "-n";         /* no stdin */
198 <                        if (ps->username[0]) {
197 >                        av[++i] = "-n";                 /* no stdin */
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] = ";";
206                          }
207 <                        if (ps->directory[0]) {
207 >                        if (ps->directory[0]) {         /* change directory */
208                                  av[++i] = "cd";
209                                  av[++i] = ps->directory;
210                                  av[++i] = ";";
# Line 237 | 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 247 | 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 267 | Line 260 | int    fd;
260          if (pp->elen == 0)
261                  pp->errs = (char *)malloc(nr+1);
262          else
263 <                pp->errs = (char *)realloc(pp->errs, pp->elen+nr+1);
263 >                pp->errs = (char *)realloc((void *)pp->errs, pp->elen+nr+1);
264          if (pp->errs == NULL) {
265                  perror("malloc failed");
266                  exit(1);
# Line 278 | 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 301 | 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 314 | Line 308 | int    status;
308          close(pp->efd);                         /* close error stream */
309          pindex[pp->efd] = NULL;
310          FD_CLR(pp->efd, &errdesc);
311 <        free((char *)pp->errs);
311 >        free((void *)pp->errs);
312          pp->com = NULL;                         /* clear settings */
313          pp->pid = -1;
314          pp->efd = -1;
# Line 325 | 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