npppd(8): sync option parsing with other userland utils

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

npppd(8): sync option parsing with other userland utils

Benjamin Baier
Hello tech@

This patch brings npppd(8)'s option parsing in sync with all the other userland
utils that don't recognize -h for help/usage (except for some games, still).

Also exit(3) at the end of the usage() function and mark it as __dead.

Greetings Ben

Index: npppd/npppd.8
===================================================================
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd.8,v
retrieving revision 1.5
diff -u -p -r1.5 npppd.8
--- npppd/npppd.8 29 Jan 2013 15:42:20 -0000 1.5
+++ npppd/npppd.8 8 Nov 2015 20:30:35 -0000
@@ -23,7 +23,7 @@
 .Nd new Point-to-Point Protocol daemon
 .Sh SYNOPSIS
 .Nm npppd
-.Op Fl dhn
+.Op Fl dn
 .Op Fl f Ar config_file
 .Sh DESCRIPTION
 .Nm
@@ -38,8 +38,6 @@ will run in the foreground and log to
 .Em stderr .
 .It Fl f Ar config_file
 Specify an alternative configuration file.
-.It Fl h
-Show the usage.
 .It Fl n
 Configtest mode.
 Only check the configuration file for validity.
Index: npppd/npppd.c
===================================================================
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd.c,v
retrieving revision 1.41
diff -u -p -r1.41 npppd.c
--- npppd/npppd.c 24 Jun 2015 04:57:55 -0000 1.41
+++ npppd/npppd.c 8 Nov 2015 20:54:15 -0000
@@ -145,7 +145,7 @@ main(int argc, char *argv[])
  const char    *npppd_conf0 = DEFAULT_NPPPD_CONF;
  struct passwd *pw;

- while ((ch = getopt(argc, argv, "nf:dh")) != -1) {
+ while ((ch = getopt(argc, argv, "nf:d")) != -1) {
  switch (ch) {
  case 'n':
  nflag = 1;
@@ -157,17 +157,14 @@ main(int argc, char *argv[])
  debuglevel++;
  runasdaemon = 0;
  break;
- case '?':
- case 'h':
+ default:
  usage();
- exit(1);
  }
  }
  argc -= optind;
  argv += optind;
  if (argc != 0) {
  usage();
- exit(1);
  }
  if (nflag) {
  debuglevel++;
@@ -225,10 +222,11 @@ main(int argc, char *argv[])
  exit((!stop_by_error)? EXIT_SUCCESS : EXIT_FAILURE);
 }

-static void
-usage()
+static __dead void
+usage(void)
 {
- fprintf(stderr, "usage: npppd [-dhn] [-f config_file]\n");
+ fprintf(stderr, "usage: npppd [-dn] [-f config_file]\n");
+ exit(1);
 }

 /** Returns the singleton npppd instance */

Reply | Threaded
Open this post in threaded view
|

Re: npppd(8): sync option parsing with other userland utils

Ted Unangst-6
Benjamin Baier wrote:
> Hello tech@
>
> This patch brings npppd(8)'s option parsing in sync with all the other userland
> utils that don't recognize -h for help/usage (except for some games, still).
>
> Also exit(3) at the end of the usage() function and mark it as __dead.

This will change behavior (now printing "unknown option" in addition to the
usage) but I think that's ok. The -h option, as is, is not very useful since
the usage is so short.

Reply | Threaded
Open this post in threaded view
|

Re: npppd(8): sync option parsing with other userland utils

YASUOKA Masahiko-4
In reply to this post by Benjamin Baier
On Sun, 8 Nov 2015 22:20:33 +0100
Benjamin Baier <[hidden email]> wrote:
> This patch brings npppd(8)'s option parsing in sync with all the
> other userland  utils that don't recognize -h for help/usage (except
> for some games, still).
>
> Also exit(3) at the end of the usage() function and mark it as __dead.

Committed with some additional tweaks below.

Thanks,

--- npppd.c-bak Mon Nov  9 10:11:45 2015
+++ npppd.c Mon Nov  9 10:12:12 2015
@@ -98,7 +98,7 @@ static npppd s_npppd; /* singleton */
 static void         npppd_reload0 (npppd *);
 static void         npppd_update_pool_reference (npppd *);
 static int          npppd_rd_walktree_delete(struct radish_head *);
-static void         usage (void);
+static __dead void  usage (void);
 static void         npppd_stop_really (npppd *);
 static uint32_t     str_hash(const void *, int);
 static void         npppd_on_sighup (int, short, void *);
@@ -163,9 +163,8 @@ main(int argc, char *argv[])
  }
  argc -= optind;
  argv += optind;
- if (argc != 0) {
+ if (argc != 0)
  usage();
- }
  if (nflag) {
  debuglevel++;
  runasdaemon = 0;