From 02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 1 Sep 2012 14:45:15 +0000 Subject: Rework all non-contributed files that use `struct timezone'. This structure is not part of POSIX. According to POSIX, gettimeofday() has the following prototype: int gettimeofday(struct timeval *restrict tp, void *restrict tzp); Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is not used). Remove dead error handling code. Also use NULL for a nul-pointer instead of integer 0. While there, change all pieces of code that only use tv_sec to use time(3), as this provides less overhead. --- usr.sbin/timed/timed/master.c | 32 ++++++++++++++++---------------- usr.sbin/timed/timed/measure.c | 6 +++--- usr.sbin/timed/timed/readmsg.c | 6 +++--- usr.sbin/timed/timed/slave.c | 28 ++++++++++++++-------------- usr.sbin/timed/timed/timed.c | 6 ++---- usr.sbin/timed/timedc/cmds.c | 2 +- 6 files changed, 39 insertions(+), 41 deletions(-) (limited to 'usr.sbin/timed') diff --git a/usr.sbin/timed/timed/master.c b/usr.sbin/timed/timed/master.c index a7d74ee..b64259b 100644 --- a/usr.sbin/timed/timed/master.c +++ b/usr.sbin/timed/timed/master.c @@ -85,7 +85,7 @@ master() if (ntp->status == MASTER) masterup(ntp); } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); pollingtime = ntime.tv_sec+3; if (justquit) polls = 0; @@ -96,14 +96,14 @@ master() * to update all timers. */ loop: - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); wait.tv_sec = pollingtime - ntime.tv_sec; if (wait.tv_sec < 0) wait.tv_sec = 0; wait.tv_usec = 0; msg = readmsg(TSP_ANY, ANYADDR, &wait, 0); if (!msg) { - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); if (ntime.tv_sec >= pollingtime) { pollingtime = ntime.tv_sec + SAMPLEINTVL; get_goodgroup(0); @@ -175,7 +175,7 @@ loop: } mchgdate(msg); - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); pollingtime = ntime.tv_sec + SAMPLEINTVL; break; @@ -203,7 +203,7 @@ loop: } mchgdate(msg); - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); pollingtime = ntime.tv_sec + SAMPLEINTVL; break; @@ -284,7 +284,7 @@ loop: * do not want to call synch() while waiting * to be killed! */ - (void)gettimeofday(&ntime, (struct timezone *)0); + (void)gettimeofday(&ntime, NULL); pollingtime = ntime.tv_sec + SAMPLEINTVL; break; @@ -354,7 +354,7 @@ mchgdate(msg) (void)strcpy(olddate, date()); /* adjust time for residence on the queue */ - (void)gettimeofday(&otime, 0); + (void)gettimeofday(&otime, NULL); adj_msg_time(msg,&otime); tmptv.tv_sec = msg->tsp_time.tv_sec; @@ -368,11 +368,11 @@ mchgdate(msg) synch(tvtomsround(ntime)); } else { utx.ut_type = OLD_TIME; - gettimeofday(&utx.ut_tv, NULL); + (void)gettimeofday(&utx.ut_tv, NULL); pututxline(&utx); (void)settimeofday(&tmptv, 0); utx.ut_type = NEW_TIME; - gettimeofday(&utx.ut_tv, NULL); + (void)gettimeofday(&utx.ut_tv, NULL); pututxline(&utx); spreadtime(); } @@ -396,7 +396,7 @@ synch(mydelta) if (slvcount > 0) { if (trace) fprintf(fd, "measurements starting at %s\n", date()); - (void)gettimeofday(&check, 0); + (void)gettimeofday(&check, NULL); for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) { if (htp->noanswer != 0) { measure_status = measure(500, 100, @@ -424,7 +424,7 @@ synch(mydelta) } else { htp->delta = measure_delta; } - (void)gettimeofday(&stop, 0); + (void)gettimeofday(&stop, NULL); timevalsub(&stop, &stop, &check); if (stop.tv_sec >= 1) { if (trace) @@ -437,7 +437,7 @@ synch(mydelta) if (0 != readmsg(TSP_TRACEON,ANYADDR, &wait,0)) traceon(); - (void)gettimeofday(&check, 0); + (void)gettimeofday(&check, NULL); } } if (trace) @@ -474,7 +474,7 @@ spreadtime() for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) { to.tsp_type = TSP_SETTIME; (void)strcpy(to.tsp_name, hostname); - (void)gettimeofday(&tmptv, 0); + (void)gettimeofday(&tmptv, NULL); to.tsp_time.tv_sec = tmptv.tv_sec; to.tsp_time.tv_usec = tmptv.tv_usec; answer = acksend(&to, &htp->addr, htp->name, @@ -732,7 +732,7 @@ masterup(net) * we do not tell them to start using our time, before we have * found a good master. */ - (void)gettimeofday(&net->slvwait, 0); + (void)gettimeofday(&net->slvwait, NULL); } void @@ -755,12 +755,12 @@ newslave(msg) * If we are stable, send our time to the slave. * Do not go crazy if the date has been changed. */ - (void)gettimeofday(&now, 0); + (void)gettimeofday(&now, NULL); if (now.tv_sec >= fromnet->slvwait.tv_sec+3 || now.tv_sec < fromnet->slvwait.tv_sec) { to.tsp_type = TSP_SETTIME; (void)strcpy(to.tsp_name, hostname); - (void)gettimeofday(&tmptv, 0); + (void)gettimeofday(&tmptv, NULL); to.tsp_time.tv_sec = tmptv.tv_sec; to.tsp_time.tv_usec = tmptv.tv_usec; answer = acksend(&to, &htp->addr, diff --git a/usr.sbin/timed/timed/measure.c b/usr.sbin/timed/timed/measure.c index 7f14e79..81ab7c4 100644 --- a/usr.sbin/timed/timed/measure.c +++ b/usr.sbin/timed/timed/measure.c @@ -128,7 +128,7 @@ measure(maxmsec, wmsec, hname, addr, print) FD_ZERO(&ready); - (void)gettimeofday(&tdone, 0); + (void)gettimeofday(&tdone, NULL); mstotvround(&tout, maxmsec); timevaladd(&tdone, &tout); /* when we give up */ @@ -136,7 +136,7 @@ measure(maxmsec, wmsec, hname, addr, print) rcvcount = 0; while (rcvcount < MSGS) { - (void)gettimeofday(&tcur, 0); + (void)gettimeofday(&tcur, NULL); /* * keep sending until we have sent the max @@ -173,7 +173,7 @@ measure(maxmsec, wmsec, hname, addr, print) FD_SET(sock_raw, &ready); count = select(sock_raw+1, &ready, (fd_set *)0, (fd_set *)0, &tout); - (void)gettimeofday(&tcur, (struct timezone *)0); + (void)gettimeofday(&tcur, NULL); if (count <= 0) break; diff --git a/usr.sbin/timed/timed/readmsg.c b/usr.sbin/timed/timed/readmsg.c index 9bbb3d7..aca2dbe 100644 --- a/usr.sbin/timed/timed/readmsg.c +++ b/usr.sbin/timed/timed/readmsg.c @@ -168,11 +168,11 @@ again: * right one, return it, otherwise insert it in the linked list. */ - (void)gettimeofday(&rtout, 0); + (void)gettimeofday(&rtout, NULL); timevaladd(&rtout, intvl); FD_ZERO(&ready); for (;;) { - (void)gettimeofday(&rtime, 0); + (void)gettimeofday(&rtime, NULL); timevalsub(&rwait, &rtout, &rtime); if (rwait.tv_sec < 0) rwait.tv_sec = rwait.tv_usec = 0; @@ -219,7 +219,7 @@ again: inet_ntoa(from.sin_addr)); continue; } - (void)gettimeofday(&from_when, (struct timezone *)0); + (void)gettimeofday(&from_when, NULL); bytehostorder(&msgin); if (msgin.tsp_vers > TSPVERSION) { diff --git a/usr.sbin/timed/timed/slave.c b/usr.sbin/timed/timed/slave.c index 9076d17..26e34f7 100644 --- a/usr.sbin/timed/timed/slave.c +++ b/usr.sbin/timed/timed/slave.c @@ -83,7 +83,7 @@ slave() refusetime = 0; adjtime = 0; - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; fastelection = ntime.tv_sec + FASTTOUT; if (justquit) @@ -103,7 +103,7 @@ slave() loop: get_goodgroup(0); - (void)gettimeofday(&ntime, (struct timezone *)0); + (void)gettimeofday(&ntime, NULL); if (ntime.tv_sec > electiontime) { if (trace) fprintf(fd, "election timer expired\n"); @@ -132,7 +132,7 @@ loop: makeslave(slavenet); /* prune extras */ setstatus(); } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); looktime = ntime.tv_sec + delay2; } if (ntime.tv_sec >= looptime) { @@ -153,7 +153,7 @@ loop: } } } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); looptime = ntime.tv_sec + delay2; } @@ -225,7 +225,7 @@ loop: * Otherwise the clocks can race until the loop * is found. */ - (void)gettimeofday(&otime, 0); + (void)gettimeofday(&otime, NULL); if (adjtime < otime.tv_sec) looptime -= (looptime-otime.tv_sec)/2 + 1; @@ -234,7 +234,7 @@ loop: seq = msg->tsp_seq; synch(tvtomsround(msg->tsp_time)); } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; fastelection = ntime.tv_sec + FASTTOUT; adjtime = ntime.tv_sec + SAMPLEINTVL*2; @@ -248,7 +248,7 @@ loop: seq = msg->tsp_seq; /* adjust time for residence on the queue */ - (void)gettimeofday(&otime, 0); + (void)gettimeofday(&otime, NULL); adj_msg_time(msg,&otime); /* * the following line is necessary due to syslog @@ -289,7 +289,7 @@ loop: if (status & MASTER) spreadtime(); } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; fastelection = ntime.tv_sec + FASTTOUT; @@ -327,7 +327,7 @@ loop: setstatus(); answerdelay(); xmit(TSP_SLAVEUP, 0, &from); - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; fastelection = ntime.tv_sec + FASTTOUT; refusetime = 0; @@ -336,7 +336,7 @@ loop: case TSP_MASTERREQ: if (fromnet->status != SLAVE) break; - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; break; @@ -381,7 +381,7 @@ loop: case TSP_ELECTION: if (fromnet->status == SLAVE) { - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); electiontime = ntime.tv_sec + delay2; fastelection = ntime.tv_sec + FASTTOUT; seq = 0; @@ -538,7 +538,7 @@ loop: electiontime = 0; } } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); looptime = ntime.tv_sec + FASTTOUT; } else { if (msg->tsp_hopcnt-- < 1) @@ -590,7 +590,7 @@ loop: (void)remmach(htp); } } - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); looptime = ntime.tv_sec + FASTTOUT; } break; @@ -660,7 +660,7 @@ schgdate(msg, newdate) msg->tsp_name, newdate); /* adjust time for residence on the queue */ - (void)gettimeofday(&otime, 0); + (void)gettimeofday(&otime, NULL); adj_msg_time(msg, &otime); to.tsp_type = TSP_SETDATEREQ; diff --git a/usr.sbin/timed/timed/timed.c b/usr.sbin/timed/timed/timed.c index 63d1a48..e3397a9 100644 --- a/usr.sbin/timed/timed/timed.c +++ b/usr.sbin/timed/timed/timed.c @@ -232,7 +232,7 @@ main(argc, argv) } /* choose a unique seed for random number generation */ - (void)gettimeofday(&ntime, 0); + (void)gettimeofday(&ntime, NULL); srandom(ntime.tv_sec + ntime.tv_usec); sequence = random(); /* initial seq number */ @@ -701,11 +701,9 @@ casual(inf, sup) char * date() { - struct timeval tv; time_t tv_sec; - (void)gettimeofday(&tv, (struct timezone *)0); - tv_sec = tv.tv_sec; + tv_sec = time(NULL); return (ctime(&tv_sec)); } diff --git a/usr.sbin/timed/timedc/cmds.c b/usr.sbin/timed/timedc/cmds.c index b778b1a..84740f6 100644 --- a/usr.sbin/timed/timedc/cmds.c +++ b/usr.sbin/timed/timedc/cmds.c @@ -131,7 +131,7 @@ daydiff(hostname) } sec -= BU; - (void)gettimeofday(&now, (struct timezone*)0); + (void)gettimeofday(&now, NULL); return (sec - now.tv_sec); } } -- cgit v1.1