Make the matching rule of printer device path more flexible#183
Make the matching rule of printer device path more flexible#183tillkamppeter merged 2 commits intoOpenPrinting:masterfrom
Conversation
hugh712
commented
Sep 30, 2020
- 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.
… systems. * Make the matching rule of printer device path more flexible.
|
Hi @hugh712 , I'm sorry for not getting to your issue yesterday, but I managed to look into the code on your fork and I would like to comment on it tomorrow. Anyway, thank you for the PR! |
| full_path = (char *) malloc(strlen(uri_store) + 4); | ||
| memset(full_path, 0, sizeof(full_path)); | ||
| strcpy(full_path, "/sys"); | ||
| strcat(full_path, uri_store); |
There was a problem hiding this comment.
You can do this with single snprintf() call and it will take care of NULL terminator too. Or Am I missing something?
There was a problem hiding this comment.
that's fine, I will do it
| // check the exist of this device | ||
| if (subset == 1 && stat(full_path, &buffer) == 0){ | ||
| exist = 1; |
There was a problem hiding this comment.
I would propose to move it to a separate function - it is against the name of function. The name indicates it will compare the uris, not checking its existence.
device_exists() can be an additional argument in if (compare_usb_uri()) condition. IMO it causes no harm if it is run even on devices which aren't substrings, but they match will usb uri from udev event. What do you think?
|
|
||
| // check whether it's a substring | ||
| full_path = (char *) malloc(strlen(uri_store) + 4); | ||
| memset(full_path, 0, sizeof(full_path)); | ||
| strcpy(full_path, "/sys"); | ||
| strcat(full_path, uri_store); |
There was a problem hiding this comment.
Plus I would move this to separate function - device_exists().
| // check whether it's a substring | ||
| full_path = (char *) malloc(strlen(uri_store) + 4); |
There was a problem hiding this comment.
Please comment the magic number in a comment, thank you!
| { | ||
| if (compare_usb_uri(entry->devpath, devpath)) |
There was a problem hiding this comment.
What about using strstr() instead of strcmp(). It will do the trick with finding an exact match and substring too.
Then you can add device_exists() to check if the device really exists and move the code I marked into it.
| 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" | ||
| # Low-level USB device remove trigger | ||
| ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p" | ||
| ACTION=="remove", SUBSYSTEM=="usb", ENV{INTERFACE}=="7/1/*", ENV{INTERFACE}!="7/1/4", RUN+="udev-configure-printer remove %p" |
There was a problem hiding this comment.
Would you mind explaining about values of env variable INTERFACE? Why value 7/1/4 is omitted? It would be good to have a brief comment in the code too.
There was a problem hiding this comment.
seems this is a trick from ubuntu, because all of the ippusbxd protocol (7/1/4) devices has been taken care by another rules, I think let's just leave this file as the original status, I will revert this one.
There was a problem hiding this comment.
I will still keep ENV{INTERFACE}=="7/1/*" in this file, due to in systemd [0], it goes to default_end directly when removing action occurred, which meant IMPORT{builtin}="usb_id" will not be executed, so we have to use ENV{INTERFACE} when removing usb printer.
[0] https://github.com/systemd/systemd/blob/master/rules.d/50-udev-default.rules.in
|
Did you test the PR if it works? I tried to apply my suggestions into the code, but the print queue wasn't disabled - so I'm trying to find out whether I made a mistake or the design needs adjusting. |
Yes, I tried it and it works well |
Hi
@zdohnal, |
|
No problem. |
Use strstr to search substring. Use snprintf to combine the device path. Do not skip ippusbxd printer in the rules
|
Please help to review again, thanks :) |
|
Hi @hugh712 , I'm sorry I won't probably get to the review this week. Hope I'll manage at the beginning of the next. I'm sorry for inconvenience :( |
|
Wondering do you have some spare time to review this PR this week? :) |
|
Hi @hugh712 , I'm sorry, I haven't checked and tested it yet - I will not promise any exact date from now, but I have this PR on my TODO list. I'll give a heads-up when I get to this. I'm really sorry for inconvenience and still I'm grateful for the PR! |
|
no problem :) |
|
@zdohnal, the |
|
@hugh712, thanks for your contribution, I have merged your pull request now. |
|
Great!, thank you so much :) |
|
Thank you for merging the PR, Till! @hugh712 thanks for the PR! I was able to test it at last and it works. I'll do some minor changes regarding the code (spaces, use strstr directly...), but it looks good overall. Again, sorry for the delay. |