#901695 scanbd: After powercycling a scanner, scanbd tries to open old ID

Package:
scanbd
Source:
scanbd
Description:
Scanner button daemon
Submitter:
Pelzi
Date:
2023-01-31 14:57:02 UTC
Severity:
important
#901695#5
Date:
2018-06-16 20:47:45 UTC
From:
To:
Dear Maintainer,

scanbd is running on a machine connected via USB with a scanner that has an actual power switch. If switched off, the USB device becomes unavailable.

scanbd is not correctly reacting, when the device is switched on while it is already running. Everything is perfect if scanbd is restarted when the
scanner is switched on.

The logs attached below occur at step 5 in the following context:
1) Scanner is switched on
2) scanbd is started
3) scanning is done
4) scanner is switched off for a while
5) scanner is switche on again

The logs seem to show that scanbd receives an error on trying to open the old scanner ID, i.e. containing the USB path the scanner had in step 2.
This device no longer exists in step 5, so the problem seems to be that scanbd tries to open an outdated device ID.

At the same time, scanimage -L shows a different device ID, so it seems that scanbd fails to correctly operate on an updated device list.

Obviously, I expected that scanbd would open the new device ID and started polling for the button to be pressed.

Regards,
Andreas

#901695#10
Date:
2022-02-08 08:23:56 UTC
From:
To:
I can confirm this bug and have the same problem with a Canon PIXMA TS6050 (6000 series).

Any idea what we can do to fix this?

Cheers
Jakob

#901695#15
Date:
2023-01-31 14:55:34 UTC
From:
To:
message is identical (mutans mutatis) to that in the logs posted here, but
in my case `scanimage -L` shows that the device name has not changed.

Nonetheless, sane is still returning SANE_STATUS_INVAL.

I have turned on debug output in scanbd, and looked at the source code, but
I can't see why the call to sane_open is succeeding the first time, but not
subsequently. It might be worth debugging inside libsane to make progress,
but I'd welcome assistance from experts!

For now, I added an rsyslog filter that runs a program to restart scanbd
whenever it logs an "abandon" message.

This in itself requires a few steps:

1. Compile the following C program, setuid, as
/usr/local/sbin/restart-scanbd:

#include <stdlib.h>

int main (void)
{
  system ("sudo systemctl restart scanbd.service");
}

2. Write the rsyslog filter to execute it (/etc/rsyslog.d/99-scanbd):

:msg, regex, "/usr/sbin/scanbd: abandon polling of"
^/usr/local/sbin/restart-scanbd

3. Edit systemd's unit for rsyslog to add "NotifyAccess=all" (sudo
systemctl edit rsyslog), otherwise the filter doesn't get executed.

4. Run visudo and add the following to /etc/sudoers:

# Allow syslog to restart scanbd
syslog ALL=(root) NOPASSWD: /usr/bin/systemctl restart scanbd.service

It's a painful workaround, but for me it worked flawlessly.