From owner-freebsd-current@FreeBSD.ORG Mon Jul 16 14:57:39 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2CDE216A4AB for ; Mon, 16 Jul 2007 14:57:39 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id E716B13C4BD for ; Mon, 16 Jul 2007 14:57:38 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.7b8) with ESMTP id 196960693 for multiple; Mon, 16 Jul 2007 11:05:55 -0400 Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l6GEvML8032514; Mon, 16 Jul 2007 10:57:35 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-current@freebsd.org Date: Mon, 16 Jul 2007 09:08:30 -0400 User-Agent: KMail/1.9.6 References: <20070617213948.GA50404@rot13.obsecurity.org> In-Reply-To: <20070617213948.GA50404@rot13.obsecurity.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707160908.31093.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 16 Jul 2007 10:57:35 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3681/Mon Jul 16 09:16:18 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: Kris Kennaway Subject: Re: Userland problems from kern.pts.enable=1 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2007 14:57:39 -0000 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 @@ -715,10 +715,11 @@ { 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; @@ -745,21 +746,31 @@ 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