From: Frank Kardel Date: Sun, 19 Mar 2006 07:23:01 +0000 (+0000) Subject: refclock_datum.c: X-Git-Tag: NTP_4_2_1P10_RC~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9d63ca0954e9d936f478b58586e3a7e5a16f5ce;p=thirdparty%2Fntp.git refclock_datum.c: error handling: check success of open(2) - bail out early (Coverity CID 1282 NetBSD Scan 5) bk: 441d06d53jNFl-LGN2t6rf9lXP1pSA --- diff --git a/ntpd/refclock_datum.c b/ntpd/refclock_datum.c index 82b73690f..b26fe73cf 100644 --- a/ntpd/refclock_datum.c +++ b/ntpd/refclock_datum.c @@ -119,6 +119,7 @@ #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 */