Re: Bug in example in https://man7.org/linux/man-pages/man2/clock_gettime.2.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[CC += linux-man@]

On Tue, 25 Aug 2020 at 16:13, Tony May <tony.may@xxxxxxxxxxxxx> wrote:
>
> Dear Michael Kerrisk,
>
> I have been using PTP and found the documentation
> patch provided by Richard Cochran:
> https://lore.kernel.org/patchwork/patch/868609/. This patch
> included a bug which now appears in
> https://man7.org/linux/man-pages/man2/clock_gettime.2.html
>
> I think the example code he provides contains a bug:
>
>            struct timeval tv;
>            clockid_t clkid;
>            int fd;
>
>            fd = open("/dev/ptp0", O_RDWR);
>            clkid = FD_TO_CLOCKID(fd);
>            clock_gettime(clkid, &tv);
>
> The clock_gettime function requires a timespec not a
> timeval variable, so the code should be:
>
>            struct timespec ts;
>            clockid_t clkid;
>            int fd;
>
>            fd = open("/dev/ptp0", O_RDWR);
>            clkid = FD_TO_CLOCKID(fd);
>            clock_gettime(clkid, &ts);
>
> I have a running test application based on my changes,
> so I am confident the modified code works.

Thanks, Tony. I applied the patch below.

Cheers,

Michael

diff --git a/man2/clock_getres.2 b/man2/clock_getres.2
index c0e486c2a..8fc7c6fef 100644
--- a/man2/clock_getres.2
+++ b/man2/clock_getres.2
@@ -251,13 +251,13 @@ dynamic clock ID.
 #define FD_TO_CLOCKID(fd)   ((\(ti(clockid_t) (fd) << 3) | CLOCKFD)
 #define CLOCKID_TO_FD(clk)  ((unsigned int) \(ti((clk) >> 3))

-struct timeval tv;
+struct timespec ts;
 clockid_t clkid;
 int fd;

 fd = open("/dev/ptp0", O_RDWR);
 clkid = FD_TO_CLOCKID(fd);
-clock_gettime(clkid, &tv);
+clock_gettime(clkid, &ts);
 .EE
 .in
 .SH RETURN VALUE

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux