summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-02-13 05:27:16 +0000
committerJim Meyering <jim@meyering.net>1996-02-13 05:27:16 +0000
commit0b2ebf98755aacf850ac68022bbe3b7bd93128ea (patch)
tree1bcea4ca5b09be014de142847d9d849e1de7e5b8 /src
parentaa35ed104c9d5fc280e56e39712b4a93f27351ee (diff)
downloadcoreutils-0b2ebf98755aacf850ac68022bbe3b7bd93128ea.tar.xz
(print_entry): If possible, canonicalize the host hame.
From Miles Bader (miles@gnu.ai.mit.edu).
Diffstat (limited to 'src')
-rw-r--r--src/who-users.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/who-users.c b/src/who-users.c
index bf32dc8fe..8a09088c5 100644
--- a/src/who-users.c
+++ b/src/who-users.c
@@ -1,5 +1,5 @@
/* GNU's users/who.
- Copyright (C) 92, 93, 94, 1995 Free Software Foundation, Inc.
+ Copyright (C) 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -245,7 +245,31 @@ print_entry (struct utmp *this)
}
#ifdef HAVE_UT_HOST
if (this->ut_host[0])
- printf (" (%-.*s)", (int) sizeof (this->ut_host), this->ut_host);
+ {
+ extern char *canon_host ();
+ char ut_host[sizeof (this->ut_host) + 1];
+ char *host = 0, *display = 0;
+
+ /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
+ strncpy (ut_host, this->ut_host, (int) sizeof (this->ut_host));
+ ut_host[sizeof (this->ut_host)] = '\0';
+
+ /* Look for an X display. */
+ display = index (ut_host, ':');
+ if (display)
+ *display++ = '\0';
+
+ if (*ut_host)
+ /* See if we can canonicalize it. */
+ host = canon_host (ut_host);
+ if (! host)
+ host = ut_host;
+
+ if (display)
+ printf (" (%s:%s)", host, display);
+ else
+ printf (" (%s)", host);
+ }
#endif
putchar ('\n');