--- ray/src/util/netproc.c 2003/11/10 16:52:24 2.13 +++ ray/src/util/netproc.c 2010/03/15 21:31:50 2.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: netproc.c,v 2.13 2003/11/10 16:52:24 greg Exp $"; +static const char RCSid[] = "$Id: netproc.c,v 2.17 2010/03/15 21:31:50 greg Exp $"; #endif /* * Parallel network process handling routines @@ -11,7 +11,9 @@ static const char RCSid[] = "$Id: netproc.c,v 2.13 200 #include #include #include +#include +#include "rtmisc.h" #include "selcall.h" #include "netproc.h" #include "paths.h" @@ -30,11 +32,18 @@ static int maxfd; /* maximum assigned descriptor */ extern char *remsh; /* externally defined remote shell program */ +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 */ @@ -103,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; @@ -127,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; @@ -144,11 +156,12 @@ 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[PATH_MAX]; char *av[16]; @@ -172,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); @@ -185,11 +198,13 @@ int (*compf)(); if (ps->username[0]) { /* different user */ av[++i] = "-l"; av[++i] = ps->username; - av[++i] = "cd"; - udirt[0] = '~'; - strcpy(udirt+1, ouruser); - av[++i] = udirt; - av[++i] = ";"; + if (ps->directory[0] != '/') { + av[++i] = "cd"; + udirt[0] = '~'; + strcpy(udirt+1, ouruser); + av[++i] = udirt; + av[++i] = ";"; + } } if (ps->directory[0]) { /* change directory */ av[++i] = "cd"; @@ -216,7 +231,7 @@ int (*compf)(); ps->proc[i].pid = pid; close(pfd[1]); /* get piped stderr file descriptor */ ps->proc[i].efd = pfd[0]; - fcntl(pfd[0], F_SETFD, 1); /* set close on exec flag */ + fcntl(pfd[0], F_SETFD, FD_CLOEXEC); /* set close on exec flag */ pindex[pfd[0]] = ps->proc + i; /* assign error fd index */ FD_SET(pfd[0], &errdesc); /* add to select call parameter */ if (pfd[0] > maxfd) @@ -226,8 +241,9 @@ 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; @@ -257,8 +273,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; @@ -280,10 +296,11 @@ 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 NETPROC *pp; @@ -304,10 +321,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;