Subject: bin/15771: progname need not be global
To: None <gnats-bugs@gnats.netbsd.org>
From: None <franklin@elfie.org>
List: netbsd-bugs
Date: 02/28/2002 17:25:12
>Number:         15771
>Category:       bin
>Synopsis:       progname need not be global
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 28 14:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     John Franklin
>Release:        NetBSD 1.5ZA
>Organization:
	
>Environment:
	
	
# ident arp
arp:
     $NetBSD: crt0.c,v 1.12 2001/12/30 23:23:38 thorpej Exp $
     $NetBSD: arp.c,v 1.32 2001/10/06 19:09:44 bjh21 Exp $

System: NetBSD deathmitten 1.5ZA NetBSD 1.5ZA (DM.MP) #0: Sun Feb 24 13:09:22 EST 2002 franklin@deathmitten:/usr/src/sys/arch/i386-MP/compile/DM.MP i386
Architecture: i386
Machine: i386
>Description:
	
With the inclusion of getprogname() in libc, we no longer need to 
explicitly extract the program name from argv[0].  Since it is only 
used in usage(), we can initialize it in and limit its scope to usage().
>How-To-Repeat:
	
Inspection of /usr/src/usr.sbin/arp/arp.c will reveal.
>Fix:
	
Apply the following patch.

RCS file: /cvsroot/basesrc/usr.sbin/arp/arp.c,v
retrieving revision 1.32
diff -u -r1.32 arp.c
--- arp.c       2001/10/06 19:09:44     1.32
+++ arp.c       2002/02/28 22:18:28
@@ -105,7 +105,6 @@
 
 static struct ifconf ifc;
 static char ifconfbuf[8192];
-static char *progname;
 
 int
 main(argc, argv)
@@ -116,7 +115,6 @@
        int op = 0;
 
        pid = getpid();
-       progname = ((progname = strrchr(argv[0], '/')) ? progname + 1 : argv[0]);
 
        while ((ch = getopt(argc, argv, "andsfv")) != -1)
                switch((char)ch) {
@@ -557,6 +555,7 @@
 void
 usage()
 {
+       const char *progname = getprogname();
 
        (void)fprintf(stderr, "usage: %s [-n] hostname\n", progname);
        (void)fprintf(stderr, "usage: %s [-n] -a\n", progname);

>Release-Note:
>Audit-Trail:
>Unformatted: