1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

scsi_id: add rand() in retry loop

This commit is contained in:
Kay Sievers 2010-04-07 09:22:30 +02:00
parent 09a5b335b5
commit 1c8dc990dc

View File

@ -863,21 +863,21 @@ int scsi_get_serial(struct udev *udev,
{ {
unsigned char page0[SCSI_INQ_BUFF_LEN]; unsigned char page0[SCSI_INQ_BUFF_LEN];
int fd = -1; int fd = -1;
int cnt = 10; int cnt;
int ind; int ind;
int retval; int retval;
memset(dev_scsi->serial, 0, len); memset(dev_scsi->serial, 0, len);
dbg(udev, "opening %s\n", devname); dbg(udev, "opening %s\n", devname);
while (--cnt) { srand((unsigned int)getpid());
const struct timespec duration = { 0, 500 * 1000 * 1000 }; for (cnt = 20; cnt > 0; cnt--) {
struct timespec duration;
fd = open(devname, O_RDONLY | O_NONBLOCK); fd = open(devname, O_RDONLY | O_NONBLOCK);
if (fd >= 0) if (fd >= 0 || errno != EBUSY)
break;
info(udev, "%s: cannot open %s: %s\n", dev_scsi->kernel, devname, strerror(errno));
if (errno != EBUSY)
break; break;
duration.tv_sec = 0;
duration.tv_nsec = (200 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
nanosleep(&duration, NULL); nanosleep(&duration, NULL);
} }
if (fd < 0) if (fd < 0)