Skip to content

Commit 596d600

Browse files
committed
Minor changes after latest merge
1 parent 5d4faec commit 596d600

3 files changed

Lines changed: 34 additions & 17 deletions

File tree

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- github #174 - put back notification about missing pysmbc
55
- update .pot file because of fix #174
66
- python3.9 - xml module removed elem.getchildren() method, use list(elem)
7+
- Make the matching rule of printer device path more flexible (#183)
78

89
1.5.12 changes
910
--------------

udev/70-printers.rules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
# UDEV rules for USB devices - ENV variables can be monitored
2+
# via 'sudo udevadm monitor --udev --subsystem-match=usb --property'
13
# Low-level USB device add trigger
24
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="systemd", ENV{SYSTEMD_WANTS}="configure-printer@usb-$env{BUSNUM}-$env{DEVNUM}.service"
35
# Low-level USB device remove trigger
6+
# Interface types:
7+
# 7/1/1 - device with unidirectional USB, managed by usb backend
8+
# 7/1/2 - device with bidirectional USB, managed by usb backend
9+
# 7/1/3 - device with special USB protocol, managed by hp backend
10+
# 7/1/4 - device with IPP over USB protocol, managed by ipp-usb daemon
411
ACTION=="remove", SUBSYSTEM=="usb", ENV{INTERFACE}=="7/1/*", RUN+="udev-configure-printer remove %p"

udev/udev-configure-printer.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,28 +1792,25 @@ disable_queue (const char *printer_uri, void *context)
17921792
httpClose (cups);
17931793
}
17941794

1795-
static int
1796-
device_exists(char *device_path)
1795+
/*
1796+
* 'device_exists()' - Checks if the device really exists within filesystem.
1797+
*/
1798+
1799+
static int /* 0 if not found, 1 if found*/
1800+
device_exists(
1801+
char *device_path) /* I - string representing device path of USB device*/
17971802
{
17981803
char full_path[100];
17991804
struct stat buffer;
1800-
int exist = -1;
1801-
int path_length=strlen(device_path);
1802-
// 5 is the length of "/sys" + null
1803-
snprintf(full_path, path_length + 5, "%s%s", "/sys", device_path);
18041805

1805-
// check the exist of this device
1806-
if (stat(full_path, &buffer) == 0){
1807-
exist = 1;
1808-
}
1806+
// create a full path
1807+
snprintf(full_path, sizeof(full_path), "%s%s", "/sys", device_path);
18091808

1810-
return exist;
1811-
}
1809+
// check the exist of this device
1810+
if (stat(full_path, &buffer) == 0)
1811+
return 1;
18121812

1813-
static char*
1814-
compare_usb_uri(char *uri_store, char *uri_uevent)
1815-
{
1816-
return strstr(uri_uevent, uri_store);
1813+
return 0;
18171814
}
18181815

18191816
static int
@@ -1855,7 +1852,19 @@ do_remove (const char *devaddr)
18551852
prev = &map->entries;
18561853
for (entry = map->entries; entry; entry = entry->next)
18571854
{
1858-
if (compare_usb_uri(entry->devpath, devpath) !=NULL && device_exists(entry->devpath) == -1)
1855+
/* devpath is a string obtained from USB 'remove' event
1856+
* and it is usually longer or the same as the string
1857+
* from the main USB 'add' event, when the device is added.
1858+
*
1859+
* Both strings represent device paths in filesystem without '/sys':
1860+
* f.e.:
1861+
* /devices/pci0000:00/0000:00:14.0/usb3/3-2
1862+
*
1863+
* When we are disabling the queue, we check if the string from 'add'
1864+
* event is a substring of string from 'remove' event and the actual
1865+
* device doesn't exist anymore.
1866+
*/
1867+
if (strstr(devpath, entry->devpath) != NULL && !device_exists(entry->devpath))
18591868
{
18601869
uris = &entry->uris;
18611870
break;

0 commit comments

Comments
 (0)