aboutsummaryrefslogtreecommitdiff
path: root/ntpd/refclock_chronolog.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpd/refclock_chronolog.c')
-rw-r--r--ntpd/refclock_chronolog.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/ntpd/refclock_chronolog.c b/ntpd/refclock_chronolog.c
index a1d131ec0304..ba4f60b4ed62 100644
--- a/ntpd/refclock_chronolog.c
+++ b/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,7 +104,7 @@ 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);
@@ -115,12 +115,8 @@ chronolog_start(
/*
* 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(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = chronolog_receive;
@@ -128,8 +124,10 @@ chronolog_start(
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);
}
@@ -157,8 +155,10 @@ chronolog_shutdown(
pp = peer->procptr;
up = (struct chronolog_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
@@ -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;