Skip to content

Commit d1aab4e

Browse files
committed
* Update the udev rule due to usb_id udev import is disabled in some systems.
* Make the matching rule of printer device path more flexible.
1 parent 63eccd5 commit d1aab4e

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

udev/70-printers.rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Low-level USB device add trigger
22
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"
33
# Low-level USB device remove trigger
4-
ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"
4+
ACTION=="remove", SUBSYSTEM=="usb", ENV{INTERFACE}=="7/1/*", ENV{INTERFACE}!="7/1/4", RUN+="udev-configure-printer remove %p"

udev/udev-configure-printer.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,39 @@ disable_queue (const char *printer_uri, void *context)
17911791
ippDelete (answer);
17921792
httpClose (cups);
17931793
}
1794+
static int
1795+
compare_usb_uri(char *uri_store, char *uri_uevent)
1796+
{
1797+
int index = 0;
1798+
int subset = 1;
1799+
int exist = -1;
1800+
char *full_path = NULL;
1801+
struct stat buffer;
1802+
1803+
if (strlen(uri_uevent) < strlen(uri_store))
1804+
return -1;
1805+
1806+
// check whether it's a substring
1807+
full_path = (char *) malloc(strlen(uri_store) + 4);
1808+
memset(full_path, 0, sizeof(full_path));
1809+
strcpy(full_path, "/sys");
1810+
strcat(full_path, uri_store);
1811+
while (uri_store[index] != '\0'){
1812+
if (uri_store[index] != uri_uevent[index]){
1813+
subset = -1;
1814+
break;
1815+
}
1816+
index++;
1817+
}
1818+
1819+
// check the exist of this device
1820+
if (subset == 1 && stat(full_path, &buffer) == 0){
1821+
exist = 1;
1822+
}
1823+
1824+
free(full_path);
1825+
return exist;
1826+
}
17941827

17951828
static int
17961829
do_remove (const char *devaddr)
@@ -1830,8 +1863,8 @@ do_remove (const char *devaddr)
18301863
map = read_usb_uri_map ();
18311864
prev = &map->entries;
18321865
for (entry = map->entries; entry; entry = entry->next)
1833-
{
1834-
if (!strcmp (entry->devpath, devpath))
1866+
{
1867+
if (compare_usb_uri(entry->devpath, devpath))
18351868
{
18361869
uris = &entry->uris;
18371870
break;

0 commit comments

Comments
 (0)