Skip to content

Make the matching rule of printer device path more flexible#183

Merged
tillkamppeter merged 2 commits intoOpenPrinting:masterfrom
hugh712:master
Nov 2, 2020
Merged

Make the matching rule of printer device path more flexible#183
tillkamppeter merged 2 commits intoOpenPrinting:masterfrom
hugh712:master

Conversation

@hugh712
Copy link
Copy Markdown
Contributor

@hugh712 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.
@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Sep 30, 2020

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!

Copy link
Copy Markdown
Member

@zdohnal zdohnal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hugh712 ,

I have a following comments about the code, would you mind looking into them?

Thank you in advance!

Zdenek

Comment thread udev/udev-configure-printer.c Outdated
full_path = (char *) malloc(strlen(uri_store) + 4);
memset(full_path, 0, sizeof(full_path));
strcpy(full_path, "/sys");
strcat(full_path, uri_store);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this with single snprintf() call and it will take care of NULL terminator too. Or Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, I will do it

Comment thread udev/udev-configure-printer.c Outdated
Comment on lines +1819 to +1821
// check the exist of this device
if (subset == 1 && stat(full_path, &buffer) == 0){
exist = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread udev/udev-configure-printer.c Outdated
Comment on lines +1805 to +1810

// 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus I would move this to separate function - device_exists().

Comment thread udev/udev-configure-printer.c Outdated
Comment on lines +1806 to +1807
// check whether it's a substring
full_path = (char *) malloc(strlen(uri_store) + 4);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment the magic number in a comment, thank you!

Comment thread udev/udev-configure-printer.c Outdated
Comment on lines +1866 to +1867
{
if (compare_usb_uri(entry->devpath, devpath))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread udev/70-printers.rules Outdated
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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Oct 6, 2020

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.

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 6, 2020

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

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 6, 2020

Hi @hugh712 ,

I have a following comments about the code, would you mind looking into them?

Thank you in advance!

Zdenek

Hi

Hi @hugh712 ,

I have a following comments about the code, would you mind looking into them?

Thank you in advance!

Zdenek

@zdohnal,
Hi, I have limited hardware access this week,
will work on it once I have the hardware, many thanks :)

@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Oct 6, 2020

No problem.

Use strstr to search substring.
Use snprintf to combine the device path.
Do not skip ippusbxd printer in the rules
@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 13, 2020

@zdohnal,

Please help to review again, thanks :)

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 13, 2020

@zdohnal,

and please help to link this PR to the issue[0], thanks.

[0] #182

@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Oct 15, 2020

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 :(

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 21, 2020

@zdohnal,

Wondering do you have some spare time to review this PR this week? :)

@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Oct 21, 2020

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!

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Oct 21, 2020

no problem :)

@tillkamppeter
Copy link
Copy Markdown
Member

@zdohnal, the ENV{INTERFACE}!="7/1/4" is to not treat interfaces which are for IPP-over-USB, as they are handled separately by the ipp-usb or ippusbxd daemon. They cannot be used by the "usb" backend of CUPS (uses 7/1/1 and 7/1/2) or the "hp" backend of HPLIP (uses 7/1/3).

@tillkamppeter tillkamppeter merged commit 5d4faec into OpenPrinting:master Nov 2, 2020
@tillkamppeter
Copy link
Copy Markdown
Member

@hugh712, thanks for your contribution, I have merged your pull request now.
If anyone finds corener cases which are not covered, please post an issue.

@hugh712
Copy link
Copy Markdown
Contributor Author

hugh712 commented Nov 3, 2020

Great!, thank you so much :)

@zdohnal
Copy link
Copy Markdown
Member

zdohnal commented Nov 3, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants