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_hopfpci.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_hopfpci.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_hopfpci.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/contrib/ntp/ntpd/refclock_hopfpci.c b/contrib/ntp/ntpd/refclock_hopfpci.c index 81c186d..95bcab9 100644 --- a/contrib/ntp/ntpd/refclock_hopfpci.c +++ b/contrib/ntp/ntpd/refclock_hopfpci.c @@ -124,51 +124,38 @@ hopfpci_start( /* * Allocate and initialize unit structure */ - up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit)); - - if (!(up)) { - msyslog(LOG_ERR, "hopfPCIClock(%d) emalloc: %m",unit); -#ifdef DEBUG - printf("hopfPCIClock(%d) emalloc\n",unit); -#endif - return (0); - } - memset((char *)up, 0, sizeof(struct hopfclock_unit)); + up = emalloc_zero(sizeof(*up)); #ifndef SYS_WINNT fd = open(DEVICE,O_RDWR); /* try to open hopf clock device */ #else - if (!OpenHopfDevice()){ - msyslog(LOG_ERR,"Start: %s unit: %d failed!",DEVICE,unit); + if (!OpenHopfDevice()) { + msyslog(LOG_ERR, "Start: %s unit: %d failed!", DEVICE, unit); + free(up); return (0); } #endif pp = peer->procptr; pp->io.clock_recv = noentry; - pp->io.srcclock = (caddr_t)peer; + pp->io.srcclock = peer; pp->io.datalen = 0; pp->io.fd = INVALID_SOCKET; - pp->unitptr = (caddr_t)up; + pp->unitptr = up; get_systime(&pp->lastrec); /* * Initialize miscellaneous peer variables */ - if (pp->unitptr!=0) { - memcpy((char *)&pp->refid, REFID, 4); - peer->precision = PRECISION; - pp->clockdesc = DESCRIPTION; - up->leap_status = 0; - up->unit = (short) unit; - return (1); - } - else { - return 0; - } + memcpy((char *)&pp->refid, REFID, 4); + peer->precision = PRECISION; + pp->clockdesc = DESCRIPTION; + up->leap_status = 0; + up->unit = (short) unit; + return (1); } @@ -187,6 +174,8 @@ hopfpci_shutdown( #else CloseHopfDevice(); #endif + if (NULL != peer->procptr->unitptr) + free(peer->procptr->unitptr); } @@ -205,7 +194,9 @@ hopfpci_poll( pp = peer->procptr; #ifndef SYS_WINNT - ioctl(fd,HOPF_CLOCK_GET_UTC,&m_time); + if (ioctl(fd, HOPF_CLOCK_GET_UTC, &m_time) < 0) + msyslog(LOG_ERR, "HOPF_P(%d): HOPF_CLOCK_GET_UTC: %m", + unit); #else GetHopfSystemTime(&m_time); #endif @@ -221,9 +212,11 @@ hopfpci_poll( else pp->leap = LEAP_NOWARNING; - sprintf(pp->a_lastcode,"ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d", - m_time.wStatus, pp->hour, pp->minute, pp->second, - pp->nsec / 1000000, m_time.wDay, m_time.wMonth, m_time.wYear); + snprintf(pp->a_lastcode, sizeof(pp->a_lastcode), + "ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d", + m_time.wStatus, pp->hour, pp->minute, pp->second, + pp->nsec / 1000000, m_time.wDay, m_time.wMonth, + m_time.wYear); pp->lencode = (u_short)strlen(pp->a_lastcode); get_systime(&pp->lastrec); |