Subject: sam -r <machine> *

From: [email-masked]
Date: Wed, 7 Jul 1993 12:01:15 -0400

I've always found it strange that ``sam -r machine'' was mutually
exclusive with ``sam [option ...] [files].'' A quick look at the
source revealed that it could easily be changed to allow the -r
option to pass the list of files to sam on the remote machine.
Here's the patch:

diff -C 2 -r old.sam/sam/io.c new.sam/sam/io.c
*** old.sam/sam/io.c	Wed Jul  7 13:34:43 1993
--- new.sam/sam/io.c	Wed Jul  7 15:44:21 1993
***************
*** 215,221 ****
  
  void
! connectto(char *machine)
  {
  	int p1[2], p2[2];
  
  	if(pipe(p1)<0 || pipe(p2)<0){
--- 215,222 ----
  
  void
! connectto(char *machine, int fargc, char **fargv)
  {
  	int p1[2], p2[2];
+ 	char **nargv, **fp, **tp;
  
  	if(pipe(p1)<0 || pipe(p2)<0){
***************
*** 227,230 ****
--- 228,239 ----
  	switch(fork()){
  	case 0:
+ 		tp = nargv = emalloc((4+fargc)*sizeof(char *));
+ 		*tp++ = RX;
+ 		*tp++ = machine;
+ 		*tp++ = rsamname;
+ 		*tp++ = "-R";
+ 		fp = fargv;
+ 		while (*tp++ = *fp++)
+ 			;
  		dup(p2[0], 0);
  		dup(p1[1], 1);
***************
*** 233,237 ****
  		close(p2[0]);
  		close(p2[1]);
! 		execl(RXPATH, RX, machine, rsamname, "-R", (char*)0);
  		dprint("can't exec %s\n", RXPATH);
  		exits("exec");
--- 242,246 ----
  		close(p2[0]);
  		close(p2[1]);
! 		exec(RXPATH, nargv);
  		dprint("can't exec %s\n", RXPATH);
  		exits("exec");
***************
*** 246,253 ****
  
  void
! startup(char *machine, int Rflag, char **argv, char **end)
  {
  	if(machine)
! 		connectto(machine);
  	if(!Rflag)
  		bootterm(machine, argv, end);
--- 255,262 ----
  
  void
! startup(char *machine, int Rflag, char **argv, char **end, int fargc, char **fargv)
  {
  	if(machine)
! 		connectto(machine, fargc, fargv);
  	if(!Rflag)
  		bootterm(machine, argv, end);
diff -C 2 -r old.sam/sam/sam.c new.sam/sam/sam.c
*** old.sam/sam/sam.c	Wed Jul  7 13:35:03 1993
--- new.sam/sam/sam.c	Wed Jul  7 15:28:01 1993
***************
*** 95,99 ****
  		home = "/";
  	if(!dflag)
! 		startup(machine, Rflag, arg, ap);
  	Fstart();
  	notify(notifyf);
--- 95,99 ----
  		home = "/";
  	if(!dflag)
! 		startup(machine, Rflag, arg, ap, argc, argv);
  	Fstart();
  	notify(notifyf);
diff -C 2 -r old.sam/sam/sam.h new.sam/sam/sam.h
*** old.sam/sam/sam.h	Wed Jul  7 13:35:05 1993
--- new.sam/sam/sam.h	Wed Jul  7 15:30:18 1993
***************
*** 286,290 ****
  void	snarf(File*, Posn, Posn, Buffer*, int);
  void	sortname(File*);
! void	startup(char*, int, char**, char**);
  void	state(File*, int);
  int	statfd(int, ulong*, ulong*, long*, long*);
--- 286,290 ----
  void	snarf(File*, Posn, Posn, Buffer*, int);
  void	sortname(File*);
! void	startup(char*, int, char**, char**, int, char**);
  void	state(File*, int);
  int	statfd(int, ulong*, ulong*, long*, long*);