udev/cdrom: use random_u64() and usleep()
This commit is contained in:
parent
56c1a2977b
commit
511ff06e99
|
@ -1050,7 +1050,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int cnt;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -1065,16 +1064,13 @@ int main(int argc, char *argv[]) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize_srand();
|
for (int cnt = 0; cnt < 20; cnt++) {
|
||||||
for (cnt = 20; cnt > 0; cnt--) {
|
if (cnt != 0)
|
||||||
struct timespec duration;
|
(void) usleep(100 * USEC_PER_MSEC + random_u64() % (100 * USEC_PER_MSEC));
|
||||||
|
|
||||||
fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
|
fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
|
||||||
if (fd >= 0 || errno != EBUSY)
|
if (fd >= 0 || errno != EBUSY)
|
||||||
break;
|
break;
|
||||||
duration.tv_sec = 0;
|
|
||||||
duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
|
|
||||||
nanosleep(&duration, NULL);
|
|
||||||
}
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
log_debug("unable to open '%s'", arg_node);
|
log_debug("unable to open '%s'", arg_node);
|
||||||
|
|
Loading…
Reference in New Issue