]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1356] core dump from refclock_nmea when can't open /dev/gpsU.
authorDave Hart <hart@ntp.org>
Wed, 28 Oct 2009 03:42:47 +0000 (03:42 +0000)
committerDave Hart <hart@ntp.org>
Wed, 28 Oct 2009 03:42:47 +0000 (03:42 +0000)
bk: 4ae7bdb7crX-PqNrNWjfAqJ9SscBww

ChangeLog
ntpd/refclock_nmea.c

index de2f3bd6536c0216982fcaf78c96f49191a31261..d64d20d9c4400849f44efa60d520e52381915f71 100644 (file)
--- 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 <stenn@ntp.org>
 * Changes from Dave Mills.
 * driver4.html updates from Dave Mills.
index 30e14261b9b8798423bfc63928c8d7136d5b8b18..31fe88ad03bc79f05b7fcadb933202ee1e9fa435 100644 (file)
@@ -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);
 }
 
 /*