NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/38765: add setprogname to programs used in bootstrapping



>Number:         38765
>Category:       bin
>Synopsis:       add setprogname to programs used in bootstrapping
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue May 27 08:35:00 +0000 2008
>Originator:     Murray Armfield
>Release:        NetBSD-current
>Organization:
N/A
>Environment:
NetBSD zeus.river-styx.org 4.99.63 NetBSD 4.99.63 (ZEUS) #0: Tue May 27 
14:32:01 EST 2008  
admin%zeus.river-styx.org@localhost:/vol01/build/obj/sys/arch/amd64/compile/ZEUS
 amd64
>Description:
Being a good citizen in the portability world, the use of setprogname is 
recommended as not all platforms do this work as part of their equivalent crt 
code.

Also a little cleanup around the use of getprogname and usage().

It is not worth adding setprogname to programs that dont get built on other 
platforms.
>How-To-Repeat:
Code inspection
>Fix:
Index: disklabel/main.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/main.c,v
retrieving revision 1.18
diff -u -u -p -r1.18 main.c
--- disklabel/main.c    28 Apr 2008 20:23:08 -0000      1.18
+++ disklabel/main.c    27 May 2008 08:18:48 -0000
@@ -271,6 +271,8 @@ main(int argc, char *argv[])
                WRITE, INTERACT, DELETE
        } op = UNSPEC, old_op;

+       setprogname(argv[0]);
+
 #ifdef USE_MBR
        mflag = 1;
 #endif
Index: fdisk/fdisk.c
===================================================================
RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
retrieving revision 1.116
diff -u -u -p -r1.116 fdisk.c
--- fdisk/fdisk.c       9 Mar 2008 14:57:10 -0000       1.116
+++ fdisk/fdisk.c       27 May 2008 08:18:49 -0000
@@ -298,6 +298,8 @@ main(int argc, char *argv[])

        int csysid, cstart, csize;      /* For the b_flag. */

+       setprogname(argv[0]);
+
        a_flag = i_flag = u_flag = sh_flag = f_flag = s_flag = b_flag = 0;
        v_flag = 0;
        E_flag = 0;
Index: mknod/mknod.c
===================================================================
RCS file: /cvsroot/src/sbin/mknod/mknod.c,v
retrieving revision 1.37
diff -u -u -p -r1.37 mknod.c
--- mknod/mknod.c       28 Apr 2008 20:23:09 -0000      1.37
+++ mknod/mknod.c       27 May 2008 08:18:49 -0000
@@ -99,6 +99,8 @@ main(int argc, char **argv)
        fifo = hasformat = 0;
        pack = pack_native;

+       setprogname(argv[0]);
+
 #ifdef KERN_DRIVERS
        while ((ch = getopt(argc, argv, "lrRF:g:m:u:")) != -1) {
 #else
Index: cksum/cksum.c
===================================================================
RCS file: /cvsroot/src/usr.bin/cksum/cksum.c,v
retrieving revision 1.41
diff -u -u -p -r1.41 cksum.c
--- cksum/cksum.c       17 Jan 2007 00:21:43 -0000      1.41
+++ cksum/cksum.c       27 May 2008 08:20:23 -0000
@@ -172,7 +172,8 @@ main(int argc, char **argv)
        check_warn = 0;
        do_check = 0;

-       setlocale(LC_ALL, "");
+       setprogname(argv[0]);
+       (void)setlocale(LC_ALL, "");

        progname = getprogname();

Index: crunch/crunchgen/crunchgen.c
===================================================================
RCS file: /cvsroot/src/usr.bin/crunch/crunchgen/crunchgen.c,v
retrieving revision 1.73
diff -u -u -p -r1.73 crunchgen.c
--- crunch/crunchgen/crunchgen.c        18 Oct 2006 21:20:44 -0000      1.73
+++ crunch/crunchgen/crunchgen.c        27 May 2008 08:20:23 -0000
@@ -131,6 +131,8 @@ main(int argc, char **argv)
     char *p;
     int optc;

+    setprogname(argv[0]);
+
     if ((makebin = getenv("MAKE")) == NULL)
        makebin = strdup("make");

Index: ctags/ctags.c
===================================================================
RCS file: /cvsroot/src/usr.bin/ctags/ctags.c,v
retrieving revision 1.11
diff -u -u -p -r1.11 ctags.c
--- ctags/ctags.c       17 Feb 2005 17:29:58 -0000      1.11
+++ ctags/ctags.c       27 May 2008 08:20:23 -0000
@@ -94,6 +94,8 @@ main(int argc, char **argv)
        int     ch;                             /* getopts char */
        char    cmd[100];                       /* too ugly to explain */

+       setprogname(argv[0]);
+
        aflag = uflag = NO;
        while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
                switch(ch) {
Index: fgen/fgen.l
===================================================================
RCS file: /cvsroot/src/usr.bin/fgen/fgen.l,v
retrieving revision 1.27
diff -u -u -p -r1.27 fgen.l
--- fgen/fgen.l 22 Apr 2006 17:51:09 -0000      1.27
+++ fgen/fgen.l 27 May 2008 08:20:27 -0000
@@ -1009,6 +1009,8 @@ main(argc, argv)
        char *hdrtype = "version1";
        int i;

+       setprogname(argv[0]);
+
        outf = 1; /* stdout */
        myname = argv[0];

Index: gencat/gencat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/gencat/gencat.c,v
retrieving revision 1.25
diff -u -u -p -r1.25 gencat.c
--- gencat/gencat.c     28 Apr 2008 20:24:13 -0000      1.25
+++ gencat/gencat.c     27 May 2008 08:20:27 -0000
@@ -153,6 +153,8 @@ main(int argc, char *argv[])
        int     c;
        int     updatecat = 0;

+       setprogname(argv[0]);
+
        while ((c = getopt(argc, argv, "")) != -1) {
                switch (c) {
                case '?':
Index: hexdump/hexdump.c
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/hexdump.c,v
retrieving revision 1.13
diff -u -u -p -r1.13 hexdump.c
--- hexdump/hexdump.c   4 Jan 2006 01:30:21 -0000       1.13
+++ hexdump/hexdump.c   27 May 2008 08:20:27 -0000
@@ -67,6 +67,7 @@ main(int argc, char *argv[])
        FS *tfs;
        char *p;

+       setprogname(argv[0]);
        setlocale(LC_ALL, "");

        if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od"))
Index: join/join.c
===================================================================
RCS file: /cvsroot/src/usr.bin/join/join.c,v
retrieving revision 1.28
diff -u -u -p -r1.28 join.c
--- join/join.c 21 Feb 2007 20:45:27 -0000      1.28
+++ join/join.c 27 May 2008 08:20:27 -0000
@@ -124,6 +124,8 @@ main(int argc, char *argv[])
        int aflag, ch, cval, vflag;
        char *end;

+       setprogname(argv[0]);
+
        F1 = &input1;
        F2 = &input2;

Index: lex/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/lex/main.c,v
retrieving revision 1.17
diff -u -u -p -r1.17 main.c
--- lex/main.c  22 Apr 2006 20:51:09 -0000      1.17
+++ lex/main.c  27 May 2008 08:20:27 -0000
@@ -137,6 +137,8 @@ char **argv;
        {
        int i;

+       setprogname(argv[0]);
+
 #ifdef THINK_C
        argc = ccommand( &argv );
 #endif
Index: m4/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/m4/main.c,v
retrieving revision 1.36
diff -u -u -p -r1.36 main.c
--- m4/main.c   7 Jun 2005 09:25:00 -0000       1.36
+++ m4/main.c   27 May 2008 08:20:27 -0000
@@ -179,6 +179,8 @@ main(argc,argv)
        int n;
        char *p;

+       setprogname(argv[0]);
+
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                signal(SIGINT, onintr);

Index: make/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.149
diff -u -u -p -r1.149 main.c
--- make/main.c 15 Feb 2008 21:29:50 -0000      1.149
+++ make/main.c 27 May 2008 08:20:27 -0000
@@ -690,6 +690,8 @@ main(int argc, char **argv)
        struct utsname utsname;
 #endif

+       setprogname(argv[0]);
+
        /* default to writing debug to stdout */
        debug_file = stdout;

Index: menuc/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/menuc/main.c,v
retrieving revision 1.10
diff -u -u -p -r1.10 main.c
--- menuc/main.c        20 Jun 2004 22:20:16 -0000      1.10
+++ menuc/main.c        27 May 2008 08:20:27 -0000
@@ -57,15 +57,15 @@ __RCSID("$NetBSD: main.c,v 1.10 2004/06/
 #include "defs.h"

 /* Local prototypes */
-void usage (char *);
+void usage(void);

 int
 main (int argc, char **argv)
 {
        int ch;

-       prog_name = argv[0];
-
+       setprogname(argv[0]);
+
        /* Process the arguments. */
        while ( (ch = getopt (argc, argv, "o:")) != -1 ) {
                switch (ch) {
@@ -73,19 +73,19 @@ main (int argc, char **argv)
                        out_name = optarg;
                        break;
                default:
-                       usage (prog_name);
+                       usage();
                }
        }

        if (optind != argc-1)
-               usage (prog_name);
+               usage();

        src_name = argv[optind];

        yyin = fopen (src_name, "r");
        if (yyin == NULL) {
                (void) fprintf (stderr, "%s: could not open %s.\n",
-                               prog_name, src_name);
+                               getprogname(), src_name);
                exit (1);
        }

@@ -117,8 +117,8 @@ main (int argc, char **argv)


 void
-usage (char *prog)
+usage(void)
 {
-       (void) fprintf (stderr, "%s [-o name] file\n", prog);
+       (void) fprintf (stderr, "%s [-o name] file\n", getprogname());
        exit (1);
 }
Index: mkcsmapper/yacc.y
===================================================================
RCS file: /cvsroot/src/usr.bin/mkcsmapper/yacc.y,v
retrieving revision 1.7
diff -u -u -p -r1.7 yacc.y
--- mkcsmapper/yacc.y   9 Sep 2006 14:35:17 -0000       1.7
+++ mkcsmapper/yacc.y   27 May 2008 08:20:27 -0000
@@ -690,6 +690,8 @@ main(int argc, char **argv)
        FILE *in = NULL;
        int mkdb = 0, mkpv = 0;

+       setprogname(argv[0]);
+
        while ((ch=getopt(argc, argv, "do:mp")) != EOF) {
                switch (ch) {
                case 'd':
Index: mkesdb/yacc.y
===================================================================
RCS file: /cvsroot/src/usr.bin/mkesdb/yacc.y,v
retrieving revision 1.4
diff -u -u -p -r1.4 yacc.y
--- mkesdb/yacc.y       2 Jun 2005 02:09:25 -0000       1.4
+++ mkesdb/yacc.y       27 May 2008 08:20:27 -0000
@@ -306,6 +306,8 @@ main(int argc, char **argv)
        FILE *in = NULL;
        int mkdb = 0;

+       setprogname(argv[0]);
+
        while ((ch=getopt(argc, argv, "do:m")) != EOF) {
                switch (ch) {
                case 'd':
Index: mklocale/yacc.y
===================================================================
RCS file: /cvsroot/src/usr.bin/mklocale/yacc.y,v
retrieving revision 1.24
diff -u -u -p -r1.24 yacc.y
--- mklocale/yacc.y     5 Jan 2004 23:23:36 -0000       1.24
+++ mklocale/yacc.y     27 May 2008 08:20:27 -0000
@@ -256,8 +256,7 @@ main(ac, av)
 {
     int x;

-    extern char *optarg;
-    extern int optind;
+    setprogname(av[0]);

     while ((x = getopt(ac, av, "do:")) != EOF) {
        switch(x) {
Index: mktemp/mktemp.c
===================================================================
RCS file: /cvsroot/src/usr.bin/mktemp/mktemp.c,v
retrieving revision 1.10
diff -u -u -p -r1.10 mktemp.c
--- mktemp/mktemp.c     15 Dec 2007 19:44:52 -0000      1.10
+++ mktemp/mktemp.c     27 May 2008 08:20:27 -0000
@@ -64,7 +64,7 @@ main(int argc, char **argv)
        char *name;
        int dflag, qflag, tflag, uflag;

-       setprogname(*argv);
+       setprogname(argv[0]);
        ret = dflag = qflag = tflag = uflag = 0;
        prefix = "mktemp";
        name = NULL;
Index: msgc/msgmain.c
===================================================================
RCS file: /cvsroot/src/usr.bin/msgc/msgmain.c,v
retrieving revision 1.7
diff -u -u -p -r1.7 msgmain.c
--- msgc/msgmain.c      20 Jun 2004 22:20:16 -0000      1.7
+++ msgc/msgmain.c      27 May 2008 08:20:27 -0000
@@ -57,14 +57,14 @@ __RCSID("$NetBSD: msgmain.c,v 1.7 2004/0
 #include "defs.h"

 /* Local prototypes */
-void usage (char *);
+void usage(void);

 int
 main (int argc, char **argv)
 {
        int ch;

-       prog_name = argv[0];
+       setprogname(argv[0]);

        /* Process the arguments. */
        while ( (ch = getopt (argc, argv, "o:")) != -1 ) {
@@ -73,19 +73,19 @@ main (int argc, char **argv)
                        out_name = optarg;
                        break;
                default:
-                       usage (prog_name);
+                       usage();
                }
        }

        if (optind != argc-1)
-               usage (prog_name);
+               usage();

        src_name = argv[optind];

        yyin = fopen (src_name, "r");
        if (yyin == NULL) {
                (void) fprintf (stderr, "%s: could not open %s.\n",
-                               prog_name, src_name);
+                               getprogname(), src_name);
                exit (1);
        }

@@ -102,8 +102,8 @@ main (int argc, char **argv)


 void
-usage (char *prog)
+usage(void)
 {
-       (void) fprintf (stderr, "%s [-o name] file\n", prog);
+       (void) fprintf (stderr, "%s [-o name] file\n", getprogname());
        exit (1);
 }
Index: stat/stat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/stat/stat.c,v
retrieving revision 1.27
diff -u -u -p -r1.27 stat.c
--- stat/stat.c 16 May 2008 17:58:33 -0000      1.27
+++ stat/stat.c 27 May 2008 08:20:27 -0000
@@ -201,6 +201,8 @@ main(int argc, char *argv[])
        int lsF, fmtchar, usestat, fn, nonl, quiet;
        char *statfmt, *options, *synopsis;

+       setprogname(argv[0]);
+
        am_readlink = 0;
        lsF = 0;
        fmtchar = '\0';
Index: xlint/lint2/main2.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint2/main2.c,v
retrieving revision 1.7
diff -u -u -p -r1.7 main2.c
--- xlint/lint2/main2.c 20 Jun 2004 22:20:17 -0000      1.7
+++ xlint/lint2/main2.c 27 May 2008 08:20:27 -0000
@@ -99,6 +99,8 @@ main(int argc, char *argv[])
        size_t  len;
        char    *lname;

+       setprogname(argv[0]);
+
        libs = xcalloc(1, sizeof (char *));

        opterr = 0;
Index: yacc/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/yacc/main.c,v
retrieving revision 1.19
diff -u -u -p -r1.19 main.c
--- yacc/main.c 15 Dec 2007 19:44:54 -0000      1.19
+++ yacc/main.c 27 May 2008 08:20:27 -0000
@@ -459,6 +459,7 @@ open_files(void)
 int
 main(int argc, char *argv[])
 {
+    setprogname(argv[0]);
     set_signals();
     getargs(argc, argv);
     open_files();
Index: paxctl/paxctl.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/paxctl/paxctl.c,v
retrieving revision 1.7
diff -u -u -p -r1.7 paxctl.c
--- paxctl/paxctl.c     26 Dec 2007 22:16:31 -0000      1.7
+++ paxctl/paxctl.c     27 May 2008 08:20:40 -0000
@@ -306,6 +306,8 @@ main(int argc, char **argv)
        char *opt;
        int i, add_flags = 0, del_flags = 0, list = 0, bad = 0, many;

+       setprogname(argv[0]);
+
        if (argc < 2)
                usage();

Index: pwd_mkdb/pwd_mkdb.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pwd_mkdb/pwd_mkdb.c,v
retrieving revision 1.33
diff -u -u -p -r1.33 pwd_mkdb.c
--- pwd_mkdb/pwd_mkdb.c 24 Nov 2006 22:52:16 -0000      1.33
+++ pwd_mkdb/pwd_mkdb.c 27 May 2008 08:20:41 -0000
@@ -153,6 +153,8 @@ main(int argc, char *argv[])
        struct stat st;
        u_int cachesize;

+       setprogname(argv[0]);
+
        prefix[0] = '\0';
        makeold = 0;
        oldfp = NULL;
Index: sunlabel/sunlabel.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sunlabel/sunlabel.c,v
retrieving revision 1.22
diff -u -u -p -r1.22 sunlabel.c
--- sunlabel/sunlabel.c 28 Apr 2008 20:24:17 -0000      1.22
+++ sunlabel/sunlabel.c 27 May 2008 08:20:41 -0000
@@ -324,6 +324,8 @@ handleargs(int ac, char **av)
 {
        int c;

+       setprogname(av[0]);
+
        while ((c = getopt(ac, av, "mnqs")) != -1) {
                switch (c) {
                case 'm':
Index: veriexecgen/veriexecgen.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/veriexecgen/veriexecgen.c,v
retrieving revision 1.16
diff -u -u -p -r1.16 veriexecgen.c
--- veriexecgen/veriexecgen.c   29 Apr 2008 06:53:04 -0000      1.16
+++ veriexecgen/veriexecgen.c   27 May 2008 08:20:41 -0000
@@ -382,6 +382,8 @@ main(int argc, char **argv)
        hash_t *hash = NULL;
        veriexecgen_t   v;

+       setprogname(argv[0]);
+
        (void) memset(&v, 0x0, sizeof(v));
        make_immutable = 0;
        Fflag = 0;



Home | Main Index | Thread Index | Old Index