[net.unix-wizards] Script screws up after rlogind dies..

ks@pur-ee.UUCP (Smith) (12/15/84)

Description:
	Often, rlogin daemons terminate abnormally and fail to reset
	the modes on the psuedo tty.  The next rlogin daemon can
	fix this since it runs as root, but script runs as the
	individual user and has no recourse.  When script can't
	open the tty, it merely says "Permission denied" and exits.
	It should just skip over that pty and try the next...
Repeat-By:
	% chmod 622 /dev/ttyp0
		- or -
	% kill -9 rlogindpid
	% script
	Permission denied
Fix:
	Just don't use a tty that you can't read and write:

RCS file: RCS/script.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -c -r1.1 -r1.3
*** /tmp/,RCSt1007377	Fri Dec 14 21:10:58 1984
--- /tmp/,RCSt2007377	Fri Dec 14 21:11:02 1984
***************
*** 12,17
  #include <sys/ioctl.h>
  #include <sgtty.h>
  #include <sys/time.h>
  
  char	*getenv();
  char	*ctime();

--- 12,18 -----
  #include <sys/ioctl.h>
  #include <sgtty.h>
  #include <sys/time.h>
+ #include <sys/file.h>
  
  char	*getenv();
  char	*ctime();
***************
*** 191,196
  			line[strlen("/dev/ptyp")] = "0123456789abcdef"[i];
  			master = open(line, 2);
  			if (master >= 0) {
  				ioctl(0, TIOCGETP, (char *)&b);
  				ioctl(0, TIOCGETC, (char *)&tc);
  				ioctl(0, TIOCGETD, (char *)&l);

--- 192,201 -----
  			line[strlen("/dev/ptyp")] = "0123456789abcdef"[i];
  			master = open(line, 2);
  			if (master >= 0) {
+ 				if (!checkslave()) {
+ 					close(master);
+ 					continue;
+ 				}
  				ioctl(0, TIOCGETP, (char *)&b);
  				ioctl(0, TIOCGETC, (char *)&tc);
  				ioctl(0, TIOCGETD, (char *)&l);
***************
*** 202,207
  	}
  	fprintf(stderr, "Out of pty's\n");
  	fail();
  }
  
  getslave()

--- 207,223 -----
  	}
  	fprintf(stderr, "Out of pty's\n");
  	fail();
+ }
+ 
+ checkslave()
+ {
+ 	line[strlen("/dev/")] = 't';
+ 	if (access(line, R_OK|W_OK) < 0) {
+ 		line[strlen("/dev/")] = 'p';
+ 		return 0;
+ 	}
+ 	line[strlen("/dev/")] = 'p';
+ 	return 1;
  }
  
  getslave()

dave@garfield.UUCP (David Janes) (12/18/84)

Also, it helps to add these lines to rc.local: 

chown root /dev/tty[pqr]*
chmod 666 /dev/tty[pqr]*

A common reason for rlogind being terminated abnormally is system crashes.

dave (the Mercenary Programmer)
-------
David Janes 	(Dept. of Redundancy Dept.)
Internet:	dave@garfield.UUCP
UUCP:		{allegra,ihnp4,utcsrgv}!garfield!dave