From: Dave Hart Date: Wed, 28 Oct 2009 03:42:47 +0000 (+0000) Subject: [Bug 1356] core dump from refclock_nmea when can't open /dev/gpsU. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff3a30b97b5ac7bcdd5fa42099a8ca6ddd503842;p=thirdparty%2Fntp.git [Bug 1356] core dump from refclock_nmea when can't open /dev/gpsU. bk: 4ae7bdb7crX-PqNrNWjfAqJ9SscBww --- diff --git a/ChangeLog b/ChangeLog index de2f3bd653..d64d20d9c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1356] core dump from refclock_nmea when can't open /dev/gpsU. (4.2.5p238-RC) 2009/10/27 Released by Harlan Stenn * Changes from Dave Mills. * driver4.html updates from Dave Mills. diff --git a/ntpd/refclock_nmea.c b/ntpd/refclock_nmea.c index 30e14261b9..31fe88ad03 100644 --- a/ntpd/refclock_nmea.c +++ b/ntpd/refclock_nmea.c @@ -177,6 +177,8 @@ nmea_start( int baudrate; char *baudtext; + pp = peer->procptr; + /* * Open serial port. Use CLK line discipline, if available. */ @@ -269,6 +271,7 @@ nmea_start( return (0); } #else + pp->io.fd = -1; return (0); #endif } @@ -281,12 +284,12 @@ nmea_start( */ up = emalloc(sizeof(*up)); memset(up, 0, sizeof(*up)); - pp = peer->procptr; pp->io.clock_recv = nmea_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; pp->io.fd = fd; if (!io_addclock(&pp->io)) { + pp->io.fd = -1; close(fd); free(up); return (0); @@ -308,6 +311,9 @@ nmea_start( /* * nmea_shutdown - shut down a GPS clock + * + * NOTE this routine is called after nmea_start() returns failure, + * as well as during a normal shutdown due to ntpq :config unpeer. */ static void nmea_shutdown( @@ -322,15 +328,18 @@ nmea_shutdown( pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr; + if (up != NULL) { #ifdef HAVE_PPSAPI - if (up->ppsapi_lit) { - time_pps_destroy(up->atom.handle); - if (up->ppsapi_fd != pp->io.fd) - close(up->ppsapi_fd); - } + if (up->ppsapi_lit) { + time_pps_destroy(up->atom.handle); + if (up->ppsapi_fd != pp->io.fd) + close(up->ppsapi_fd); + } #endif - io_closeclock(&pp->io); - free(up); + free(up); + } + if (-1 != pp->io.fd) + io_closeclock(&pp->io); } /*