[Debburn-changes] r352 - in nonameyet/trunk: . libscg
Eduard Bloch
blade at costa.debian.org
Mon Oct 2 20:44:09 UTC 2006
Author: blade
Date: 2006-10-02 20:44:09 +0000 (Mon, 02 Oct 2006)
New Revision: 352
Modified:
nonameyet/trunk/Changelog
nonameyet/trunk/libscg/scsi-linux-sg.c
Log:
better device opening failure handling
Modified: nonameyet/trunk/Changelog
===================================================================
--- nonameyet/trunk/Changelog 2006-09-27 13:05:21 UTC (rev 351)
+++ nonameyet/trunk/Changelog 2006-10-02 20:44:09 UTC (rev 352)
@@ -13,6 +13,8 @@
* table formating fixes in cdda2wav.1, helps small terminals
* AIX 5l port
* killing FIFO process on ungraceful termination
+ * scsi-linux-sg.c: skipping unallowed devices, cleanup/consolidation of the
+ old workaround(s) for ATA now for SCSI too
[ Eugen Dedu ]
* corrections and constructive help on cdda2ogg
Modified: nonameyet/trunk/libscg/scsi-linux-sg.c
===================================================================
--- nonameyet/trunk/libscg/scsi-linux-sg.c 2006-09-27 13:05:21 UTC (rev 351)
+++ nonameyet/trunk/libscg/scsi-linux-sg.c 2006-10-02 20:44:09 UTC (rev 352)
@@ -242,25 +242,23 @@
#endif
LOCAL void sg_settimeout __PR((int f, int timeout));
-int sg_open_excl __PR((char *device, int mode, int quickAndQuiet));
+int sg_open_excl __PR((char *device, int mode));
int
-sg_open_excl(device, mode, quickAndQuiet)
+sg_open_excl(device, mode)
char *device;
int mode;
- int quickAndQuiet;
{
int f;
int i;
f = open(device, mode|O_EXCL);
- if(!quickAndQuiet)
- for (i = 0; (i < 10) && (f == -1 && (errno == EACCES || errno == EBUSY)); i++) {
- fprintf(stderr, "Error trying to open %s exclusively (%s)... retrying in 1 second.\n", device, strerror(errno));
- usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
- f = open(device, mode|O_EXCL);
- }
- if (f == -1 && errno != EACCES && errno != EBUSY) {
- f = open(device, mode);
+ /* 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<4)?"retrying in 1 second.":"giving up.");
+ usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
+ f = open(device, mode|O_EXCL);
}
return f;
}
@@ -448,7 +446,7 @@
if (use_ata) for (i=2*busno+tgt >= 0 ? 2*busno+tgt:0; i <= 25; i++) {
js_snprintf(devname, sizeof (devname), "/dev/hd%c", i+'a');
/* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, 1);
+ f = sg_open_excl(devname, O_RDWR | O_NONBLOCK);
if (f < 0) {
/*
* Set up error string but let us clear it later
@@ -489,7 +487,7 @@
if (nopen == 0) for (i = 0; i < 32; i++) {
js_snprintf(devname, sizeof (devname), "/dev/sg%d", i);
/* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, 0);
+ f = sg_open_excl(devname, O_RDWR | O_NONBLOCK);
if (f < 0) {
/*
* Set up error string but let us clear it later
@@ -498,6 +496,8 @@
if (scgp->errstr)
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
"Cannot open '/dev/sg*'");
+ if(errno == EACCES || errno==EPERM)
+ continue;
if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
if (scgp->errstr)
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
@@ -518,7 +518,7 @@
if (nopen == 0) for (i = 0; i <= 25; i++) {
js_snprintf(devname, sizeof (devname), "/dev/sg%c", i+'a');
/* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, 0);
+ f = sg_open_excl(devname, O_RDWR | O_NONBLOCK);
if (f < 0) {
/*
* Set up error string but let us clear it later
@@ -527,6 +527,8 @@
if (scgp->errstr)
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
"Cannot open '/dev/sg*'");
+ if(errno == EACCES || errno==EPERM)
+ continue;
if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
if (scgp->errstr)
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
@@ -552,25 +554,8 @@
if (b < 0 || b > 25)
b = -1;
}
- if (scgp->overbose) {
- /*
- * Before you patch this away, are you sure that you
- * know what you are going to to?
- *
- * Note that this is a warning that helps users from
- * cdda2wav, mkisofs and other programs (that
- * distinguish SCSI addresses from file names) from
- * getting unexpected results.
- *
- *
- * EB: Yes, I know, the hell I care about the distinguish SCSI addresses
- * which I do not need and don't want to care about.
- js_fprintf((FILE *)scgp->errfile,
- "Warning: Open by 'devname' is unintentional and not supported.\n");
- */
- }
- /* O_NONBLOCK is dangerous */
- f = sg_open_excl(device, O_RDWR | O_NONBLOCK, 0);
+ /* O_NONBLOCK is dangerous */
+ f = sg_open_excl(device, O_RDWR | O_NONBLOCK);
/* if (f < 0 && errno == ENOENT)*/
/* goto openpg;*/
More information about the Debburn-changes
mailing list