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 |
+ |
|
15 |
+ |
#include "selcall.h" |
16 |
|
#include "netproc.h" |
17 |
< |
#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 |
17 |
> |
#include "paths.h" |
18 |
|
|
19 |
|
PSERVER *pslist = NULL; /* global process server list */ |
20 |
|
|
21 |
< |
static PROC *pindex[FD_SETSIZE]; /* process index table */ |
21 |
> |
static NETPROC *pindex[FD_SETSIZE]; /* process index table */ |
22 |
|
|
23 |
|
static char ourhost[64]; /* this host name */ |
24 |
< |
static char ourdir[128]; /* our working directory */ |
24 |
> |
static char ourdir[PATH_MAX]; /* our working directory */ |
25 |
|
static char ouruser[32]; /* our user name */ |
26 |
|
static char *ourshell; /* our user's shell */ |
27 |
|
|
28 |
|
static fd_set errdesc; /* error file descriptors */ |
29 |
|
static int maxfd; /* maximum assigned descriptor */ |
30 |
|
|
31 |
< |
extern char *malloc(), *realloc(); |
58 |
< |
extern char *getenv(); |
31 |
> |
extern char *remsh; /* externally defined remote shell program */ |
32 |
|
|
33 |
|
|
34 |
|
PSERVER * |
40 |
|
/* allocate the struct */ |
41 |
|
if (np < 1) |
42 |
|
return(NULL); |
43 |
< |
ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(PROC)); |
43 |
> |
ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(NETPROC)); |
44 |
|
if (ps == NULL) |
45 |
|
return(NULL); |
46 |
|
if (!ourhost[0]) { /* initialize */ |
47 |
< |
char dirtmp[128]; |
47 |
> |
char dirtmp[PATH_MAX]; |
48 |
|
register char *cp; |
49 |
|
register int len; |
50 |
|
|
51 |
< |
gethostname(ourhost, sizeof(ourhost)); |
51 |
> |
strcpy(ourhost, myhostname()); |
52 |
|
getcwd(dirtmp, sizeof(dirtmp)); |
53 |
|
if ((cp = getenv("HOME")) != NULL) { |
54 |
|
if (!strcmp(cp, dirtmp)) |
123 |
|
/* remove server from list */ |
124 |
|
psp->next = ps->next; |
125 |
|
pslist = pstart.next; |
126 |
< |
free((char *)ps); /* free associated memory */ |
126 |
> |
free((void *)ps); /* free associated memory */ |
127 |
|
} |
128 |
|
|
129 |
|
|
150 |
|
char *command; |
151 |
|
int (*compf)(); |
152 |
|
{ |
153 |
< |
char *av[12]; |
153 |
> |
char udirt[PATH_MAX]; |
154 |
> |
char *av[16]; |
155 |
|
int pfd[2], pid; |
156 |
|
register int i; |
157 |
|
|
172 |
|
exit(1); |
173 |
|
} |
174 |
|
/* start child process */ |
175 |
< |
if ((pid = vfork()) == 0) { |
175 |
> |
if ((pid = fork()) == 0) { |
176 |
|
close(pfd[0]); /* connect stderr to pipe */ |
177 |
|
if (pfd[1] != 2) { |
178 |
|
dup2(pfd[1], 2); |
179 |
|
close(pfd[1]); |
180 |
|
} |
181 |
|
if (ps->hostname[0]) { /* rsh command */ |
182 |
< |
av[i=0] = RSH; |
182 |
> |
av[i=0] = remsh; |
183 |
|
av[++i] = ps->hostname; |
184 |
< |
av[++i] = "-n"; /* no stdin */ |
185 |
< |
if (ps->username[0]) { |
184 |
> |
av[++i] = "-n"; /* no stdin */ |
185 |
> |
if (ps->username[0]) { /* different user */ |
186 |
|
av[++i] = "-l"; |
187 |
|
av[++i] = ps->username; |
188 |
+ |
av[++i] = "cd"; |
189 |
+ |
udirt[0] = '~'; |
190 |
+ |
strcpy(udirt+1, ouruser); |
191 |
+ |
av[++i] = udirt; |
192 |
+ |
av[++i] = ";"; |
193 |
|
} |
194 |
< |
if (ps->directory[0]) { |
194 |
> |
if (ps->directory[0]) { /* change directory */ |
195 |
|
av[++i] = "cd"; |
196 |
|
av[++i] = ps->directory; |
197 |
|
av[++i] = ";"; |
231 |
|
{ |
232 |
|
char errbuf[BUFSIZ]; |
233 |
|
int nr; |
234 |
< |
register PROC *pp; |
234 |
> |
register NETPROC *pp; |
235 |
|
/* look up associated process */ |
236 |
|
if ((pp = pindex[fd]) == NULL) |
237 |
|
abort(); /* serious consistency error */ |
246 |
|
if (pp->elen == 0) |
247 |
|
pp->errs = (char *)malloc(nr+1); |
248 |
|
else |
249 |
< |
pp->errs = (char *)realloc(pp->errs, pp->elen+nr+1); |
249 |
> |
pp->errs = (char *)realloc((void *)pp->errs, pp->elen+nr+1); |
250 |
|
if (pp->errs == NULL) { |
251 |
|
perror("malloc failed"); |
252 |
|
exit(1); |
285 |
|
int pn; |
286 |
|
int status; |
287 |
|
{ |
288 |
< |
register PROC *pp; |
288 |
> |
register NETPROC *pp; |
289 |
|
|
290 |
|
pp = ps->proc + pn; |
291 |
|
if (pp->cf != NULL) /* client cleanup */ |
293 |
|
close(pp->efd); /* close error stream */ |
294 |
|
pindex[pp->efd] = NULL; |
295 |
|
FD_CLR(pp->efd, &errdesc); |
296 |
< |
free((char *)pp->errs); |
296 |
> |
free((void *)pp->errs); |
297 |
|
pp->com = NULL; /* clear settings */ |
298 |
|
pp->pid = -1; |
299 |
|
pp->efd = -1; |