diff --git a/stinit.8 b/stinit.8 index f918600..279e5eb 100644 --- a/stinit.8 +++ b/stinit.8 @@ -263,10 +263,9 @@ The long timeout for the device is set to seconds. .SH RETURN VALUE The program exits with value one if the command line is incorrect, the -definition file is not found, or option -p is given and parsing the -definition file fails. In all other cases the return value is -zero (i.e., failing of initialization is not currently signaled by -the return value). +definition file is not found, option -p is given and parsing the +definition file fails, or defining one or more of the options fails +when the tape number(s) are given on command line. .SH RESTRICTIONS With the exception of the -p option, the program can be used only by the superuser. This is because the program uses ioctls allowed only diff --git a/stinit.c b/stinit.c index 80face7..bc7a333 100644 --- a/stinit.c +++ b/stinit.c @@ -681,11 +681,11 @@ static int find_devfiles(int tapeno, char **names) static int set_defs(devdef_tr *defs, char **fnames) { - int i, tape; + int i, tape, fails; int clear_set[2]; struct mtop op; - for (i = 0; i < NBR_MODES; i++) { + for (i = fails = 0; i < NBR_MODES; i++) { if (*fnames[i] == '\0' || !defs->modedefs[i].defined) continue; @@ -699,14 +699,19 @@ static int set_defs(devdef_tr *defs, char **fnames) if (defs->do_rewind) { op.mt_op = MTREW; op.mt_count = 1; - ioctl(tape, MTIOCTOP, &op); /* Don't worry about result */ + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; + fprintf(stderr, "Rewind of %s fails.\n", fnames[i]); + } } if (defs->drive_buffering >= 0) { op.mt_op = MTSETDRVBUFFER; op.mt_count = MT_ST_DEF_DRVBUFFER | defs->drive_buffering; if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set drive buffering to %d.\n", defs->drive_buffering); + fails++; + fprintf(stderr, "Can't set drive buffering to %d.\n", + defs->drive_buffering); } } @@ -714,7 +719,9 @@ static int set_defs(devdef_tr *defs, char **fnames) op.mt_op = MTSETDRVBUFFER; op.mt_count = MT_ST_SET_TIMEOUT | defs->timeout; if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set device timeout %d s.\n", defs->timeout); + fails++; + fprintf(stderr, "Can't set device timeout %d s.\n", + defs->timeout); } } @@ -722,6 +729,7 @@ static int set_defs(devdef_tr *defs, char **fnames) op.mt_op = MTSETDRVBUFFER; op.mt_count = MT_ST_SET_LONG_TIMEOUT | defs->long_timeout; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set device long timeout %d s.\n", defs->long_timeout); } @@ -731,6 +739,7 @@ static int set_defs(devdef_tr *defs, char **fnames) op.mt_op = MTSETDRVBUFFER; op.mt_count = MT_ST_SET_CLN | defs->cleaning; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set cleaning request parameter to %x\n", defs->cleaning); } @@ -774,6 +783,7 @@ static int set_defs(devdef_tr *defs, char **fnames) if (clear_set[0] != 0) { op.mt_count = MT_ST_CLEARBOOLEANS | clear_set[0]; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't clear the tape options (bits 0x%x, mode %d).\n", clear_set[0], i); } @@ -781,6 +791,7 @@ static int set_defs(devdef_tr *defs, char **fnames) if (clear_set[1] != 0) { op.mt_count = MT_ST_SETBOOLEANS | clear_set[1]; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set the tape options (bits 0x%x, mode %d).\n", clear_set[1], i); } @@ -789,6 +800,7 @@ static int set_defs(devdef_tr *defs, char **fnames) if (defs->modedefs[i].blocksize >= 0) { op.mt_count = MT_ST_DEF_BLKSIZE | defs->modedefs[i].blocksize; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set blocksize %d for mode %d.\n", defs->modedefs[i].blocksize, i); } @@ -796,6 +808,7 @@ static int set_defs(devdef_tr *defs, char **fnames) if (defs->modedefs[i].density >= 0) { op.mt_count = MT_ST_DEF_DENSITY | defs->modedefs[i].density; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set density %x for mode %d.\n", defs->modedefs[i].density, i); } @@ -803,6 +816,7 @@ static int set_defs(devdef_tr *defs, char **fnames) if (defs->modedefs[i].compression >= 0) { op.mt_count = MT_ST_DEF_COMPRESSION | defs->modedefs[i].compression; if (ioctl(tape, MTIOCTOP, &op) != 0) { + fails++; fprintf(stderr, "Can't set compression %d for mode %d.\n", defs->modedefs[i].compression, i); } @@ -810,7 +824,7 @@ static int set_defs(devdef_tr *defs, char **fnames) close(tape); } - return TRUE; + return (fails == 0); } @@ -876,7 +890,7 @@ static char usage(int retval) int main(int argc, char **argv) { FILE *dbf = NULL; - int argn; + int argn, retval = 0; int tapeno, parse_only = FALSE; char *dbname = NULL; char *convp; @@ -933,8 +947,10 @@ int main(int argc, char **argv) fprintf(stderr, "Can't find tape number for name '%s'.\n", argv[argn]); continue; } - if (!define_tape(tapeno, dbf, &defs, TRUE)) + if (!define_tape(tapeno, dbf, &defs, TRUE)) { fprintf(stderr, "Definition for '%s' failed.\n", argv[argn]); + retval = 1; + } } } else { /* Initialize all SCSI tapes */ for (tapeno = 0; tapeno < MAX_TAPES; tapeno++) @@ -945,5 +961,5 @@ int main(int argc, char **argv) } } - return 0; + return retval; } diff --git a/tests/stinit-errors.test b/tests/stinit-errors.test index 4fed36f..9f670a2 100644 --- a/tests/stinit-errors.test +++ b/tests/stinit-errors.test @@ -39,11 +39,11 @@ # 1000 tapes. ./stinit -f stinit.def.examples 1000 >>>2 /Can't find any device files for tape 1000/ ->>>= 0 +>>>= 1 ./stinit -f stinit.def.examples 1000 >>>2 /Definition for '1000' failed/ ->>>= 0 +>>>= 1 # Wrong tape number (non-numeric). ./stinit -f stinit.def.examples 1000a