diff options
author | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
commit | 2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch) | |
tree | b0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/ntpd/refclock_chronolog.c | |
parent | a0741a75537b2e0514472ac3b28afc55a7846c30 (diff) | |
download | FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz |
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435:
ntp 4.2.8p3.
Relnotes: yes
Approved by: re (?)
Diffstat (limited to 'contrib/ntp/ntpd/refclock_chronolog.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_chronolog.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/contrib/ntp/ntpd/refclock_chronolog.c b/contrib/ntp/ntpd/refclock_chronolog.c index a1d131e..ee54b43 100644 --- a/contrib/ntp/ntpd/refclock_chronolog.c +++ b/contrib/ntp/ntpd/refclock_chronolog.c @@ -67,10 +67,10 @@ struct chronolog_unit { /* * Function prototypes */ -static int chronolog_start P((int, struct peer *)); -static void chronolog_shutdown P((int, struct peer *)); -static void chronolog_receive P((struct recvbuf *)); -static void chronolog_poll P((int, struct peer *)); +static int chronolog_start (int, struct peer *); +static void chronolog_shutdown (int, struct peer *); +static void chronolog_receive (struct recvbuf *); +static void chronolog_poll (int, struct peer *); /* * Transfer vector @@ -104,32 +104,30 @@ chronolog_start( * Open serial port. Don't bother with CLK line discipline, since * it's not available. */ - (void)sprintf(device, DEVICE, unit); + snprintf(device, sizeof(device), DEVICE, unit); #ifdef DEBUG if (debug) printf ("starting Chronolog with device %s\n",device); #endif - if (!(fd = refclock_open(device, SPEED232, 0))) + fd = refclock_open(device, SPEED232, 0); + if (fd <= 0) return (0); /* * Allocate and initialize unit structure */ - if (!(up = (struct chronolog_unit *) - emalloc(sizeof(struct chronolog_unit)))) { - (void) close(fd); - return (0); - } - memset((char *)up, 0, sizeof(struct chronolog_unit)); + up = emalloc_zero(sizeof(*up)); pp = peer->procptr; - pp->unitptr = (caddr_t)up; + pp->unitptr = up; pp->io.clock_recv = chronolog_receive; - pp->io.srcclock = (caddr_t)peer; + pp->io.srcclock = peer; pp->io.datalen = 0; pp->io.fd = fd; if (!io_addclock(&pp->io)) { - (void) close(fd); + close(fd); + pp->io.fd = -1; free(up); + pp->unitptr = NULL; return (0); } @@ -156,9 +154,11 @@ chronolog_shutdown( struct refclockproc *pp; pp = peer->procptr; - up = (struct chronolog_unit *)pp->unitptr; - io_closeclock(&pp->io); - free(up); + up = pp->unitptr; + if (-1 != pp->io.fd) + io_closeclock(&pp->io); + if (NULL != up) + free(up); } @@ -184,9 +184,9 @@ chronolog_receive( /* * Initialize pointers and read the timecode and timestamp */ - peer = (struct peer *)rbufp->recv_srcclock; + peer = rbufp->recv_peer; pp = peer->procptr; - up = (struct chronolog_unit *)pp->unitptr; + up = pp->unitptr; temp = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &trtmp); if (temp == 0) { @@ -240,6 +240,8 @@ chronolog_receive( * otherwise, we get the time wrong. */ + memset(&local, 0, sizeof(local)); + local.tm_year = up->year; local.tm_mon = up->month-1; local.tm_mday = up->day; @@ -295,7 +297,7 @@ chronolog_receive( pp->lastref = pp->lastrec; refclock_receive(peer); record_clock_stats(&peer->srcadr, pp->a_lastcode); - up->lasthour = pp->hour; + up->lasthour = (u_char)pp->hour; } @@ -322,7 +324,7 @@ chronolog_poll( char pollchar; pp = peer->procptr; - up = (struct chronolog_unit *)pp->unitptr; + up = pp->unitptr; if (peer->burst == 0 && peer->reach == 0) refclock_report(peer, CEVNT_TIMEOUT); if (up->linect > 0) |