From 0f8ff22a9f148bfea0fffea7b776b80030bf0791 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 4 Sep 2024 15:59:30 +0200 Subject: [PATCH] timemaster: Wait for udev to set up vclock devices. timemaster created vclock /dev/ptp devices (by writing to /sys/class/ptp/ptp?/n_vclocks) and immediately started ptp4l instances using those vclocks. It's a race condition. On a SELinux-enabled system ptp4l was observed to exit with an error due to the device not having its SELinux context set by udev yet. Add a 100-millisecond sleep after creating the vclocks to give udev time to finish its job before starting ptp4l instances. Signed-off-by: Miroslav Lichvar --- timemaster.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/timemaster.c b/timemaster.c index fab71fc8..b367b2f8 100644 --- a/timemaster.c +++ b/timemaster.c @@ -1240,12 +1240,18 @@ static int create_vclocks(struct phc_vclocks **phc_vclocks) { struct phc_vclocks **vclocks; + if (!*phc_vclocks) + return 0; + for (vclocks = phc_vclocks; *vclocks; vclocks++) { if (set_phc_n_vclocks((*vclocks)->pclock_index, (*vclocks)->vclocks)) return 1; } + /* Wait for udev to set up the new /dev/ptp* devices */ + usleep(100000); + return 0; }