[Debburn-devel] handling device opening failures
neologix at free.fr
neologix at free.fr
Mon Oct 2 14:19:39 UTC 2006
In fact, it's even clearer if we start of at 1 (the rank of the try):
// try to reopen locked/busy devices up to five times
for (i = 1; (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);
}
cheers
Selon neologix at free.fr:
> 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
>
> _______________________________________________
> Debburn-devel mailing list
> Debburn-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/debburn-devel
>
More information about the Debburn-devel
mailing list