From 8fcacaf0464a9a45fded4392e4f9ac31896d77c3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 Sep 2023 11:18:59 +0200 Subject: [PATCH] scsi_serial: convert from nanosleep() to usleep_safe() --- src/udev/scsi_id/scsi_serial.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index a271b1786cf..aed6082620e 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -793,14 +793,11 @@ int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname, memzero(dev_scsi->serial, len); for (cnt = 20; cnt > 0; cnt--) { - struct timespec duration; - fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOCTTY); if (fd >= 0 || errno != EBUSY) break; - duration.tv_sec = 0; - duration.tv_nsec = (200 * 1000 * 1000) + (random_u32() % 100 * 1000 * 1000); - nanosleep(&duration, NULL); + + usleep_safe(200U*USEC_PER_MSEC + random_u64_range(100U*USEC_PER_MSEC)); } if (fd < 0) return 1; -- 2.47.3