Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Printer Application with "autoadd" segfaults #89

Closed
tillkamppeter opened this issue Nov 23, 2020 · 12 comments
Closed

Calling Printer Application with "autoadd" segfaults #89

tillkamppeter opened this issue Nov 23, 2020 · 12 comments
Assignees
Labels
bug Something isn't working priority-high
Milestone

Comments

@tillkamppeter
Copy link
Contributor

Describe the bug
I am running the PostScript Printer Application as server. While it is running I run the command:

ps-printer-app autoadd

to automatically detect and add printers. The program makes the server logging the lines shown below and then segfaults. I get the same independent whether I have already set up a printer or not.

No core file got written.

Additional context
Log entries of the server in debug mode:

I [2020-11-23T21:28:39.897Z] [Client 32] Accepted connection from 'localhost'.
I [2020-11-23T21:28:39.897Z] [Client 32] POST http://localhost:0/ipp/system HTTP/1.1
I [2020-11-23T21:28:39.897Z] [Client 32] Continue
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request: IPP/2.0 request-id=1
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request: operation-attributes-tag
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request:   attributes-charset charset utf-8
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request:   attributes-natural-language naturalLanguage en-us
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request:   system-uri uri ipp://localhost/ipp/system
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers request:   requesting-user-name nameWithoutLanguage till
D [2020-11-23T21:28:39.897Z] papplSystemFindPrinter(system, resource="(null)", printer_id=0, device_uri="(null)")
D [2020-11-23T21:28:39.897Z] papplSystemFindPrinter: 0 printers.
D [2020-11-23T21:28:39.897Z] papplSystemFindPrinter: Returning (nil)(none)
I [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers successful-ok
I [2020-11-23T21:28:39.897Z] [Client 32] OK application/ipp 75
D [2020-11-23T21:28:39.897Z] [Client 32] Get-Printers response: IPP/2.0 request-id=1, status-code=successful-ok
D [2020-11-23T21:28:39.898Z] [Client 32] Get-Printers response: operation-attributes-tag
D [2020-11-23T21:28:39.898Z] [Client 32] Get-Printers response:   attributes-charset charset utf-8
D [2020-11-23T21:28:39.898Z] [Client 32] Get-Printers response:   attributes-natural-language naturalLanguage en-us
I [2020-11-23T21:28:40.522Z] [Client 32] Closing connection from 'localhost'.
@michaelrsweet michaelrsweet self-assigned this Nov 24, 2020
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Nov 24, 2020
@michaelrsweet
Copy link
Owner

@tillkamppeter Can you retry this with the current Github master code? And enable debugging (--enable-debug) so that you can get a backtrace if there is a crash?

@tillkamppeter
Copy link
Contributor Author

I have investigated the case now and observed the following:

If I add a printer manually via the web interface and select "Auto Detect" in the driver menu, the server calls ps_autoadd() to make the decision about the driver to use. There is no client process running.

If I have a server running and I want to automatically add all supported printers using the "autoadd" sub-command, I have a second instance of the Printer Application running, the one I fired up with the sub-command. This one works as a client for my server, sending IPP commands to make the server create a print queue. In this case the decision about which driver to use is made by the client calling ps_autoadd(), but the client did not create a system or at least run the system driver setup callback function (ps_setup()) before calling ps_autoadd(), so the driver list is empty and ps_autoadd() segfaults as I never have taken into account that ps_autoadd() is run with an empty driver list.

So there are two possibilities to fix the bug:

  1. The client needs to create a system or at least call the driver setup callback to assure that the driver repository of the Printer Application is set up as on the server and only after that call the auto-add callback.
  2. The client does not do any driver assignment decision but, instead simply sends an IPP command to the server that it sets up the discovered printer with the driver named "auto". The server already has the driver list readily available. If the printer is not supported, the auto-add callback on the server returns "false" and the server does not create a print queue.

I recommend (2), as

  • When going the (1) approach the client and the server can be of mis-matching versions or accessing different external driver files, ending up with mis-matching driver repository lists, and so the client can send a driver name to the server which does not exist there.
  • For (1) the client needs to create a driver list identical to the one that the server has already available, in case of very long driver lists this can be resource-consuming (time, memory). As we have the standard driver name "auto" on every Printer Application on which the "autoadd" subcommand works, we do not need to bother with driver lists on the client.

@michaelrsweet michaelrsweet added bug Something isn't working priority-high and removed investigating Investigating the issue labels Nov 29, 2020
@michaelrsweet michaelrsweet added this to the v1.0 milestone Nov 29, 2020
@michaelrsweet
Copy link
Owner

@tillkamppeter Option 2 is probably the right answer. I'll have a fix sometime today...

michaelrsweet added a commit that referenced this issue Nov 29, 2020
…oop`

(Issue #89)

Also fix an implementation bug - was looking printers up by their device IDs
and not by their URIs.
@michaelrsweet
Copy link
Owner

[master 5ad0cde] Fix a crash bug associated with the "autoadd" command for papplMainloop (Issue #89)

@tillkamppeter
Copy link
Contributor Author

I have built your GIT master and also added a crash guard to ps_autoadd() (not actually needed as the function is now run by the server), then rebuilt the Printer Application, killed and restarted the server and after that ran the command

$ ./ps-printer-app autoadd

No printer got created and the server has logged the following:

I [2020-11-29T17:52:00.422Z] [Client 23] Accepted connection from 'localhost'.
I [2020-11-29T17:52:00.423Z] [Client 23] POST http://localhost:0/ipp/system HTTP/1.1
I [2020-11-29T17:52:00.423Z] [Client 23] Continue
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request: IPP/2.0 request-id=1
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request: operation-attributes-tag
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request:   attributes-charset charset utf-8
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request:   system-uri uri ipp://localhost/ipp/system
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers request:   requesting-user-name nameWithoutLanguage till
D [2020-11-29T17:52:00.423Z] papplSystemFindPrinter(system, resource="(null)", printer_id=0, device_uri="(null)")
D [2020-11-29T17:52:00.423Z] papplSystemFindPrinter: Returning (nil)(none)
I [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers successful-ok
I [2020-11-29T17:52:00.423Z] [Client 23] OK application/ipp 75
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers response: IPP/2.0 request-id=1, status-code=successful-ok
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers response: operation-attributes-tag
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers response:   attributes-charset charset utf-8
D [2020-11-29T17:52:00.423Z] [Client 23] Get-Printers response:   attributes-natural-language naturalLanguage en-us
I [2020-11-29T17:52:00.925Z] [Client 23] POST http://localhost:0/ipp/system HTTP/1.1
I [2020-11-29T17:52:00.925Z] [Client 23] Continue
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request: IPP/2.0 request-id=2
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request: operation-attributes-tag
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   attributes-charset charset utf-8
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   system-uri uri ipp://localhost/ipp/system
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   printer-service-type keyword print
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request: printer-attributes-tag
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   printer-name nameWithoutLanguage HP OfficeJet Pro 8730 \\[08C229] (DNS-SD Network Printer)
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   printer-device-id textWithoutLanguage MFG:HP;MDL:OfficeJet Pro 8730;CMD:PS,PCL,PCLXL,JPEG;
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   smi2699-device-command keyword auto
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer request:   smi2699-device-uri uri dnssd://HP%5C032OfficeJet%5C032Pro%5C0328730%5C032%5C09108C229%5C093._pdl-datastream._tcp.local/
D [2020-11-29T17:52:00.925Z] papplSystemFindPrinter(system, resource="(null)", printer_id=0, device_uri="(null)")
D [2020-11-29T17:52:00.925Z] papplSystemFindPrinter: Returning (nil)(none)
I [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer client-error-attributes-or-values-not-supported (Unsupported smi2699-device-uri uri value.)
I [2020-11-29T17:52:00.925Z] [Client 23] OK application/ipp 255
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response: IPP/2.0 request-id=2, status-code=client-error-attributes-or-values-not-supported
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response: operation-attributes-tag
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response:   attributes-charset charset utf-8
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response:   status-message textWithoutLanguage Unsupported smi2699-device-uri uri value.
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response: unsupported-attributes-tag
D [2020-11-29T17:52:00.925Z] [Client 23] Create-Printer response:   smi2699-device-uri uri dnssd://HP%5C032OfficeJet%5C032Pro%5C0328730%5C032%5C09108C229%5C093._pdl-datastream._tcp.local/
I [2020-11-29T17:52:04.965Z] [Client 23] POST http://localhost:0/ipp/system HTTP/1.1
I [2020-11-29T17:52:04.965Z] [Client 23] Continue
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request: IPP/2.0 request-id=3
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request: operation-attributes-tag
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   attributes-charset charset utf-8
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   system-uri uri ipp://localhost/ipp/system
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   printer-service-type keyword print
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request: printer-attributes-tag
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   printer-name nameWithoutLanguage HP OfficeJet Pro 8730 (Network Printer HP08C229)
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   printer-device-id textWithoutLanguage MFG:HP;MDL:HP OfficeJet Pro 8730;CMD:PCL5c,PCLXL,POSTSCRIPT,NATIVEOFFICE,PDF,PCL3GUI,PCL3,PJL,Automatic,JPEG,PCLM,AppleRaster,PWGRaster,802.11,802.3,DESKJET,DYN;CLS:PRINTER;DES:D9L20A;CID:HPIJVIPAV9;LEDMDIS:USB#FF#CC#00,USB#FF#04#01;MCT:MF;MCL:DI;MCV:3.0;SN:CN783F60W1;S:038080C484100001005800800004418001e4518001e4618001441180014;Z:05000009000009000009000009000009,12000,17000000000000000000000000000000,181;
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   smi2699-device-command keyword auto
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer request:   smi2699-device-uri uri snmp://HP08C229
D [2020-11-29T17:52:04.965Z] papplSystemFindPrinter(system, resource="(null)", printer_id=0, device_uri="(null)")
D [2020-11-29T17:52:04.965Z] papplSystemFindPrinter: Returning (nil)(none)
I [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer client-error-attributes-or-values-not-supported (Unsupported smi2699-device-uri uri value.)
I [2020-11-29T17:52:04.965Z] [Client 23] OK application/ipp 174
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response: IPP/2.0 request-id=3, status-code=client-error-attributes-or-values-not-supported
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response: operation-attributes-tag
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response:   attributes-charset charset utf-8
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response:   status-message textWithoutLanguage Unsupported smi2699-device-uri uri value.
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response: unsupported-attributes-tag
D [2020-11-29T17:52:04.965Z] [Client 23] Create-Printer response:   smi2699-device-uri uri snmp://HP08C229
I [2020-11-29T17:52:04.970Z] [Client 23] POST http://localhost:0/ipp/system HTTP/1.1
I [2020-11-29T17:52:04.970Z] [Client 23] Continue
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request: IPP/2.0 request-id=4
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request: operation-attributes-tag
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   attributes-charset charset utf-8
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   system-uri uri ipp://localhost/ipp/system
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   printer-service-type keyword print
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request: printer-attributes-tag
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   printer-name nameWithoutLanguage HP OfficeJet Pro 8730 (USB)
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   printer-device-id textWithoutLanguage MFG:HP;MDL:HP OfficeJet Pro 8730;CMD:PCL5c,PCLXL,POSTSCRIPT,NATIVEOFFICE,PDF,PCL3GUI,PCL3,PJL,Automatic,JPEG,PCLM,AppleRaster,PWGRaster,802.11,802.3,DESKJET,DYN;CLS:PRINTER;DES:D9L20A;CID:HPIJVIPAV9;LEDMDIS:USB#FF#CC#00,USB#FF#04#01;MCT:MF;MCL:DI;MCV:3.0;SN:CN783F60W1;S:038080C484100001005800800004418001e4518001e4618001441180014;Z:05000009000009000009000009000009,12000,17000000000000000000000000000000,181;
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   smi2699-device-command keyword auto
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer request:   smi2699-device-uri uri usb://HP/HP%20OfficeJet%20Pro%208730?serial=CN783F60W1
D [2020-11-29T17:52:04.970Z] papplSystemFindPrinter(system, resource="(null)", printer_id=0, device_uri="(null)")
D [2020-11-29T17:52:04.970Z] papplSystemFindPrinter: Returning (nil)(none)
I [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer client-error-attributes-or-values-not-supported (Unsupported smi2699-device-uri uri value.)
I [2020-11-29T17:52:04.970Z] [Client 23] OK application/ipp 213
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer response: IPP/2.0 request-id=4, status-code=client-error-attributes-or-values-not-supported
D [2020-11-29T17:52:04.970Z] [Client 23] Create-Printer response: operation-attributes-tag
D [2020-11-29T17:52:04.971Z] [Client 23] Create-Printer response:   attributes-charset charset utf-8
D [2020-11-29T17:52:04.971Z] [Client 23] Create-Printer response:   attributes-natural-language naturalLanguage en-us
D [2020-11-29T17:52:04.971Z] [Client 23] Create-Printer response:   status-message textWithoutLanguage Unsupported smi2699-device-uri uri value.
D [2020-11-29T17:52:04.971Z] [Client 23] Create-Printer response: unsupported-attributes-tag
D [2020-11-29T17:52:04.971Z] [Client 23] Create-Printer response:   smi2699-device-uri uri usb://HP/HP%20OfficeJet%20Pro%208730?serial=CN783F60W1
ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error
ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error
ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error
I [2020-11-29T17:52:04.976Z] [Client 23] Closing connection from 'localhost'.

The printer is again the HP OfficeJet Pro 8730, connected via both USB and network.
Note that the errors

ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error
ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error
ps-printer-app: Unable to get IEEE-1284 device ID: Input/Output Error

are most probably not the culprit, I get them on every device auto-discovery run of a Printer Application but the device ID is always correctly read out or synthesized.

@michaelrsweet
Copy link
Owner

@tillkamppeter Looks like the device URI schemes weren't registered yet...

[master 39c81ff] Make sure standard URI schemes are added (Issue #89)

@tillkamppeter
Copy link
Contributor Author

Thanks. We are coming closer.

Now printers get actually auto-generated, but for my one single printer I get three queues, for the three ways it got autodetected: DNS-SD, SNMP, and USB. You should add some mechanism to detect whether various auto-discovery entries come from the same physical device. Best way is the UUID in the printer hardware. I do not know ehether you can obtain it on all 3 auto-discovery methods, for network you can also check IP address, host name, and perhaps even MAC address. Also the printer's serial number is a candidate.

I suggest priorities between auto-discovery/connection types, for example USB has highest priority, as it is most secure and if someone connects a printer by both USB and network it can be more than belt and suspenders, perhaps the higher security of USB for the local user but also sharing the device on the network. After that I would suggest DNS-SD, as it is more sophisticated than SNMP, or perhaps also give the user a possibility to configure.

@michaelrsweet
Copy link
Owner

@tillkamppeter There is absolutely no way for us to detect duplicate network printers (between the different protocols) short of resolving the addresses which will wake the printers up.

My solution will be simple: only auto-add USB printers. Network printers MUST be added manually (or you can provide your own autoadd-network command and deal with the consequences yourself...)

@tillkamppeter
Copy link
Contributor Author

So let us do as follows then:

For USB, while the Printer Application is running, we let it somehow use UDEV or so to auto-detect when there is a USB printer connected and if so but no queue for this printer is already there, create it. If a queue is there enable the queue on appearing and disable (but not remove) on disappearing of the printer. This is probably all what PR #36 is about. So also newly connected USB printers get automatically set up when the Printer Application is alreasy running.

The "autoadd" subcommand can stay as it is and output a warning on the terminal if it has set up more than one printer, telling the user to visit the web interface and remove the unwished ones. Anyway, the command should always tell the user on the terminal how many printers it has set up. Important is for developers of Printer Application Snaps to not call it automatically after firing up the server. The Printer Application running as server should have PR #36 implemented and so automatically set up USB printers.

@michaelrsweet
Copy link
Owner

@tillkamppeter Any long-term monitoring/auto-add/auto-pause/auto-resume functionality needs to be managed separately, and honestly since the snap hotplug functionality is still non-existent I'm not in a hurry to add it. This is not something that all printer applications will have enabled by default.

@tillkamppeter
Copy link
Contributor Author

Hotplug inside Snaps is possible. I will look for some sample code.

@michaelrsweet
Copy link
Owner

@tillkamppeter Note that I'm still tracking the hot-plug functionality via PR #36, and my goal is to support both USB and DNS-SD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high
Projects
None yet
Development

No branches or pull requests

2 participants