Date: Fri, 03 Feb 2006 00:29:48 +0100 From: Michal Mertl <mime@traveller.cz> To: freebsd-current@freebsd.org Subject: buglets with pts - with patch Message-ID: <1138922988.10456.29.camel@genius.i.cz>
next in thread | raw e-mail | index | archive | help
--=-EHgGsY+mVrGMXkzIh+ZU Content-Type: text/plain Content-Transfer-Encoding: 7bit I found a couple of display issues with the new pts type ptys. wall and who - don't check the utmp tty validity (see also PR bin/84041) The attached patch duplicates the check from the w program in who and wall. For some reason closed pts ttys are displayed/printed to when there wasn't a problem with the old pty implementation. ps - the TT column displays garbage (always "pts") The attached patch trims "pts/" from the tty name. The printout doesn't look nice ("10443 pts IWs 0:00,00 bash" changes to "10443 3 IWs 0:00,00 bash") but the field width is 4 which doesn't allow much. The right solution would probably involve removing TT column and always use the longer version TTY with width of 8 (which allows to correctly display "pts/3"). I checked Solaris 10 and it displays the full tty name by default. Regards Michal --=-EHgGsY+mVrGMXkzIh+ZU Content-Disposition: attachment; filename=wall.diff Content-Type: text/x-patch; name=wall.diff; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit Index: wall.c =================================================================== RCS file: /home/fcvs/cvs/src/usr.bin/wall/wall.c,v retrieving revision 1.23 diff -u -r1.23 wall.c --- wall.c 21 Feb 2003 08:46:44 -0000 1.23 +++ wall.c 2 Feb 2006 22:49:50 -0000 @@ -82,6 +82,19 @@ char *mbuf; int +ttystat(char *line, int sz) +{ + struct stat sb; + char ttybuf[MAXPATHLEN]; + + (void)snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line); + if (stat(ttybuf, &sb) == 0) { + return (0); + } else + return (-1); +} + +int main(int argc, char *argv[]) { struct iovec iov; @@ -140,6 +153,8 @@ while (fread((char *)&utmp, sizeof(utmp), 1, fp) == 1) { if (!utmp.ut_name[0]) continue; + if (ttystat(utmp.ut_line, UT_LINESIZE) != 0) + continue; if (grouplist) { ingroup = 0; strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name)); --=-EHgGsY+mVrGMXkzIh+ZU Content-Disposition: attachment; filename=who.diff Content-Type: text/x-patch; name=who.diff; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit Index: who.c =================================================================== RCS file: /home/fcvs/cvs/src/usr.bin/who/who.c,v retrieving revision 1.21 diff -u -r1.21 who.c --- who.c 29 May 2005 15:52:48 -0000 1.21 +++ who.c 2 Feb 2006 22:44:29 -0000 @@ -27,6 +27,7 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD: src/usr.bin/who/who.c,v 1.21 2005/05/29 15:52:48 charnier Exp $"); +#include <sys/param.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/stat.h> @@ -203,14 +204,31 @@ putchar('\n'); } +int +ttystat(char *line, int sz) +{ + struct stat sb; + char ttybuf[MAXPATHLEN]; + + (void)snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line); + if (stat(ttybuf, &sb) == 0) { + return (0); + } else + return (-1); +} + static void process_utmp(FILE *fp) { struct utmp ut; - while (fread(&ut, sizeof(ut), 1, fp) == 1) - if (*ut.ut_name != '\0') - row(&ut); + while (fread(&ut, sizeof(ut), 1, fp) == 1) { + if (*ut.ut_name == '\0') + continue; + if (ttystat(ut.ut_line, UT_LINESIZE) != 0) + continue; + row(&ut); + } } static void --=-EHgGsY+mVrGMXkzIh+ZU Content-Disposition: attachment; filename=ps.diff Content-Type: text/x-patch; name=ps.diff; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit Index: print.c =================================================================== RCS file: /home/fcvs/cvs/src/bin/ps/print.c,v retrieving revision 1.93 diff -u -r1.93 print.c --- print.c 20 Jul 2004 05:52:00 -0000 1.93 +++ print.c 2 Feb 2006 23:05:07 -0000 @@ -366,6 +366,8 @@ if (strncmp(ttname, "tty", 3) == 0 || strncmp(ttname, "cua", 3) == 0) ttname += 3; + if (strncmp(ttname, "pts/", 4) == 0) + ttname += 4; (void)printf("%*.*s%c", v->width - 1, v->width - 1, ttname, k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-'); } --=-EHgGsY+mVrGMXkzIh+ZU--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1138922988.10456.29.camel>