--- ray/src/util/netproc.c 1996/02/07 16:42:45 2.2 +++ ray/src/util/netproc.c 2003/10/27 10:32:06 2.12 @@ -1,61 +1,35 @@ -/* 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.12 2003/10/27 10:32:06 schorsch Exp $"; #endif - /* * Parallel network process handling routines */ +#include #include -#include +#include #include #include +#include + +#include "selcall.h" #include "netproc.h" +#include "paths.h" #include "vfork.h" - /* Remote shell location */ -#ifdef sgi -#define RSH "/usr/bsd/rsh" -#endif -#ifdef _AUX_SOURCE -#define RSH "/usr/bin/remsh" -#endif -#ifndef RSH -#define RSH "/usr/ucb/rsh" -#endif - /* 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[128]; /* 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 */ static fd_set errdesc; /* error file descriptors */ static int maxfd; /* maximum assigned descriptor */ -extern char *malloc(), *realloc(); -extern char *getenv(); +extern char *remsh; /* externally defined remote shell program */ PSERVER * @@ -67,11 +41,11 @@ int np; /* 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[128]; + char dirtmp[PATH_MAX]; register char *cp; register int len; @@ -150,7 +124,7 @@ 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 */ } @@ -177,7 +151,8 @@ register PSERVER *ps; char *command; int (*compf)(); { - char *av[12]; + char udirt[PATH_MAX]; + char *av[16]; int pfd[2], pid; register int i; @@ -205,14 +180,19 @@ int (*compf)(); close(pfd[1]); } if (ps->hostname[0]) { /* rsh command */ - av[i=0] = RSH; + av[i=0] = remsh; av[++i] = ps->hostname; - av[++i] = "-n"; /* no stdin */ - if (ps->username[0]) { + av[++i] = "-n"; /* no stdin */ + 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]) { + if (ps->directory[0]) { /* change directory */ av[++i] = "cd"; av[++i] = ps->directory; av[++i] = ";"; @@ -252,7 +232,7 @@ 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 */ @@ -267,7 +247,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); @@ -306,7 +286,7 @@ PSERVER *ps; int pn; int status; { - register PROC *pp; + register NETPROC *pp; pp = ps->proc + pn; if (pp->cf != NULL) /* client cleanup */ @@ -314,7 +294,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;