Re: Userland problems from kern.pts.enable=1

From: John Baldwin <jhb_at_freebsd.org>
Date: Mon, 16 Jul 2007 09:08:30 -0400
On Sunday 17 June 2007 05:39:48 pm Kris Kennaway wrote:
> When the kern.pts.enable sysctl is set to '1', pseudo-ttys are created
> with device name /dev/pts/${NUMBER}.  With some kernel fixes from kib
> this appears to now be stable and the kernel side is ready for a
> possible change of default.  However, the new device naming confuses
> some userland utilities.  For example:
> 
> pointyhat# write simon
> write: /dev/398: No such file or directory
> 
> simon was logged in on /dev/pts/398.
> 
> killall -t also fails to parse the new device format:
> 
> bento# ps -t pts/187
>   PID  TT  STAT      TIME COMMAND
> 67734 187  Ss     0:00.04 /bin/csh
> 72599 187  R+     0:00.00 ps -t pts/187
> bento# killall -t pts/187
> killall: stat(/dev/ttypts/187): No such file or directory
> 
> It would also be useful if ps -t recognized a numeric argument as
> magic and converted it to add the pts/.  It already appears to do the
> converse when displaying the TTY, as you can see above.
> 
> There are probably other utilities also affected.

Patch for ps (if you didn't get one already):
Index: ps.c
===================================================================
RCS file: /usr/cvs/src/bin/ps/ps.c,v
retrieving revision 1.110
diff -u -r1.110 ps.c
--- ps.c	9 Feb 2005 17:37:38 -0000	1.110
+++ ps.c	16 Jul 2007 13:07:01 -0000
_at__at_ -715,10 +715,11 _at__at_
 {
 	const char *ttypath;
 	struct stat sb;
-	char pathbuf[PATH_MAX], pathbuf2[PATH_MAX];
+	char pathbuf[PATH_MAX], pathbuf2[PATH_MAX], pathbuf3[PATH_MAX];
 
 	ttypath = NULL;
 	pathbuf2[0] = '\0';
+	pathbuf3[0] = '\0';
 	switch (*elem) {
 	case '/':
 		ttypath = elem;
_at__at_ -745,21 +746,31 _at__at_
 			ttypath = NULL;	
 			break;
 		}
+		/* Check to see if /dev/pts/${elem} exists */
+		strlcpy(pathbuf3, _PATH_DEV, sizeof(pathbuf2));
+		strlcat(pathbuf3, "pts/", sizeof(pathbuf2));
+		strlcat(pathbuf3, elem, sizeof(pathbuf2));
+		if (stat(pathbuf3, &sb) == 0 && S_ISCHR(sb.st_mode)) {
+			/* No need to repeat stat() && S_ISCHR() checks */
+			ttypath = NULL;	
+			break;
+		}
 		break;
 	}
 	if (ttypath) {
 		if (stat(ttypath, &sb) == -1) {
-			if (pathbuf2[0] != '\0')
-				warn("%s and %s", pathbuf2, ttypath);
+			if (pathbuf3[0] != '\0')
+				warn("%s, %s, and %s", pathbuf3, pathbuf2,
+				    ttypath);
 			else
 				warn("%s", ttypath);
 			optfatal = 1;
 			return (0);
 		}
 		if (!S_ISCHR(sb.st_mode)) {
-			if (pathbuf2[0] != '\0')
-				warnx("%s and %s: Not a terminal", pathbuf2,
-				    ttypath);
+			if (pathbuf3[0] != '\0')
+				warnx("%s, %s, and %s: Not a terminal",
+				    pathbuf3, pathbuf2, ttypath);
 			else
 				warnx("%s: Not a terminal", ttypath);
 			optfatal = 1;

-- 
John Baldwin
Received on Mon Jul 16 2007 - 12:57:39 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:14 UTC