summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2008-07-24 15:35:41 +0000
committerchristos <christos@NetBSD.org>2008-07-24 15:35:41 +0000
commitecfa5800d4f86649daa8e77071dff0fcb26f7244 (patch)
treee800fc550542785f98ef7c23fb826661f84129f4 /usr.bin
parent3e1a92fedda9c1cb1f451f7aff35b32ff11962b7 (diff)
PR/39201: Brian Marcotte: "who am i" problem when using ptyfs, because it
strips pts/
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/who/who.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c
index ac4484f4784..9dd4e40ac33 100644
--- a/usr.bin/who/who.c
+++ b/usr.bin/who/who.c
@@ -1,4 +1,4 @@
-/* $NetBSD: who.c,v 1.22 2008/07/21 14:19:28 lukem Exp $ */
+/* $NetBSD: who.c,v 1.23 2008/07/24 15:35:41 christos Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#if 0
static char sccsid[] = "@(#)who.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: who.c,v 1.22 2008/07/21 14:19:28 lukem Exp $");
+__RCSID("$NetBSD: who.c,v 1.23 2008/07/24 15:35:41 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -206,6 +206,22 @@ main(int argc, char *argv[])
return 0;
}
+static char *
+strrstr(const char *str, const char *pat)
+{
+ const char *estr;
+ size_t len;
+ if (*pat == '\0')
+ return __UNCONST(str);
+
+ len = strlen(pat);
+
+ for (estr = str + strlen(str); str < estr; estr--)
+ if (strncmp(estr, pat, len) == 0)
+ return __UNCONST(estr);
+ return NULL;
+}
+
static void
who_am_i(const char *fname, int show_labels)
{
@@ -218,8 +234,9 @@ who_am_i(const char *fname, int show_labels)
/* 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)
+ /* strip directory prefixes for ttys */
+ if ((t = strrstr(p, "/pts/")) != NULL ||
+ (t = strrchr(p, '/')) != NULL)
p = t + 1;
(void)getutentries(fname, &ehead);