Skip to content

Commit aa8bed0

Browse files
committed
Seperate device_exists function from compare_usb_uri.
Use strstr to search substring. Use snprintf to combine the device path. Do not skip ippusbxd printer in the rules
1 parent d1aab4e commit aa8bed0

2 files changed

Lines changed: 18 additions & 27 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{INTERFACE}=="7/1/*", ENV{INTERFACE}!="7/1/4", 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: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,40 +1791,31 @@ 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)
1794+
1795+
static int
1796+
device_exists(char *device_path)
17961797
{
1797-
int index = 0;
1798-
int subset = 1;
1799-
int exist = -1;
1800-
char *full_path = NULL;
1798+
char full_path[100];
18011799
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-
}
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);
18181804

18191805
// check the exist of this device
1820-
if (subset == 1 && stat(full_path, &buffer) == 0){
1821-
exist = 1;
1806+
if (stat(full_path, &buffer) == 0){
1807+
exist = 1;
18221808
}
18231809

1824-
free(full_path);
18251810
return exist;
18261811
}
18271812

1813+
static char*
1814+
compare_usb_uri(char *uri_store, char *uri_uevent)
1815+
{
1816+
return strstr(uri_uevent, uri_store);
1817+
}
1818+
18281819
static int
18291820
do_remove (const char *devaddr)
18301821
{
@@ -1864,7 +1855,7 @@ do_remove (const char *devaddr)
18641855
prev = &map->entries;
18651856
for (entry = map->entries; entry; entry = entry->next)
18661857
{
1867-
if (compare_usb_uri(entry->devpath, devpath))
1858+
if (compare_usb_uri(entry->devpath, devpath) !=NULL && device_exists(entry->devpath) == -1)
18681859
{
18691860
uris = &entry->uris;
18701861
break;

0 commit comments

Comments
 (0)