From fullermd@mortis.futuresouth.com  Thu Nov 12 02:03:20 1998
Received: from mortis.futuresouth.com (mortis.futuresouth.com [209.45.228.14])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA19218
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Nov 1998 02:03:19 -0800 (PST)
          (envelope-from fullermd@mortis.futuresouth.com)
Received: (from fullermd@localhost)
	by mortis.futuresouth.com (8.8.8/8.8.5) id EAA29366;
	Thu, 12 Nov 1998 04:03:00 -0600 (CST)
Message-Id: <199811121003.EAA29366@mortis.futuresouth.com>
Date: Thu, 12 Nov 1998 04:03:00 -0600 (CST)
From: fullermd@futuresouth.com
Reply-To: fullermd@futuresouth.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: w (-stable) has hardwired sizes
X-Send-Pr-Version: 3.2

>Number:         8662
>Category:       bin
>Synopsis:       w (-stable) has hardwired sizes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 12 02:10:00 PST 1998
>Closed-Date:    Sat Dec 12 20:09:12 PST 1998
>Last-Modified:  Sat Dec 12 20:10:35 PST 1998
>Originator:     Matthew Fuller
>Release:        FreeBSD 2.2.7-STABLE i386
>Organization:
FutureSouth Communications
>Environment:

	Various fairly bland -STABLE machines

>Description:

	w(1) has fixed sizes for field widths on the output.  This causes
	problems when running with >8 char usernames.
	Below patch is the one applied to -current in rev 1.27.
	Applies cleanly, looks to be working fine from this end.  Further
	testing couldn't, of course, hurt.  It shouldn't cause any problems
	for 8 char usernames (the default case), but makes migrating to
	different lengths easier.

>How-To-Repeat:

	See description.

>Fix:
	

Index: w.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/w/w.c,v
retrieving revision 1.16.2.7
diff -u -r1.16.2.7 w.c
--- w.c	1998/05/22 09:09:29	1.16.2.7
+++ w.c	1998/11/12 07:58:14
@@ -246,9 +246,18 @@
 		if (wcmd == 0)
 			exit (0);
 
-#define HEADER	"USER     TTY FROM              LOGIN@  IDLE WHAT\n"
-#define WUSED	(sizeof (HEADER) - sizeof ("WHAT\n"))
-		(void)printf(HEADER);
+#define HEADER_USER		"USER"
+#define HEADER_TTY		"TTY"
+#define HEADER_FROM		"FROM"
+#define HEADER_LOGIN_IDLE	"LOGIN@  IDLE "
+#define HEADER_WHAT		"WHAT\n"
+#define WUSED  (UT_NAMESIZE + UT_LINESIZE + UT_HOSTSIZE + \
+		sizeof(HEADER_LOGIN_IDLE) + 3)	/* header width incl. spaces */ 
+		(void)printf("%-*.*s %-*.*s %-*.*s  %s", 
+				UT_NAMESIZE, UT_NAMESIZE, HEADER_USER,
+				UT_LINESIZE, UT_LINESIZE, HEADER_TTY,
+				UT_HOSTSIZE, UT_HOSTSIZE, HEADER_FROM,
+				HEADER_LOGIN_IDLE HEADER_WHAT);
 	}
 
 	if ((kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries)) == NULL)
@@ -372,8 +381,9 @@
 				(void)printf( "\t\t%-9d %s\n", dkp->kp_proc.p_pid, p);
 			}
 		}
-		(void)printf("%-*.*s %-3.3s %-*.*s ",
+		(void)printf("%-*.*s %-*.*s %-*.*s ",
 		    UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name,
+		    UT_LINESIZE, UT_LINESIZE,
 		    strncmp(ep->utmp.ut_line, "tty", 3) &&
 		    strncmp(ep->utmp.ut_line, "cua", 3) ?
 		    ep->utmp.ut_line : ep->utmp.ut_line + 3,

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: dillon 
State-Changed-When: Sat Dec 12 20:09:12 PST 1998 
State-Changed-Why:  
Well, we missed this in the 2.2.8 releas and that's the final release.  I 
verified that the printfs use dynamic sizes in the -current version so I 
am just going to close this PR. 

Thanks for the report, though! 

-Matt 
>Unformatted:
