--- ray/src/util/netproc.c 2003/02/22 02:07:30 2.9 +++ ray/src/util/netproc.c 2004/03/26 21:36:19 2.15 @@ -1,24 +1,29 @@ #ifndef lint -static const char RCSid[] = "$Id: netproc.c,v 2.9 2003/02/22 02:07:30 greg Exp $"; +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 "rtmisc.h" #include "selcall.h" #include "netproc.h" #include "paths.h" -#include "vfork.h" 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 */ @@ -27,28 +32,33 @@ static int maxfd; /* maximum assigned descriptor */ extern char *remsh; /* externally defined remote shell program */ -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'; @@ -102,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; @@ -126,9 +138,10 @@ PSERVER *ps; } -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; @@ -143,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; @@ -171,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); @@ -225,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 */ @@ -245,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); @@ -256,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; @@ -279,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 */ @@ -303,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;