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

lp (-h) hostname option has to come before destination (-d) #357

Closed
debiantriage opened this issue Mar 25, 2022 · 9 comments
Closed

lp (-h) hostname option has to come before destination (-d) #357

debiantriage opened this issue Mar 25, 2022 · 9 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation priority-medium
Milestone

Comments

@debiantriage
Copy link

Debian user Paul Hutschemaekers has reported

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1008210

lp -d DESTINATION -h HOSTNAME FILENAME fails, whereas lp -h HOSTNAME -d DESTINATION FILENAME succeeds. I have reproduced this behaviour with 2.3.3op2 and 2.4.1op1 but not with 2.2.10-6.

--
Brian.

@tillkamppeter
Copy link
Member

This is due to the fact that CUPS' command line tools do not parse the complete command line before executing the command, but instead, parse each argument, one by one, and execute it. So in the first command line of your example it parses and executes -d DESTINATION first and fails as DESTINATION is not available on the local machine but only on the remote machine HOSTNAME. The second command line parses and executes -h HOSTNAME first and switches to HOSTNAME after that it parses and executes -d DESTINATION and succeeds to find DESTINATION, then being able to send FILENAME for printing.

This is the architecture of the tools which @michaelrsweet has chosen more than 22 years ago when he started developing CUPS. I do not know whether other command line tools of that time (and also of today) also work this way. Perhaps it was common that time at least.

More intuitive for a user would be to parse the full command line at first and then execute the whole thing.

@jsmeix
Copy link

jsmeix commented Mar 25, 2022

So the syntax in the lp man page is wrong (or at least misleading):
https://openprinting.github.io/cups/doc/man-lp.html

lp [ -E ] [ -U username ] [ -c ] [ -d destination[/instance] ] [ -h hostname[:port] ] ...

In general the sequence of the options is significant.
For example, the following commands are all different:

lpadmin -E -p queue,
lpadmin -p queue -E
lpadmin -E -p queue -E

but here the lpadmin man page describes it correctly.

@debiantriage
Copy link
Author

@tillkamppeter Thanks for the explanation. But note: either command works on Debian's CUPS 2.2.10-6+deb10u4. Where does that leave us?

@jsmeix A documentation bug then? (With lpadmin I understand the double use of -E lies way back in the history of CUPS).

@michaelrsweet
Copy link
Member

@tillkamppeter Parsing all arguments first would change behavior, not to mention making those programs significantly more complex.

@debiantriage The "-E" option to lpadmin goes back to System V's "lp" command (enable and accept jobs) while "-E" for the CUPS commands forces encryption to be used. So what happened for lpadmin was a bit of a compromise for consistency's sake...

As for "-h" working before or after, it is probably because the queue is accessible from both the default and external servers...

@debiantriage
Copy link
Author

@michaelrsweet I'll accept the behaviour and complexity argument. Will the documentation be altered to reflect the order -h, -d?

@zdohnal
Copy link
Member

zdohnal commented Mar 28, 2022

@debiantriage I've hit the similar issue with lpstat in RHEL - user was confused by order dependency - so the idea was to create a new subsection in manpages - 'Connect options' - so users can see those have to before other options.

So the synopsis would be:

lpadmin [ connect options] -d destination
lpadmin [ connect options ] -p destination
...

WDYT?

@michaelrsweet
Copy link
Member

@zdohnal I'd call them "connection options" or (better?) "server options". The point is that "-h" and "-E" need to come before other options.

@debiantriage
Copy link
Author

@zdohnal A good idea. I would incline slightly towards Server options.

--
Brian.

@zdohnal zdohnal self-assigned this Apr 1, 2022
@zdohnal zdohnal added bug Something isn't working documentation Improvements or additions to documentation priority-medium labels Apr 1, 2022
@zdohnal zdohnal added this to the 2.4.2 milestone Apr 1, 2022
@michaelrsweet
Copy link
Member

[master 4d6787b] Update man pages for -h option (Issue #357)

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

No branches or pull requests

5 participants