mirror of
https://github.com/systemd/systemd.git
synced 2024-11-05 15:21:37 +03:00
cdrom_id: retry to open the device, if EBUSY
We might fight about the device with polling processes, or other users who probe the device. Retry a few times if the other one goes away in the meantime. Based on a patch from Harald Hoyer.
This commit is contained in:
parent
36a07a8c34
commit
cccfffbe04
@ -30,6 +30,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <time.h>
|
||||||
#include <scsi/sg.h>
|
#include <scsi/sg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -591,7 +592,22 @@ int main(int argc, char *argv[])
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));
|
if (is_mounted(node)) {
|
||||||
|
fd = open(node, O_RDONLY|O_NONBLOCK);
|
||||||
|
} else {
|
||||||
|
int cnt;
|
||||||
|
struct timespec duration;
|
||||||
|
|
||||||
|
srand((unsigned int)getpid());
|
||||||
|
for (cnt = 40; cnt > 0; cnt--) {
|
||||||
|
fd = open(node, O_RDONLY|O_NONBLOCK|O_EXCL);
|
||||||
|
if (fd >= 0 || errno != EBUSY)
|
||||||
|
break;
|
||||||
|
duration.tv_sec = 0;
|
||||||
|
duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
|
||||||
|
nanosleep(&duration, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
info(udev, "unable to open '%s'\n", node);
|
info(udev, "unable to open '%s'\n", node);
|
||||||
fprintf(stderr, "unable to open '%s'\n", node);
|
fprintf(stderr, "unable to open '%s'\n", node);
|
||||||
|
Loading…
Reference in New Issue
Block a user