]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsclocks: fix dynamic clock ids
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 23 Dec 2024 23:56:12 +0000 (00:56 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 24 Dec 2024 00:02:15 +0000 (01:02 +0100)
Without an explicitly specified clock id, lsclocks would always use
clock id 0 (CLOCK_REALTIME) for the dynamic/PTP clocks.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
misc-utils/lsclocks.c

index 66a2cd12478084090892cd79de7d8f9d4ba1a4b7..0a87256761c0859f82d25368cfa710a4202050bc 100644 (file)
 #include "all-io.h"
 #include "list.h"
 
+#define CLOCKFD 3
+
+static inline clockid_t FD_TO_CLOCKID(int fd)
+{
+       return (~(unsigned int) fd << 3) | CLOCKFD;
+}
+
 #ifndef CLOCK_REALTIME
 #define CLOCK_REALTIME                 0
 #endif
@@ -380,6 +387,7 @@ static void add_dynamic_clock_from_path(struct libscols_table *tb,
 
        struct clockinfo clockinfo = {
                .type = CT_PTP,
+               .id = FD_TO_CLOCKID(fd),
                .no_id = true,
                .id_name = path,
                .name = path,