less progname in r

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

less progname in r

Ted Unangst-6
These programs don't do anything interesting based on progname, except to echo
is back to the user. If the user creates a link, is it somehow more correct
to print that name? I'd argue the original name is better (especially in
usage) because then you have a hint what man page to read.


Index: radioctl/radioctl.c
===================================================================
RCS file: /cvs/src/usr.bin/radioctl/radioctl.c,v
retrieving revision 1.19
diff -u -p -r1.19 radioctl.c
--- radioctl/radioctl.c 21 Dec 2013 06:54:53 -0000 1.19
+++ radioctl/radioctl.c 24 Jun 2016 01:47:26 -0000
@@ -94,7 +94,6 @@ struct chansets {
 { 0, NULL }
 };
 
-extern char *__progname;
 const char *onchar = "on";
 #define ONCHAR_LEN 2
 const char *offchar = "off";
@@ -218,10 +217,9 @@ void
 usage(void)
 {
  fprintf(stderr,
-    "usage: %s [-anv] [-f file]\n"
-    "       %s [-nv] [-f file] name\n"
-    "       %s [-n] [-f file] name=value\n",
-    __progname, __progname, __progname);
+    "usage: radioctl [-anv] [-f file]\n"
+    "       radioctl [-nv] [-f file] name\n"
+    "       radioctl [-n] [-f file] name=value\n");
  exit(1);
 }
 
Index: rdist/common.c
===================================================================
RCS file: /cvs/src/usr.bin/rdist/common.c,v
retrieving revision 1.37
diff -u -p -r1.37 common.c
--- rdist/common.c 22 Dec 2015 08:48:39 -0000 1.37
+++ rdist/common.c 24 Jun 2016 01:48:13 -0000
@@ -62,7 +62,6 @@ int isserver = FALSE; /* We're the ser
 int     amchild = 0; /* This PID is a child */
 int do_fork = 1; /* Fork child process */
 char       *currenthost = NULL; /* Current client hostname */
-char       *progname = NULL; /* Name of this program */
 int rem_r = -1; /* Client file descriptor */
 int rem_w = -1; /* Client file descriptor */
 struct passwd       *pw = NULL; /* Local user's pwd entry */
Index: rdist/defs.h
===================================================================
RCS file: /cvs/src/usr.bin/rdist/defs.h,v
retrieving revision 1.36
diff -u -p -r1.36 defs.h
--- rdist/defs.h 21 Jan 2015 03:05:03 -0000 1.36
+++ rdist/defs.h 24 Jun 2016 01:48:18 -0000
@@ -156,7 +156,6 @@
 
 
 extern char       *currenthost; /* Name of current host */
-extern char       *progname; /* Name of this program */
 extern char       *locuser; /* Local User's name */
 extern int debug; /* Debugging flag */
 extern int isserver; /* Acting as remote server */
Index: rdist/message.c
===================================================================
RCS file: /cvs/src/usr.bin/rdist/message.c,v
retrieving revision 1.28
diff -u -p -r1.28 message.c
--- rdist/message.c 30 Mar 2016 20:51:59 -0000 1.28
+++ rdist/message.c 24 Jun 2016 01:48:30 -0000
@@ -251,7 +251,7 @@ setmsgtypes(struct msgfacility *msgfac,
  break;
 
  case MF_SYSLOG:
- openlog(progname, LOG_PID, LOG_DAEMON);
+ openlog("rdist", LOG_PID, LOG_DAEMON);
  break;
  }
 
Index: rdist/rdist.c
===================================================================
RCS file: /cvs/src/usr.bin/rdist/rdist.c,v
retrieving revision 1.30
diff -u -p -r1.30 rdist.c
--- rdist/rdist.c 8 Feb 2015 23:40:34 -0000 1.30
+++ rdist/rdist.c 24 Jun 2016 01:48:55 -0000
@@ -87,7 +87,6 @@ addhostlist(char *name, struct namelist
 int
 main(int argc, char **argv, char **envp)
 {
- extern char *__progname;
  struct namelist *hostlist = NULL;
  char *distfile = NULL;
  char *cp;
@@ -95,8 +94,6 @@ main(int argc, char **argv, char **envp)
  int c;
  const char *errstr;
 
- progname = __progname;
-
  if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) {
  error("Bad builtin log option (%s): %s.",
       localmsglist, cp);
@@ -334,16 +331,15 @@ opendist(char *distfile)
 static void
 usage(void)
 {
- extern char *__progname;
 
  (void) fprintf(stderr,
- "usage: %s [-DFnV] [-A num] [-a num] "
+ "usage: rdist [-DFnV] [-A num] [-a num] "
  "[-c mini_distfile]\n"
  "\t[-d var=value] [-f distfile] [-L remote_logopts] "
  "[-l local_logopts]\n"
  "\t[-M maxproc] [-m host] [-o distopts] [-P rsh-path] "
  "[-p rdistd-path]\n"
- "\t[-t timeout] [name ...]\n", __progname);
+ "\t[-t timeout] [name ...]\n");
 
 
  (void) fprintf(stderr, "\nThe values for <distopts> are:\n\t%s\n",
Index: rev/rev.c
===================================================================
RCS file: /cvs/src/usr.bin/rev/rev.c,v
retrieving revision 1.13
diff -u -p -r1.13 rev.c
--- rev/rev.c 10 Apr 2016 17:06:52 -0000 1.13
+++ rev/rev.c 24 Jun 2016 01:51:17 -0000
@@ -110,8 +110,7 @@ isu8cont(unsigned char c)
 void
 usage(void)
 {
- extern char *__progname;
 
- (void)fprintf(stderr, "usage: %s [file ...]\n", __progname);
+ fprintf(stderr, "usage: rev [file ...]\n");
  exit(1);
 }
Index: rs/rs.c
===================================================================
RCS file: /cvs/src/usr.bin/rs/rs.c,v
retrieving revision 1.30
diff -u -p -r1.30 rs.c
--- rs/rs.c 3 Dec 2015 12:23:15 -0000 1.30
+++ rs/rs.c 24 Jun 2016 01:50:10 -0000
@@ -227,11 +227,9 @@ prints(struct entry *ep, int col)
 void
 usage(void)
 {
- extern char *__progname;
 
  fprintf(stderr,
-    "usage: %s [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]\n",
-    __progname);
+    "usage: rs [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]\n");
  exit(1);
 }
 
Index: rwall/rwall.c
===================================================================
RCS file: /cvs/src/usr.bin/rwall/rwall.c,v
retrieving revision 1.13
diff -u -p -r1.13 rwall.c
--- rwall/rwall.c 16 Jan 2015 06:40:11 -0000 1.13
+++ rwall/rwall.c 24 Jun 2016 01:50:30 -0000
@@ -59,12 +59,11 @@ void makemsg(char *);
 int
 main(int argc, char *argv[])
 {
- extern char *__progname;
  char *wallhost, res;
  CLIENT *cl;
 
  if ((argc < 2) || (argc > 3)) {
- fprintf(stderr, "usage: %s host [file]\n", __progname);
+ fprintf(stderr, "usage: rwall host [file]\n");
  exit(1);
  }
 

Reply | Threaded
Open this post in threaded view
|

Re: less progname in r

Mark Kettenis
> From: "Ted Unangst" <[hidden email]>
> Date: Thu, 23 Jun 2016 21:57:00 -0400
>
> These programs don't do anything interesting based on progname,
> except to echo is back to the user. If the user creates a link, is
> it somehow more correct to print that name? I'd argue the original
> name is better (especially in usage) because then you have a hint
> what man page to read.

Using __progname in this context has been the standard on *BSD for a
long time.  This really feels like unnecessary churn to me.

> Index: radioctl/radioctl.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/radioctl/radioctl.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 radioctl.c
> --- radioctl/radioctl.c 21 Dec 2013 06:54:53 -0000 1.19
> +++ radioctl/radioctl.c 24 Jun 2016 01:47:26 -0000
> @@ -94,7 +94,6 @@ struct chansets {
>  { 0, NULL }
>  };
>  
> -extern char *__progname;
>  const char *onchar = "on";
>  #define ONCHAR_LEN 2
>  const char *offchar = "off";
> @@ -218,10 +217,9 @@ void
>  usage(void)
>  {
>   fprintf(stderr,
> -    "usage: %s [-anv] [-f file]\n"
> -    "       %s [-nv] [-f file] name\n"
> -    "       %s [-n] [-f file] name=value\n",
> -    __progname, __progname, __progname);
> +    "usage: radioctl [-anv] [-f file]\n"
> +    "       radioctl [-nv] [-f file] name\n"
> +    "       radioctl [-n] [-f file] name=value\n");
>   exit(1);
>  }
>  
> Index: rdist/common.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rdist/common.c,v
> retrieving revision 1.37
> diff -u -p -r1.37 common.c
> --- rdist/common.c 22 Dec 2015 08:48:39 -0000 1.37
> +++ rdist/common.c 24 Jun 2016 01:48:13 -0000
> @@ -62,7 +62,6 @@ int isserver = FALSE; /* We're the ser
>  int     amchild = 0; /* This PID is a child */
>  int do_fork = 1; /* Fork child process */
>  char       *currenthost = NULL; /* Current client hostname */
> -char       *progname = NULL; /* Name of this program */
>  int rem_r = -1; /* Client file descriptor */
>  int rem_w = -1; /* Client file descriptor */
>  struct passwd       *pw = NULL; /* Local user's pwd entry */
> Index: rdist/defs.h
> ===================================================================
> RCS file: /cvs/src/usr.bin/rdist/defs.h,v
> retrieving revision 1.36
> diff -u -p -r1.36 defs.h
> --- rdist/defs.h 21 Jan 2015 03:05:03 -0000 1.36
> +++ rdist/defs.h 24 Jun 2016 01:48:18 -0000
> @@ -156,7 +156,6 @@
>  
>  
>  extern char       *currenthost; /* Name of current host */
> -extern char       *progname; /* Name of this program */
>  extern char       *locuser; /* Local User's name */
>  extern int debug; /* Debugging flag */
>  extern int isserver; /* Acting as remote server */
> Index: rdist/message.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rdist/message.c,v
> retrieving revision 1.28
> diff -u -p -r1.28 message.c
> --- rdist/message.c 30 Mar 2016 20:51:59 -0000 1.28
> +++ rdist/message.c 24 Jun 2016 01:48:30 -0000
> @@ -251,7 +251,7 @@ setmsgtypes(struct msgfacility *msgfac,
>   break;
>  
>   case MF_SYSLOG:
> - openlog(progname, LOG_PID, LOG_DAEMON);
> + openlog("rdist", LOG_PID, LOG_DAEMON);
>   break;
>   }
>  
> Index: rdist/rdist.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rdist/rdist.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 rdist.c
> --- rdist/rdist.c 8 Feb 2015 23:40:34 -0000 1.30
> +++ rdist/rdist.c 24 Jun 2016 01:48:55 -0000
> @@ -87,7 +87,6 @@ addhostlist(char *name, struct namelist
>  int
>  main(int argc, char **argv, char **envp)
>  {
> - extern char *__progname;
>   struct namelist *hostlist = NULL;
>   char *distfile = NULL;
>   char *cp;
> @@ -95,8 +94,6 @@ main(int argc, char **argv, char **envp)
>   int c;
>   const char *errstr;
>  
> - progname = __progname;
> -
>   if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) {
>   error("Bad builtin log option (%s): %s.",
>        localmsglist, cp);
> @@ -334,16 +331,15 @@ opendist(char *distfile)
>  static void
>  usage(void)
>  {
> - extern char *__progname;
>  
>   (void) fprintf(stderr,
> - "usage: %s [-DFnV] [-A num] [-a num] "
> + "usage: rdist [-DFnV] [-A num] [-a num] "
>   "[-c mini_distfile]\n"
>   "\t[-d var=value] [-f distfile] [-L remote_logopts] "
>   "[-l local_logopts]\n"
>   "\t[-M maxproc] [-m host] [-o distopts] [-P rsh-path] "
>   "[-p rdistd-path]\n"
> - "\t[-t timeout] [name ...]\n", __progname);
> + "\t[-t timeout] [name ...]\n");
>  
>  
>   (void) fprintf(stderr, "\nThe values for <distopts> are:\n\t%s\n",
> Index: rev/rev.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rev/rev.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 rev.c
> --- rev/rev.c 10 Apr 2016 17:06:52 -0000 1.13
> +++ rev/rev.c 24 Jun 2016 01:51:17 -0000
> @@ -110,8 +110,7 @@ isu8cont(unsigned char c)
>  void
>  usage(void)
>  {
> - extern char *__progname;
>  
> - (void)fprintf(stderr, "usage: %s [file ...]\n", __progname);
> + fprintf(stderr, "usage: rev [file ...]\n");
>   exit(1);
>  }
> Index: rs/rs.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rs/rs.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 rs.c
> --- rs/rs.c 3 Dec 2015 12:23:15 -0000 1.30
> +++ rs/rs.c 24 Jun 2016 01:50:10 -0000
> @@ -227,11 +227,9 @@ prints(struct entry *ep, int col)
>  void
>  usage(void)
>  {
> - extern char *__progname;
>  
>   fprintf(stderr,
> -    "usage: %s [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]\n",
> -    __progname);
> +    "usage: rs [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]\n");
>   exit(1);
>  }
>  
> Index: rwall/rwall.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rwall/rwall.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 rwall.c
> --- rwall/rwall.c 16 Jan 2015 06:40:11 -0000 1.13
> +++ rwall/rwall.c 24 Jun 2016 01:50:30 -0000
> @@ -59,12 +59,11 @@ void makemsg(char *);
>  int
>  main(int argc, char *argv[])
>  {
> - extern char *__progname;
>   char *wallhost, res;
>   CLIENT *cl;
>  
>   if ((argc < 2) || (argc > 3)) {
> - fprintf(stderr, "usage: %s host [file]\n", __progname);
> + fprintf(stderr, "usage: rwall host [file]\n");
>   exit(1);
>   }
>  
>
>

Reply | Threaded
Open this post in threaded view
|

Re: less progname in r

Ted Unangst-6
Mark Kettenis wrote:

> > From: "Ted Unangst" <[hidden email]>
> > Date: Thu, 23 Jun 2016 21:57:00 -0400
> >
> > These programs don't do anything interesting based on progname,
> > except to echo is back to the user. If the user creates a link, is
> > it somehow more correct to print that name? I'd argue the original
> > name is better (especially in usage) because then you have a hint
> > what man page to read.
>
> Using __progname in this context has been the standard on *BSD for a
> long time.  This really feels like unnecessary churn to me.

Yes, although I think it's kind of mindless copying. This code doesn't benefit
from progname. (Code that inspects argv[0] does benefit.)

I doubt porting these programs is a high priority for anyone, but nevertheless
I prefer standard code over nonstandard code.

That said, it is kind of noise.

Reply | Threaded
Open this post in threaded view
|

Re: less progname in r

Todd C. Miller
On Fri, 24 Jun 2016 16:52:24 -0400, "Ted Unangst" wrote:

> Yes, although I think it's kind of mindless copying. This code doesn't
> benefit from progname. (Code that inspects argv[0] does benefit.)
>
> I doubt porting these programs is a high priority for anyone, but
> nevertheles I prefer standard code over nonstandard code.
>
> That said, it is kind of noise.

And you just know that if this is committed there will be a diff
from someone else in a year or so to use getprogname() instead of
hard-coding the value.

 - todd

Reply | Threaded
Open this post in threaded view
|

Re: less progname in r

Theo de Raadt
> > Yes, although I think it's kind of mindless copying. This code doesn't
> > benefit from progname. (Code that inspects argv[0] does benefit.)
> >
> > I doubt porting these programs is a high priority for anyone, but
> > nevertheles I prefer standard code over nonstandard code.
> >
> > That said, it is kind of noise.
>
> And you just know that if this is committed there will be a diff
> from someone else in a year or so to use getprogname() instead of
> hard-coding the value.

I actually dislike how these programs behave when linked to.  It is
rare.  But it feels misleading somehow.

Reply | Threaded
Open this post in threaded view
|

Re: less progname in r

Ted Unangst-6
Theo de Raadt wrote:
>
> I actually dislike how these programs behave when linked to.  It is
> rare.  But it feels misleading somehow.

Yes, I mentioned this in passing. It's somewhat contrived, but here's an
example.

$ cp /bin/ls ~/bin/ld
$ ld -X
ld: unknown option -- X
usage: ld [-1AaCcdFfgHhikLlmnopqRrSsTtux] [file ...]

Now I read 'man ld' and woah...

On the one hand, obviously stupid idea to copy one command and give it another
name, but the way we accomodate this misuse makes the problem worse. Sometimes
these things happen by accident. If "ld" told me its name was "ls" that would
give me a hint about how to correct the problem and I'd remember that time I
fat fingered s/d.