[email protected] (Jeremie Courreges-Anglas) writes:

> I have a diff to move rtadvd to libevent, but first there's a bunch of
> ugly stuff I'd like to get rid of.

Committed with input from Florian, except

> - pointless casts, kill caddr_t or replace it with char *
> - signed counters
> - extra newline due to ctime(3) in rtadvd_dump

this detail.  Florian as concerned about what would be returned by
ctime_r(3) eg for years > 9999.  Here another diff that ignores the
problem with years > 9999 and keeps using ctime(3).

ok?

Index: dump.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/dump.c,v
retrieving revision 1.20
diff -u -p -r1.20 dump.c
--- dump.c      29 Jun 2016 14:19:38 -0000      1.20
+++ dump.c      29 Jun 2016 14:27:03 -0000
@@ -111,6 +111,7 @@ rtadvd_dump(void)
        struct timeval now;
        char *origin, *vltime, *pltime, *flags;
        char *vltimexpire=NULL, *pltimexpire=NULL;
+       char ctimebuf[26];
 
        gettimeofday(&now, NULL);
        SLIST_FOREACH(rai, &ralist, entry) {
@@ -122,12 +123,15 @@ rtadvd_dump(void)
                /* control information */
                if (rai->lastsent.tv_sec) {
                        time_t t = rai->lastsent.tv_sec;
-                       /* note that ctime() appends CR by itself */
-                       log_info("  Last RA sent: %s", ctime(&t));
+                       (void)strlcpy(ctimebuf, ctime(&t), sizeof(ctimebuf));
+                       ctimebuf[strcspn(ctimebuf, "\n")] = '\0';
+                       log_info("  Last RA sent: %s", ctimebuf);
                }
                if (rai->timer) {
                        time_t t = rai->timer->tm.tv_sec;
-                       log_info("  Next RA will be sent: %s", ctime(&t));
+                       (void)strlcpy(ctimebuf, ctime(&t), sizeof(ctimebuf));
+                       ctimebuf[strcspn(ctimebuf, "\n")] = '\0';
+                       log_info("  Next RA will be sent: %s", ctimebuf);
                } else
                        log_info("  RA timer is stopped");
                log_info("  waits: %u, initcount: %u",


-- 
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to