Subject: Re: "who" question
To: None <emre@vsrc.uab.edu>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-users
Date: 05/29/2001 22:45:06
On Mon, 28 May 2001 emre@vsrc.uab.edu wrote:
> When I type "who" I can see all users logged on and the hosst they are
> logged from. But somehow I can only see part of the hostname (if it's
> too long). Is there a way to make it show the full hostname?
/usr/src/usr.bin/who/who.c uses:
printf("\t(%.*s)", (int)UT_HOSTSIZE, up->ut_host);
UT_HOSTSIZE is 16.
It would be interesting to add an option for no cropped strings; here is
something to try (use the -N switch):
--- who.c-orig Tue May 29 22:30:15 2001
+++ who.c Tue May 29 22:41:19 2001
@@ -70,6 +70,7 @@
@@ -70,6 +70,7 @@
int show_term; /* show term state */
int show_idle; /* show idle time */
+int no_crop; /* i.e. don't shorten hostnames */
int main __P((int, char **));
@@ -84,8 +85,8 @@
setlocale(LC_ALL, "");
- only_current_term = show_term = show_idle = show_labels = 0;
- while ((c = getopt(argc, argv, "mTuH")) != -1) {
+ only_current_term = show_term = show_idle = show_labels = no_crop = 0;
+ while ((c = getopt(argc, argv, "mTuHN")) != -1) {
switch (c) {
case 'm':
only_current_term = 1;
@@ -99,6 +100,9 @@
case 'H':
show_labels = 1;
break;
+ case 'N':
+ no_crop = 1; /* don't shorten strings */
+ break;
default:
usage();
/* NOTREACHED */
@@ -209,13 +213,21 @@
}
- (void)printf("%-*.*s ", (int)UT_NAMESIZE, (int)UT_NAMESIZE, up->ut_name);
+ if (! no_crop)
+ (void)printf("%-*.*s ",
+ (int)UT_NAMESIZE, (int)UT_NAMESIZE, up->ut_name);
+ else
+ (void)printf("%s ", up->ut_name);
if (show_term) {
(void)printf("%c ", state);
}
- (void)printf("%-*.*s ", (int)UT_LINESIZE, (int)UT_LINESIZE, up->ut_line);
+ if (! no_crop)
+ (void)printf("%-*.*s ",
+ (int)UT_LINESIZE, (int)UT_LINESIZE, up->ut_line);
+ else
+ (void)printf("%s ", up->ut_line);
(void)printf("%.12s ", ctime(&up->ut_time) + 4);
if (show_idle) {
@@ -229,8 +241,12 @@
(void)printf(" old ");
}
- if (*up->ut_host)
- printf("\t(%.*s)", (int)UT_HOSTSIZE, up->ut_host);
+ if (*up->ut_host) {
+ if (! no_crop)
+ printf("\t(%.*s)", (int)UT_HOSTSIZE, up->ut_host);
+ else
+ printf("\t(%s)", up->ut_host);
+ }
(void)putchar('\n');
}
@@ -269,6 +285,6 @@
void
usage()
{
- (void)fprintf(stderr, "usage: who [-mTuH] [ file ]\n who am i\n");
+ (void)fprintf(stderr, "usage: who [-mTuHN] [ file ]\n who am i\n");
exit(1);
}
Jeremy C. Reed
http://www.reedmedia.net/