From 63102b844b8eac9f7304e2c32fba3f115b993fc6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 24 Dec 2024 00:56:12 +0100 Subject: [PATCH] lsclocks: fix dynamic clock ids MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- misc-utils/lsclocks.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/misc-utils/lsclocks.c b/misc-utils/lsclocks.c index 66a2cd124..0a8725676 100644 --- a/misc-utils/lsclocks.c +++ b/misc-utils/lsclocks.c @@ -40,6 +40,13 @@ #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, -- 2.47.3