sane-backends: rebind printers to usblp after scan 8851/head
authorLuiz Angelo Daros de Luca <luizluca@gmail.com>
Tue, 30 Apr 2019 04:32:59 +0000 (01:32 -0300)
committerLuiz Angelo Daros de Luca <luizluca@gmail.com>
Thu, 2 May 2019 06:31:45 +0000 (03:31 -0300)
While scanning, sane unbinds usb device from usblp module. This
patch creates a saned wrapper that keep track of all usb devices
binded to usblp before saned is launched and rebind them back
if not still bound after saned exits.

This workaround is only effective if saned is launched by a super
daemon like xinetd as it needs to exit after scan job finish. If
not, printing will not be available while saned service is running.

Write access to /sys/bus/usb/drivers/usblp/bind is required. So,
normally it would require root access.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
utils/sane-backends/Makefile
utils/sane-backends/files/etc/xinetd.d/sane-port [new file with mode: 0644]
utils/sane-backends/files/usr/sbin/saned [new file with mode: 0755]
utils/sane-backends/files/xinet.d_sane-port [deleted file]

index f4077c3a14f3b716a44e4002cb01058bfe7cce97..774428d7fd3ed1804b5515a416ce52c9f2831550 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Copyright (C) 2006-2016 OpenWrt.org
-# Copyright (C) 2017-2018 Luiz Angelo Daros de Luca <luizluca@gmail.com>
+# Copyright (C) 2017-2019 Luiz Angelo Daros de Luca <luizluca@gmail.com>
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=sane-backends
 PKG_VERSION:=1.0.27
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://fossies.org/linux/misc \
     https://alioth.debian.org/frs/download.php/file/4146/
@@ -193,9 +193,11 @@ define Package/sane-daemon/install
        $(INSTALL_DIR) $(1)/etc/sane.d
        $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/sane.d/saned.conf $(1)/etc/sane.d/
        $(INSTALL_DIR) $(1)/usr/sbin
-       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/* $(1)/usr/sbin/
+       $(INSTALL_BIN) ./files/usr/sbin/saned $(1)/usr/sbin/saned
+       $(INSTALL_DIR) $(1)/usr/lib/sane/
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/saned $(1)/usr/lib/sane/saned
        $(INSTALL_DIR) $(1)/etc/xinetd.d
-       $(CP) ./files/xinet.d_sane-port $(1)/etc/xinetd.d/sane-port
+       $(CP) ./files/etc/xinetd.d/sane-port $(1)/etc/xinetd.d/sane-port
 endef
 
 define Package/sane-daemon/conffiles
diff --git a/utils/sane-backends/files/etc/xinetd.d/sane-port b/utils/sane-backends/files/etc/xinetd.d/sane-port
new file mode 100644 (file)
index 0000000..9119973
--- /dev/null
@@ -0,0 +1,14 @@
+# default: off
+# description: The saned provides scanner service via the network.  \
+#      Applications like kooka, xsane or xscanimage can use the remote \
+#      scanner. 
+service sane-port
+{
+       socket_type = stream
+       port        = 6566
+       wait        = no
+       user        = root
+       group       = root
+       server      = /usr/sbin/saned
+       disable     = yes
+}
diff --git a/utils/sane-backends/files/usr/sbin/saned b/utils/sane-backends/files/usr/sbin/saned
new file mode 100755 (executable)
index 0000000..7114926
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+usblp_driver="/sys/bus/usb/drivers/usblp"
+
+inuse=""
+if [ -e /sys/bus/usb/devices ]; then
+       for usbdev_driver in /sys/bus/usb/devices/*/driver; do
+               [ -e "$usbdev_driver" ] || continue
+               [ "$(readlink -f "$usbdev_driver")" = "$usblp_driver" ] || continue
+               usbdev="${usbdev_driver%/*}"
+               inuse="$inuse ${usbdev##*/}"
+       done
+fi
+
+/usr/lib/sane/saned "$@"
+err=$?
+
+for usbdev in $inuse; do
+       [ -e "/sys/bus/usb/devices/$usbdev/driver" ] && continue
+       logger -t saned "binding device $usbdev back to usblp..."
+       printf '%s' "$usbdev" > "$usblp_driver/bind"
+done
+
+exit $err
diff --git a/utils/sane-backends/files/xinet.d_sane-port b/utils/sane-backends/files/xinet.d_sane-port
deleted file mode 100644 (file)
index 9119973..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-# default: off
-# description: The saned provides scanner service via the network.  \
-#      Applications like kooka, xsane or xscanimage can use the remote \
-#      scanner. 
-service sane-port
-{
-       socket_type = stream
-       port        = 6566
-       wait        = no
-       user        = root
-       group       = root
-       server      = /usr/sbin/saned
-       disable     = yes
-}