[sane-devel] Microtek SANE bug and fix for ADF
Maurice Hilarius
maurice@harddata.com
Mon, 19 Nov 2001 21:20:49 -0700
If you have a Microtek or similar scanner with an automatic document feeder
(ADF) then there is a bug in the SANE code for using this feeder device.
We have been working with a Microtek ScanMaker X12USL, and ran into a
problem with the code for the ADF handling.
After a multi-page scan, it would crash you right out of X!
As this is not a desirable feature, we have been looking into the reasons
for this.
Fortunately we have found it, and I include a patch at the end of this message.
The problem is in the 'cancel_scan()' function in microtek2.c.
When using the automatic document feeder, after it has scanned all the
pages, and there are no more pages to scan, this function is called after
an I/O error ir produced by the lack of a page to feed.
It is then supposed to stop the scanner from trying to scan any more pages.
A comment in the code says:
"/* READ IMAGE with a transferlength of 0 aborts a scan */".
This is fine, but then 'close(ms->fd[1])' may be called
ms->fd[1] equal to -1 (which does not have any nasty consequences,)
BUT! a bit below that you effectively have 'kill(-1, SIGTERM);'.
Try 'man 2 kill' to see what this does. :-)
After this patch:
--- sane-backends-1.0.5/backend/microtek2.c~ Sun May 27 04:20:20 2001
+++ sane-backends-1.0.5/backend/microtek2.c Mon Nov 19 19:11:05 2001
@@ -1403,8 +1403,15 @@
status = SANE_STATUS_CANCELLED;
close(ms->fd[1]);
- kill(ms->pid, SIGTERM);
- waitpid(ms->pid, NULL, 0);
+ /* if we are aborting a scan because, for example, we run out
+ of material on a feeder, then pid may be already -1 and
+ kill(-1, SIGTERM), i.e. killing all our processes, is not
+ likely what we really want - --mj, 2001/Nov/19 */
+ if (ms->pid > 1)
+ {
+ kill(ms->pid, SIGTERM);
+ waitpid(ms->pid, NULL, 0);
+ }
return status;
}
With this revision of the code runs of batch scans using "ADF" settings
terminate properly and without any other visible side-effects.
I have no idea if other backends have similar problems; 'kill()' call
is used in a number of places.
Meanwhile, an other trivial trouble we see is that 'scanimage' without any
explicitly specified format is still using an extension of '.pnm' even if
'--format tiff' is given.
For further excitement the manpage claims that "out%d.tif" is _always_ the
default; at least in the presence of '--batch'.
Perhaps this is related to the "features" of a given scanner, but with the
"ScanMaker X12USL", (while using the microtek2 backend), we are getting
"stripes" on both sides of scanned images.
'--backend-calibration' options, which some docs suggest may help with
that, is listed by 'scanimage --help' as "[inactive]".
Indeed, it seems to not make any difference.
Does anyone have any suggestions or ideas for what to do with that problem?
Maurice Hilarius and Michal Jaegermann
maurice@harddata.com
michal@harddata.com
With our best regards,
Maurice W. Hilarius Telephone: 01-780-456-9771
Hard Data Ltd. FAX: 01-780-456-9772
11060 - 166 Avenue mailto:maurice@harddata.com
Edmonton, AB, Canada http://www.harddata.com/
T5X 1Y3