--- ray/src/util/netproc.c 1996/06/24 10:06:40 2.5 +++ ray/src/util/netproc.c 2004/03/26 21:36:19 2.15 @@ -1,44 +1,29 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: netproc.c,v 2.15 2004/03/26 21:36:19 schorsch Exp $"; #endif - /* * Parallel network process handling routines */ +#include #include -#include +#include #include #include +#include +#include + +#include "rtmisc.h" +#include "selcall.h" #include "netproc.h" #include "paths.h" -#include "vfork.h" - /* select call compatibility stuff */ -#ifndef FD_SETSIZE -#include -#define FD_SETSIZE NOFILE /* maximum # select file descriptors */ -#endif -#ifndef FD_SET -#ifndef NFDBITS -#define NFDBITS (8*sizeof(int)) /* number of bits per fd_mask */ -#endif -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) -#ifndef BSD -#define bzero(d,n) (void)memset(d,0,n) -#endif -#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) -#endif PSERVER *pslist = NULL; /* global process server list */ -static PROC *pindex[FD_SETSIZE]; /* process index table */ +static NETPROC *pindex[FD_SETSIZE]; /* process index table */ static char ourhost[64]; /* this host name */ -static char ourdir[MAXPATH]; /* our working directory */ +static char ourdir[PATH_MAX]; /* our working directory */ static char ouruser[32]; /* our user name */ static char *ourshell; /* our user's shell */ @@ -47,29 +32,33 @@ static int maxfd; /* maximum assigned descriptor */ extern char *remsh; /* externally defined remote shell program */ -extern char *malloc(), *realloc(); -extern char *getenv(); +static int readerrs(int fd); +static void wait4end(void); +static int finishjob(PSERVER *ps, int pn, int status); -PSERVER * -addpserver(host, dir, usr, np) /* add a new process server */ -char *host, *dir, *usr; -int np; +extern PSERVER * +addpserver( /* add a new process server */ + char *host, + char *dir, + char *usr, + int np +) { register PSERVER *ps; /* allocate the struct */ if (np < 1) return(NULL); - ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(PROC)); + ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(NETPROC)); if (ps == NULL) return(NULL); if (!ourhost[0]) { /* initialize */ - char dirtmp[MAXPATH]; + char dirtmp[PATH_MAX]; register char *cp; register int len; strcpy(ourhost, myhostname()); - getwd(dirtmp); + getcwd(dirtmp, sizeof(dirtmp)); if ((cp = getenv("HOME")) != NULL) { if (!strcmp(cp, dirtmp)) ourdir[0] = '\0'; @@ -123,8 +112,10 @@ int np; } -delpserver(ps) /* delete a process server */ -PSERVER *ps; +extern void +delpserver( /* delete a process server */ + PSERVER *ps +) { PSERVER pstart; register PSERVER *psp; @@ -143,13 +134,14 @@ PSERVER *ps; /* remove server from list */ psp->next = ps->next; pslist = pstart.next; - free((char *)ps); /* free associated memory */ + free((void *)ps); /* free associated memory */ } -PSERVER * -findjob(pnp) /* find out where process is running */ -register int *pnp; /* modified */ +extern PSERVER * +findjob( /* find out where process is running */ + register int *pnp /* modified */ +) { register PSERVER *ps; register int i; @@ -164,13 +156,14 @@ register int *pnp; /* modified */ } -int -startjob(ps, command, compf) /* start a job on a process server */ -register PSERVER *ps; -char *command; -int (*compf)(); +extern int +startjob( /* start a job on a process server */ + register PSERVER *ps, + char *command, + pscompfunc *compf +) { - char udirt[MAXPATH]; + char udirt[PATH_MAX]; char *av[16]; int pfd[2], pid; register int i; @@ -192,7 +185,7 @@ int (*compf)(); exit(1); } /* start child process */ - if ((pid = vfork()) == 0) { + if ((pid = fork()) == 0) { close(pfd[0]); /* connect stderr to pipe */ if (pfd[1] != 2) { dup2(pfd[1], 2); @@ -246,12 +239,13 @@ int (*compf)(); static int -readerrs(fd) /* read error output from fd */ -int fd; +readerrs( /* read error output from fd */ + int fd +) { char errbuf[BUFSIZ]; int nr; - register PROC *pp; + register NETPROC *pp; /* look up associated process */ if ((pp = pindex[fd]) == NULL) abort(); /* serious consistency error */ @@ -266,7 +260,7 @@ int fd; if (pp->elen == 0) pp->errs = (char *)malloc(nr+1); else - pp->errs = (char *)realloc(pp->errs, pp->elen+nr+1); + pp->errs = (char *)realloc((void *)pp->errs, pp->elen+nr+1); if (pp->errs == NULL) { perror("malloc failed"); exit(1); @@ -277,8 +271,8 @@ int fd; } -static -wait4end() /* read error streams until someone is done */ +static void +wait4end(void) /* read error streams until someone is done */ { fd_set readfds, excepfds; register int i; @@ -300,12 +294,13 @@ wait4end() /* read error streams until someone is do static int -finishjob(ps, pn, status) /* clean up finished process */ -PSERVER *ps; -int pn; -int status; +finishjob( /* clean up finished process */ + PSERVER *ps, + int pn, + int status +) { - register PROC *pp; + register NETPROC *pp; pp = ps->proc + pn; if (pp->cf != NULL) /* client cleanup */ @@ -313,7 +308,7 @@ int status; close(pp->efd); /* close error stream */ pindex[pp->efd] = NULL; FD_CLR(pp->efd, &errdesc); - free((char *)pp->errs); + free((void *)pp->errs); pp->com = NULL; /* clear settings */ pp->pid = -1; pp->efd = -1; @@ -324,10 +319,11 @@ int status; } -int -wait4job(ps, pid) /* wait for process to finish */ -PSERVER *ps; -int pid; +extern int +wait4job( /* wait for process to finish */ + PSERVER *ps, + int pid +) { int status, psn, psn2; PSERVER *ps2;