]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
refclock_datum.c:
authorFrank Kardel <kardel@ntp.org>
Sun, 19 Mar 2006 07:23:01 +0000 (07:23 +0000)
committerFrank Kardel <kardel@ntp.org>
Sun, 19 Mar 2006 07:23:01 +0000 (07:23 +0000)
  error handling: check success of open(2) - bail out early (Coverity CID 1282 NetBSD Scan 5)

bk: 441d06d53jNFl-LGN2t6rf9lXP1pSA

ntpd/refclock_datum.c

index 82b73690f46d7df906fdb09ed11e971a0d4a83bb..b26fe73cfc9ecc576377a343f1f61ce320a86779 100644 (file)
 #define        REFID "DATM"                    /* reference id */
 #define DATUM_DISPERSION 0             /* fixed dispersion = 0 ms */
 #define DATUM_MAX_ERROR 0.100          /* limits on sigma squared */
+#define DATUM_DEV      "/dev/datum"    /* device name */
 
 #define DATUM_MAX_ERROR2 (DATUM_MAX_ERROR*DATUM_MAX_ERROR)
 
@@ -233,6 +234,7 @@ datum_pts_start(
 {
        struct datum_pts_unit **temp_datum_pts_unit;
        struct datum_pts_unit *datum_pts;
+       int fd;
 #ifdef HAVE_TERMIOS
        struct termios arg;
 #endif
@@ -242,6 +244,16 @@ datum_pts_start(
            printf("Starting Datum PTS unit %d\n", unit);
 #endif
 
+       /*
+       ** Open the Datum PTS device
+       */
+       fd = open(DATUM_DEV, O_RDWR);
+
+       if (fd < 0) {
+               msyslog(LOG_ERR, "Datum_PTS: open(\"%s\", O_RDWR) failed: %m", DATUM_DEV);
+               return 0;
+       }
+
        /*
        ** Create the memory for the new unit
        */
@@ -260,11 +272,7 @@ datum_pts_start(
        datum_pts->yearstart = 0;       /* initialize the yearstart to 0 */
        datum_pts->sigma2 = 0.0;        /* initialize the sigma2 to 0 */
 
-       /*
-       ** Open the Datum PTS device
-       */
-
-       datum_pts->PTS_fd = open("/dev/datum",O_RDWR);
+       datum_pts->PTS_fd = fd;
 
        fcntl(datum_pts->PTS_fd, F_SETFL, 0); /* clear the descriptor flags */