Don't return bogus clock id
phc_open() can open any device and return clkid even if the device is not phc for example /dev/kvm and so on. As a result, phc2sys keeps running with reading bogus clock as below: # phc2sys -s /dev/kvm -O 0 -q -m phc2sys[687019.699]: failed to read clock: Invalid argument phc2sys[687020.699]: failed to read clock: Invalid argument phc2sys[687021.699]: failed to read clock: Invalid argument phc2sys[687022.699]: failed to read clock: Invalid argument ... This patch fixes that problem. Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>master
parent
74e703727e
commit
67c925f459
16
phc.c
16
phc.c
|
@ -36,11 +36,25 @@
|
|||
#define BITS_PER_LONG (sizeof(long)*8)
|
||||
#define MAX_PPB_32 32767999 /* 2^31 - 1 / 65.536 */
|
||||
|
||||
static int phc_get_caps(clockid_t clkid, struct ptp_clock_caps *caps);
|
||||
|
||||
clockid_t phc_open(char *phc)
|
||||
{
|
||||
clockid_t clkid;
|
||||
struct ptp_clock_caps caps;
|
||||
int fd = open(phc, O_RDWR);
|
||||
|
||||
return fd < 0 ? CLOCK_INVALID : FD_TO_CLOCKID(fd);
|
||||
if (fd < 0)
|
||||
return CLOCK_INVALID;
|
||||
|
||||
clkid = FD_TO_CLOCKID(fd);
|
||||
/* check if clkid is valid */
|
||||
if (phc_get_caps(clkid, &caps)) {
|
||||
close(fd);
|
||||
return CLOCK_INVALID;
|
||||
}
|
||||
|
||||
return clkid;
|
||||
}
|
||||
|
||||
void phc_close(clockid_t clkid)
|
||||
|
|
Loading…
Reference in New Issue