>Number: 39201
>Category: bin
>Synopsis: "who am i" problem when using ptyfs
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jul 24 09:50:00 +0000 2008
>Originator: Brian Marcotte
>Release: 4.0, looks like -current as well
>Organization:
Panix
>Environment:
NetBSD panix5.panix.com 4.0 NetBSD 4.0 (PANIX-XEN3U-USER) #1: Tue Apr 1 23:24:49 EDT 2008
root@...:/misc2/obj/misc2/devel/netbsd/4.0/src/sys/arch/i386/compile/PANIX-XEN3U-USER i386
>Description:
"who am i" does not work properly when using ptyfs. It does not find the users' ttyname in the utmp file, so prints only the current time rather than the time of login and remote host name.
$ who am i
marcotte 10 Jul 24 05:43
It should print:
marcotte pts/10 Jul 22 03:29 (166.84.167.10)
The code removes "/dev/pts/" from the ttyname, but "pts/" is in the utmp entries.
The patch below just removes "/dev/" if present.
>How-To-Repeat:
Compare the output of "who am i" with and without ptyfs.
>Fix:
diff -u who.c.orig who.c
--- who.c.orig 2006-09-28 11:24:31.000000000 -0400
+++ who.c 2008-07-24 05:35:51.000000000 -0400
@@ -212,16 +212,15 @@
{
struct passwd *pw;
const char *p;
- char *t;
time_t now;
struct utmpentry *ehead, *ep;
/* search through the utmp and find an entry for this tty */
if ((p = ttyname(STDIN_FILENO)) != NULL) {
- /* strip any directory component */
- if ((t = strrchr(p, '/')) != NULL)
- p = t + 1;
+ /* Remove "/dev/" if present */
+ if (strncmp("/dev/",p,5)==0)
+ p += 5;
(void)getutentries(fname, &ehead);
for (ep = ehead; ep; ep = ep->next)