[Debburn-devel] handling device opening failures

neologix at free.fr neologix at free.fr
Mon Oct 2 14:04:37 UTC 2006


Selon Eduard Bloch <edi at gmx.de>:

+       // try to reopen locked/busy devices up to five times
+       for (i = 0; (i < 5) && (f == -1 && errno == EBUSY); i++) {
+               fprintf(stderr, "Error trying to open %s exclusively (%s)...
%s\n", device, strerror(errno), (i<5)?"retrying in 1 second.":"giving up.");
+               usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
+               f = open(device, mode|O_EXCL);
        }


ok.
I think there is a small error here.
"giving up" will never be displayed. It should be:

fprintf(stderr, "Error trying to open %s exclusively (%s)... %s\n", device,
strerror(errno), (i<(5-1))?"retrying in 1 second.":"giving up.");


And, if you want to sleep for 1 sec., why not just use:
sleep(1)


cheers



More information about the Debburn-devel mailing list