Discussion:
rtadvd usage()
Jérémie Courrèges-Anglas
2016-02-04 13:02:46 UTC
Permalink
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
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Alexander Bluhm
2016-02-04 13:36:25 UTC
Permalink
Post by Jérémie Courrèges-Anglas
+static void usage(void);
Can you make the usage static __dead void?
Post by Jérémie Courrèges-Anglas
+#define OPTIONS ":c:ds"
Our other daemons don't have a leading ':', why to be special here?
Post by Jérémie Courrèges-Anglas
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
This OPTIONS define looks quite useless. Why not put the string here?

anyway, OK bluhm@
Florian Obser
2016-02-04 14:13:51 UTC
Permalink
Post by Alexander Bluhm
Post by Jérémie Courrèges-Anglas
+static void usage(void);
Can you make the usage static __dead void?
Post by Jérémie Courrèges-Anglas
+#define OPTIONS ":c:ds"
Our other daemons don't have a leading ':', why to be special here?
Post by Jérémie Courrèges-Anglas
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
This OPTIONS define looks quite useless. Why not put the string here?
--
I'm not entirely sure you are real.
Jérémie Courrèges-Anglas
2016-02-05 12:26:02 UTC
Permalink
Post by Alexander Bluhm
Post by Jérémie Courrèges-Anglas
+static void usage(void);
Can you make the usage static __dead void?
gsoares made the same comment, there are other functions that could be
marked __dead and I initially wanted to do them in one pass.
Post by Alexander Bluhm
Post by Jérémie Courrèges-Anglas
+#define OPTIONS ":c:ds"
Our other daemons don't have a leading ':', why to be special here?
No good reason, just an old habit. I have removed it.
Post by Alexander Bluhm
Post by Jérémie Courrèges-Anglas
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
This OPTIONS define looks quite useless. Why not put the string here?
Indeed, fixed.

The diff below adds __dead to relevant function decls and tidies up
log.h a bit.

ok?

Index: log.h
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/log.h,v
retrieving revision 1.1
diff -u -p -r1.1 log.h
--- log.h 21 Apr 2008 20:40:55 -0000 1.1
+++ log.h 5 Feb 2016 12:22:39 -0000
@@ -19,10 +19,10 @@
void log_init(int);
void logit(int pri, const char *fmt, ...);

-void fatal(const char*);
+__dead void fatal(const char*);
+__dead void fatalx(const char*);
+
void log_warn(const char*, ...) __attribute__((format(printf, 1, 2)));
+void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2)));
void log_info(const char*, ...) __attribute__((format(printf, 1, 2)));
void log_debug(const char*, ...) __attribute__((format(printf, 1, 2)));
-
-void fatalx(const char*);
-void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2)));
Index: rtadvd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.63
diff -u -p -r1.63 rtadvd.c
--- rtadvd.c 5 Feb 2016 12:16:21 -0000 1.63
+++ rtadvd.c 5 Feb 2016 12:22:39 -0000
@@ -132,7 +132,7 @@ u_int32_t ndopt_flags[] = {

static __dead void usage(void);
static void set_die(int);
-static void die(void);
+static __dead void die(void);
static void sock_open(void);
static void rtsock_open(void);
static void rtadvd_input(void);
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Alexander Bluhm
2016-02-05 13:43:42 UTC
Permalink
Post by Jérémie Courrèges-Anglas
The diff below adds __dead to relevant function decls and tidies up
log.h a bit.
ok?
Index: log.h
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/log.h,v
retrieving revision 1.1
diff -u -p -r1.1 log.h
--- log.h 21 Apr 2008 20:40:55 -0000 1.1
+++ log.h 5 Feb 2016 12:22:39 -0000
@@ -19,10 +19,10 @@
void log_init(int);
void logit(int pri, const char *fmt, ...);
-void fatal(const char*);
+__dead void fatal(const char*);
+__dead void fatalx(const char*);
+
void log_warn(const char*, ...) __attribute__((format(printf, 1, 2)));
+void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2)));
void log_info(const char*, ...) __attribute__((format(printf, 1, 2)));
void log_debug(const char*, ...) __attribute__((format(printf, 1, 2)));
-
-void fatalx(const char*);
-void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2)));
Index: rtadvd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.63
diff -u -p -r1.63 rtadvd.c
--- rtadvd.c 5 Feb 2016 12:16:21 -0000 1.63
+++ rtadvd.c 5 Feb 2016 12:22:39 -0000
@@ -132,7 +132,7 @@ u_int32_t ndopt_flags[] = {
static __dead void usage(void);
static void set_die(int);
-static void die(void);
+static __dead void die(void);
static void sock_open(void);
static void rtsock_open(void);
static void rtadvd_input(void);
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Loading...