diff options
author | Rainer Giedat <rainer@cvs.openbsd.org> | 2008-06-08 21:08:58 +0000 |
---|---|---|
committer | Rainer Giedat <rainer@cvs.openbsd.org> | 2008-06-08 21:08:58 +0000 |
commit | 92c9e8a49cc4e796de7bcd524a64a3173cbe29e9 (patch) | |
tree | 7e3259ae97ba69bd5af641b6cfad26d1f94bfb13 /usr.sbin | |
parent | 21683dff667775a17c1fdc1aae7a320c12a1521f (diff) |
Send debug output to syslog instead of a file when receiving SIGUSR1.
This is a preparation for dropping privileges.
ok henning@, pyr@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rtadvd/dump.c | 162 | ||||
-rw-r--r-- | usr.sbin/rtadvd/dump.h | 4 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.8 | 13 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.c | 11 |
4 files changed, 92 insertions, 98 deletions
diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c index 2c06a58fa0c..b2f94bff7f8 100644 --- a/usr.sbin/rtadvd/dump.c +++ b/usr.sbin/rtadvd/dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.c,v 1.8 2008/04/23 10:17:50 pyr Exp $ */ +/* $OpenBSD: dump.c,v 1.9 2008/06/08 21:08:57 rainer Exp $ */ /* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */ /* @@ -47,6 +47,7 @@ #include <time.h> #include <stdio.h> #include <stdarg.h> +#include <stdlib.h> #include <string.h> #include <errno.h> #include <netdb.h> @@ -54,15 +55,12 @@ #include "rtadvd.h" #include "timer.h" #include "if.h" -#include "dump.h" #include "log.h" - -static FILE *fp; +#include "dump.h" extern struct ralist ralist; static char *ether_str(struct sockaddr_dl *); -static void if_dump(void); static char *rtpref_str[] = { "medium", /* 00 */ @@ -88,130 +86,132 @@ ether_str(sdl) return(hbuf); } -static void -if_dump() +char* +lifetime(int lt) +{ + char *str; + + if (lt == ND6_INFINITE_LIFETIME) + asprintf(&str, "infinity"); + else + asprintf(&str, "%ld", (long)lt); + return str; +} + +void +rtadvd_dump() { struct rainfo *rai; struct prefix *pfx; char prefixbuf[INET6_ADDRSTRLEN]; int first; struct timeval now; + char *origin, *vltime, *pltime, *flags; + char *vltimexpire=NULL, *pltimexpire=NULL; gettimeofday(&now, NULL); /* XXX: unused in most cases */ SLIST_FOREACH(rai, &ralist, entry) { - fprintf(fp, "%s:\n", rai->ifname); + log_info("%s:", rai->ifname); - fprintf(fp, " Status: %s\n", - (iflist[rai->ifindex]->ifm_flags & IFF_UP) ? "UP" : - "DOWN"); + log_info(" Status: %s", + (iflist[rai->ifindex]->ifm_flags & IFF_UP) ? "UP" : "DOWN"); /* control information */ if (rai->lastsent.tv_sec) { /* note that ctime() appends CR by itself */ - fprintf(fp, " Last RA sent: %s", - ctime((time_t *)&rai->lastsent.tv_sec)); + log_info(" Last RA sent: %s", + ctime((time_t *)&rai->lastsent.tv_sec)); + } if (rai->timer) { - fprintf(fp, " Next RA will be sent: %s", - ctime((time_t *)&rai->timer->tm.tv_sec)); + log_info(" Next RA will be sent: %s", + ctime((time_t *)&rai->timer->tm.tv_sec)); + } else - fprintf(fp, " RA timer is stopped"); - fprintf(fp, " waits: %d, initcount: %d\n", + log_info(" RA timer is stopped"); + log_info(" waits: %d, initcount: %d", + rai->waiting, rai->initcounter); /* statistics */ - fprintf(fp, " statistics: RA(out/in/inconsistent): " - "%llu/%llu/%llu, ", + log_info(" statistics: RA(out/in/inconsistent): " + "%llu/%llu/%llu, RS(input): %llu", (unsigned long long)rai->raoutput, (unsigned long long)rai->rainput, - (unsigned long long)rai->rainconsistent); - fprintf(fp, "RS(input): %llu\n", + (unsigned long long)rai->rainconsistent, (unsigned long long)rai->rsinput); /* interface information */ if (rai->advlinkopt) - fprintf(fp, " Link-layer address: %s\n", + log_info(" Link-layer address: %s", ether_str(rai->sdl)); - fprintf(fp, " MTU: %d\n", rai->phymtu); + log_info(" MTU: %d", rai->phymtu); /* Router configuration variables */ - fprintf(fp, " DefaultLifetime: %d, MaxAdvInterval: %d, " - "MinAdvInterval: %d\n", rai->lifetime, rai->maxinterval, - rai->mininterval); - fprintf(fp, " Flags: %s%s%s, ", + log_info(" DefaultLifetime: %d, MaxAdvInterval: %d, " + "MinAdvInterval: %d" + "Flags: %s%s, Preference: %s, MTU: %d", + rai->lifetime, rai->maxinterval, rai->mininterval, rai->managedflg ? "M" : "", rai->otherflg ? "O" : "", - ""); - fprintf(fp, "Preference: %s, ", - rtpref_str[(rai->rtpref >> 3) & 0xff]); - fprintf(fp, "MTU: %d\n", rai->linkmtu); - fprintf(fp, " ReachableTime: %d, RetransTimer: %d, " - "CurHopLimit: %d\n", rai->reachabletime, - rai->retranstimer, rai->hoplimit); + rtpref_str[(rai->rtpref >> 3) & 0xff], rai->linkmtu); + log_info(" ReachableTime: %d, RetransTimer: %d, " + "CurHopLimit: %d", rai->reachabletime, + rai->retranstimer, rai->hoplimit); if (rai->clockskew) - fprintf(fp, " Clock skew: %ldsec\n", + log_info(" Clock skew: %ldsec", rai->clockskew); first = 1; TAILQ_FOREACH(pfx, &rai->prefixes, entry) { if (first) { - fprintf(fp, " Prefixes:\n"); + log_info(" Prefixes:"); first = 0; } - fprintf(fp, " %s/%d(", - inet_ntop(AF_INET6, &pfx->prefix, prefixbuf, - sizeof(prefixbuf)), pfx->prefixlen); switch (pfx->origin) { case PREFIX_FROM_KERNEL: - fprintf(fp, "KERNEL, "); + origin = "KERNEL"; break; case PREFIX_FROM_CONFIG: - fprintf(fp, "CONFIG, "); + origin = "CONFIG"; break; case PREFIX_FROM_DYNAMIC: - fprintf(fp, "DYNAMIC, "); + origin = "DYNAMIC"; break; + default: + origin = ""; } - if (pfx->validlifetime == ND6_INFINITE_LIFETIME) - fprintf(fp, "vltime: infinity"); - else - fprintf(fp, "vltime: %ld", - (long)pfx->validlifetime); if (pfx->vltimeexpire != 0) - fprintf(fp, "(decr,expire %ld), ", (long) - pfx->vltimeexpire > now.tv_sec ? - pfx->vltimeexpire - now.tv_sec : 0); - else - fprintf(fp, ", "); - if (pfx->preflifetime == ND6_INFINITE_LIFETIME) - fprintf(fp, "pltime: infinity"); - else - fprintf(fp, "pltime: %ld", - (long)pfx->preflifetime); + asprintf(&vltimexpire, "(decr,expire %ld)", (long) + pfx->vltimeexpire > now.tv_sec ? + pfx->vltimeexpire - now.tv_sec : 0); if (pfx->pltimeexpire != 0) - fprintf(fp, "(decr,expire %ld), ", (long) - pfx->pltimeexpire > now.tv_sec ? - pfx->pltimeexpire - now.tv_sec : 0); - else - fprintf(fp, ", "); - fprintf(fp, "flags: %s%s%s", - pfx->onlinkflg ? "L" : "", - pfx->autoconfflg ? "A" : "", - ""); - fprintf(fp, ")\n"); - } - } -} + asprintf(&pltimexpire, "(decr,expire %ld)", (long) + pfx->pltimeexpire > now.tv_sec ? + pfx->pltimeexpire - now.tv_sec : 0); + + vltime = lifetime(pfx->validlifetime); + pltime = lifetime(pfx->preflifetime); + asprintf(&flags, "%s%s", + pfx->onlinkflg ? "L" : "", + pfx->autoconfflg ? "A" : ""); + log_info(" %s/%d(%s, vltime: %s%s, " + "pltime: %s%s, flags: %s)", + inet_ntop(AF_INET6, &pfx->prefix, prefixbuf, + sizeof(prefixbuf)), pfx->prefixlen, origin, + vltime, (vltimexpire)? vltimexpire : "", + pltime, (pltimexpire)? pltimexpire : "", flags); -void -rtadvd_dump_file(dumpfile) - char *dumpfile; -{ - if ((fp = fopen(dumpfile, "w")) == NULL) { - log_warn("open a dump file(%s)", dumpfile); - return; + if (vltimexpire) { + free(vltimexpire); + vltimexpire = NULL; + } + if (pltimexpire) { + free(pltimexpire); + pltimexpire = NULL; + } + free(vltime); + free(pltime); + free(flags); + } } - - if_dump(); - - fclose(fp); } diff --git a/usr.sbin/rtadvd/dump.h b/usr.sbin/rtadvd/dump.h index 41a31d93ed3..8a0e001c7dc 100644 --- a/usr.sbin/rtadvd/dump.h +++ b/usr.sbin/rtadvd/dump.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.h,v 1.2 2002/02/16 21:28:08 millert Exp $ */ +/* $OpenBSD: dump.h,v 1.3 2008/06/08 21:08:57 rainer Exp $ */ /* $KAME: dump.h,v 1.1 2000/05/23 11:31:26 itojun Exp $ */ /* @@ -30,4 +30,4 @@ * SUCH DAMAGE. */ -extern void rtadvd_dump_file(char *); +void rtadvd_dump(); diff --git a/usr.sbin/rtadvd/rtadvd.8 b/usr.sbin/rtadvd/rtadvd.8 index 0f3f1890866..e4b532e13cd 100644 --- a/usr.sbin/rtadvd/rtadvd.8 +++ b/usr.sbin/rtadvd/rtadvd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rtadvd.8,v 1.25 2008/04/22 05:04:07 jmc Exp $ +.\" $OpenBSD: rtadvd.8,v 1.26 2008/06/08 21:08:57 rainer Exp $ .\" $KAME: rtadvd.8,v 1.18 2002/04/28 10:43:02 jinmei Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: April 22 2008 $ +.Dd $Mdocdate: June 8 2008 $ .Dt RTADVD 8 .Os .Sh NAME @@ -133,8 +133,7 @@ Only statically configured prefixes, if any, will be advertised. Upon receipt of signal .Dv SIGUSR1 , .Nm -will dump the current internal state into -.Pa /var/run/rtadvd.dump . +will dump the current internal state into syslog. .Pp Use .Dv SIGTERM @@ -149,16 +148,12 @@ to all the interfaces .Pp .Ex -std rtadvd .Sh FILES -.Bl -tag -width "/var/run/rtadvd.dumpXX" -compact +.Bl -tag -width "/var/run/rtadvd.pidXX" -compact .It Pa /etc/rtadvd.conf The default configuration file. .It Pa /var/run/rtadvd.pid Contains the PID of the currently running .Nm . -.It Pa /var/run/rtadvd.dump -The file in which -.Nm -dumps its internal state. .El .Sh SEE ALSO .Xr rtadvd.conf 5 , diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index 74f8a5b646b..1e1f4829438 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtadvd.c,v 1.34 2008/05/02 04:28:51 pyr Exp $ */ +/* $OpenBSD: rtadvd.c,v 1.35 2008/06/08 21:08:57 rainer Exp $ */ /* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */ /* @@ -78,7 +78,6 @@ struct iovec sndiov[2]; struct sockaddr_in6 from; struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6}; struct in6_addr in6a_site_allrouters; -static char *dumpfilename = "/var/run/rtadvd.dump"; /* XXX: should be configurable */ static char *mcastif; int sock; int rtsock = -1; @@ -142,7 +141,7 @@ static int nd6_options(struct nd_opt_hdr *, int, static void free_ndopts(union nd_opts *); static void ra_output(struct rainfo *); static void rtmsg_input(void); -static void rtadvd_set_dump_file(int); +static void rtadvd_set_dump(int); int main(argc, argv) @@ -243,14 +242,14 @@ main(argc, argv) FD_SET(rtsock, fdsetp); signal(SIGTERM, set_die); - signal(SIGUSR1, rtadvd_set_dump_file); + signal(SIGUSR1, rtadvd_set_dump); while (1) { memcpy(selectfdp, fdsetp, fdmasks); /* reinitialize */ if (do_dump) { /* SIGUSR1 */ do_dump = 0; - rtadvd_dump_file(dumpfilename); + rtadvd_dump(); } if (do_die) { @@ -287,7 +286,7 @@ main(argc, argv) } static void -rtadvd_set_dump_file(int signo) +rtadvd_set_dump(int signo) { do_dump = 1; } |