summaryrefslogtreecommitdiffstats
path: root/ntpd/refclock_gpsvme.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpd/refclock_gpsvme.c')
-rw-r--r--ntpd/refclock_gpsvme.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/ntpd/refclock_gpsvme.c b/ntpd/refclock_gpsvme.c
index 9f9e85c..c3322fd 100644
--- a/ntpd/refclock_gpsvme.c
+++ b/ntpd/refclock_gpsvme.c
@@ -104,13 +104,9 @@ psc_start(
return 0;
}
- if (!up) {
- msyslog(LOG_ERR, "psc_start: unit: %d, emalloc: %m", unit);
- return 0;
- }
memset(up, '\0', sizeof *up);
- sprintf(buf, DEVICE, unit); /* dev file name */
+ snprintf(buf, sizeof(buf), DEVICE, unit); /* dev file name */
fd[unit] = open(buf, O_RDONLY); /* open device file */
if (fd[unit] < 0) {
msyslog(LOG_ERR, "psc_start: unit: %d, open failed. %m", unit);
@@ -131,7 +127,7 @@ psc_start(
pp->io.fd = -1;
pp->unitptr = (caddr_t) up;
get_systime(&pp->lastrec);
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
up->unit = unit;
@@ -149,8 +145,10 @@ psc_shutdown(
struct peer *peer
)
{
- free(peer->procptr->unitptr);
- close(fd[unit]);
+ if (NULL != peer->procptr->unitptr)
+ free(peer->procptr->unitptr);
+ if (fd[unit] > 0)
+ close(fd[unit]);
}
/* psc_poll: read, decode, and record device time */
@@ -196,9 +194,10 @@ psc_poll(
pp->nsec = 1000000*BCD2INT3((tlo & 0x00FFF000) >> 12) +
BCD2INT3(tlo & 0x00000FFF);
- sprintf(pp->a_lastcode, "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x",
- pp->day, pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
- tlo);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x", pp->day,
+ pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
+ tlo);
pp->lencode = strlen(pp->a_lastcode);
/* compute the timecode timestamp */
OpenPOWER on IntegriCloud