Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site pur-ee.UUCP
Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!ks
From: ks@pur-ee.UUCP (Smith)
Newsgroups: net.unix-wizards
Subject: Script screws up after rlogind dies..
Message-ID: <2442@pur-ee.UUCP>
Date: Fri, 14-Dec-84 21:18:24 EST
Article-I.D.: pur-ee.2442
Posted: Fri Dec 14 21:18:24 1984
Date-Received: Sun, 16-Dec-84 04:50:13 EST
Organization: Electrical Engineering Department , Purdue University
Lines: 86

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 
  #include 
  #include 
  
  char	*getenv();
  char	*ctime();

--- 12,18 -----
  #include 
  #include 
  #include 
+ #include 
  
  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()