Skip to content

Commit 5d4faec

Browse files
Merge pull request #183 from hugh712/master
Make the matching rule of printer device path more flexible, make UDEV rules working with all systems
2 parents cf7a742 + aa8bed0 commit 5d4faec

2 files changed

Lines changed: 27 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/*", RUN+="udev-configure-printer remove %p"

udev/udev-configure-printer.c

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

1795+
static int
1796+
device_exists(char *device_path)
1797+
{
1798+
char full_path[100];
1799+
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);
1804+
1805+
// check the exist of this device
1806+
if (stat(full_path, &buffer) == 0){
1807+
exist = 1;
1808+
}
1809+
1810+
return exist;
1811+
}
1812+
1813+
static char*
1814+
compare_usb_uri(char *uri_store, char *uri_uevent)
1815+
{
1816+
return strstr(uri_uevent, uri_store);
1817+
}
1818+
17951819
static int
17961820
do_remove (const char *devaddr)
17971821
{
@@ -1830,8 +1854,8 @@ do_remove (const char *devaddr)
18301854
map = read_usb_uri_map ();
18311855
prev = &map->entries;
18321856
for (entry = map->entries; entry; entry = entry->next)
1833-
{
1834-
if (!strcmp (entry->devpath, devpath))
1857+
{
1858+
if (compare_usb_uri(entry->devpath, devpath) !=NULL && device_exists(entry->devpath) == -1)
18351859
{
18361860
uris = &entry->uris;
18371861
break;

0 commit comments

Comments
 (0)