Jérémie Courrèges-Anglas
2016-02-04 13:02:46 UTC
AFAIK none of our daemons ignore unknown options, I can't see why
rtadvd(8) should be special.
Bonus:
- main doesn't need to be declared
- rtadvd.c now uses poll(2), not select(2)
ok?
Index: rtadvd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.61
diff -u -p -r1.61 rtadvd.c
--- rtadvd.c 1 Dec 2015 12:11:31 -0000 1.61
+++ rtadvd.c 4 Feb 2016 13:02:10 -0000
@@ -130,7 +130,7 @@ u_int32_t ndopt_flags[] = {
[ND_OPT_DNSSL] = NDOPT_FLAG_DNSSL,
};
-int main(int, char *[]);
+static void usage(void);
static void set_die(int);
static void die(void);
static void sock_open(void);
@@ -162,7 +162,7 @@ main(int argc, char *argv[])
closefrom(3);
/* get command line options and arguments */
-#define OPTIONS "c:ds"
+#define OPTIONS ":c:ds"
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
#undef OPTIONS
switch (ch) {
@@ -175,16 +175,14 @@ main(int argc, char *argv[])
case 's':
sflag = 1;
break;
+ default:
+ usage();
}
}
argc -= optind;
argv += optind;
- if (argc == 0) {
- fprintf(stderr,
- "usage: rtadvd [-ds] [-c configfile] "
- "interface ...\n");
- exit(1);
- }
+ if (argc == 0)
+ usage();
SLIST_INIT(&ralist);
@@ -264,7 +262,7 @@ main(int argc, char *argv[])
timeout->tv_sec * 1000 + timeout->tv_usec / 1000)) < 0) {
/* EINTR would occur upon SIGUSR1 for status dump */
if (errno != EINTR)
- log_warn("select");
+ log_warn("poll");
continue;
}
if (i == 0) /* timeout */
@@ -275,6 +273,14 @@ main(int argc, char *argv[])
rtadvd_input();
}
exit(0); /* NOTREACHED */
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-ds] [-c configfile] interface ...\n",
+ getprogname());
+ exit(1);
}
static void
rtadvd(8) should be special.
Bonus:
- main doesn't need to be declared
- rtadvd.c now uses poll(2), not select(2)
ok?
Index: rtadvd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.61
diff -u -p -r1.61 rtadvd.c
--- rtadvd.c 1 Dec 2015 12:11:31 -0000 1.61
+++ rtadvd.c 4 Feb 2016 13:02:10 -0000
@@ -130,7 +130,7 @@ u_int32_t ndopt_flags[] = {
[ND_OPT_DNSSL] = NDOPT_FLAG_DNSSL,
};
-int main(int, char *[]);
+static void usage(void);
static void set_die(int);
static void die(void);
static void sock_open(void);
@@ -162,7 +162,7 @@ main(int argc, char *argv[])
closefrom(3);
/* get command line options and arguments */
-#define OPTIONS "c:ds"
+#define OPTIONS ":c:ds"
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
#undef OPTIONS
switch (ch) {
@@ -175,16 +175,14 @@ main(int argc, char *argv[])
case 's':
sflag = 1;
break;
+ default:
+ usage();
}
}
argc -= optind;
argv += optind;
- if (argc == 0) {
- fprintf(stderr,
- "usage: rtadvd [-ds] [-c configfile] "
- "interface ...\n");
- exit(1);
- }
+ if (argc == 0)
+ usage();
SLIST_INIT(&ralist);
@@ -264,7 +262,7 @@ main(int argc, char *argv[])
timeout->tv_sec * 1000 + timeout->tv_usec / 1000)) < 0) {
/* EINTR would occur upon SIGUSR1 for status dump */
if (errno != EINTR)
- log_warn("select");
+ log_warn("poll");
continue;
}
if (i == 0) /* timeout */
@@ -275,6 +273,14 @@ main(int argc, char *argv[])
rtadvd_input();
}
exit(0); /* NOTREACHED */
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-ds] [-c configfile] interface ...\n",
+ getprogname());
+ exit(1);
}
static void
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE