From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4db,8f93d331bbb31b96,start X-Google-Attributes: gid10d4db,public X-Google-ArrivalTime: 1993-05-26 01:53:40 PST Newsgroups: comp.os.linux.announce Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!wupost!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu From: mccauleyba@vax1.bham.ac.uk (Brian McCauley) Subject: Linux lpd FAQ Message-ID: <1993May25.130211.26830@klaava.Helsinki.FI> Followup-To: comp.os.linux Keywords: printer daemon, lpd, FAQ, documentation Sender: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) Organization: University of Birmingham Date: Tue, 25 May 1993 13:02:11 GMT OK here's the first draft of the lpd-FAQ. Now I'm going to set about tidying up the layout so that it can sit along side the Linux FAQ with pride. Please comment on this. I hope everything is correct but a lot of it is empirical or hearsay. ================================================================== What is _the_ Linux lpr/lpd ? As far as there is a definitive Linux version of anything _the_ Linux lpr/lpd is Ross Biro's port of the BSD sources (so if you're used to AT&T's you'll find some differences). Ross's binaries and the diffs are found in: tsx-11.mit.edu:pub/linux/binaries/usr.bin/lpr.tar.Z sunsite.unc.edu:pub/Linux/system/Daemons/lpr.tar.Z The SLS file lpr.tgz on disk b2 contains the same stuff. In addition to the standard BSD lpr capabilities this package also has better support for serial printers (but I've heard that it still doesn't work). Unfortunately Ross's diffs aren't against the latest BSD sources (by about 3 years, '88 vs '91). If someone knows where the '88 sources are, can they tell me so that I can include that information. bir7@leland.stanford.edu no longer appears to be a valid e-mail address for Ross. It's probably a good idea for someone to port a new version of lpr/lpd but since the sources have been reorganised since Ross Biro's port it's not going to be trivial to include his patches. The BSD sources have unGNU things in their Makefiles so they don't compile ``out of the box''. Recent sources are all over the place. ftp.uu.net:systems/unix/bsd-sources/usr.sbin/lpr src.doc.ic.ac.uk:unix/bsd-sources/usr.sbin/lpr to name but two. ================================================================== How do I get lpr to work properly other than for root? Where do the files go and what should their permissions be? Put /usr/etc/lpd& in your /etc/rc or /etc/rc.local Set the group fields of the file permissons /ownership as follows: -rwxr-s--- 1 root daemon 37892 Nov 19 23:32 /usr/etc/lpd -rwx--s--x 1 root daemon 21508 Nov 19 23:32 /usr/bin/lpc -rws--s--x 1 root daemon 17412 Nov 19 23:32 /usr/bin/lpq -rwx--s--x 1 root daemon 17412 Nov 19 23:32 /usr/bin/lpr -rwx--s--x 1 root daemon 17412 Nov 19 23:32 /usr/bin/lprm ...and for each of the spool directories listed in the sd fields of /etc/printcap... /usr/spool/lp1: total 5 drwxrwxr-x 2 root daemon 1024 May 18 23:00 . drwxr-xr-x 11 root root 1024 Feb 19 20:56 .. -rw-rw-r-- 1 root daemon 4 May 18 23:00 .seq -rw-rw-r-- 1 root daemon 18 May 18 23:00 lock -rw-rw-r-- 1 root daemon 25 May 18 23:00 status Note these 3 files are created by lpr and lpd so if you've never run these they could be missing so touch them into being. Some of these permissions may be overkill so don't be surprised if your system works with different permissions. Alternative approach: just make lpc, lpr and lprm setuid(root) then you can forget the file permissions on the spool queues! You're free to choose different directories for the executables on your system. The master lpd lock file which is always in /usr/spool/ so you must have one of those but you needn't necessarily keep your spool queues there. The main configuration file is /usr/etc/printcap. The README says hosts.equiv and hosts.lpd files are looked for in /etc/inet but this is in fact may depend on the version of libc.so. The permissions on printcap, hosts.lpd and hosts.equiv are not important (they must be readable by root - but then all files are!). =================================================================== Why /usr/etc rather than /etc? For various reasons including the difficulties of fsck'ing / some people like to put all things that aren't needed during bootstrap in /usr so that / is as small as possible. For an simple (if untidy) life: mv /etc/inet/* /usr/etc/* /etc rmdir /etc/inet /usr/etc ln -s ../etc /usr/etc ls -s . /etc/inet ================================================================== Where do I get a printcap for a xxxxx? This question is essentially meaningless - see next question. ================================================================== What is the content of /usr/etc/printcap? Given the similarity in appearence and name between /etc/termcap and /etc/printcap one could be forgiven for assuming that they contain analogous infomation. This is not the case. Whereas termcap contains informations about terminal *types* - (mostly escape seqences) printcap contains information about *specific* printers (like the directory that holds the spool queue and the device name of the printer). The information about a printer's cababilities are held in the various filters which are programs called by lpd to drive the printer. /etc/printcap simply gives the locations of these filters. For details RTFM(printcap). ================================================================== What is the format of a /usr/etc/printcap? Ideally RTFM(termcap) but since most people don't have TFM(termcap) here are the essentials. Lines staring # are comments (as you might have guessed). For each printer usable from the lpr command on your system there is one logical line in the file. For the sake of readabiliy each logical line may be spread over several physical lines by making the last character on all but the last physical line a backslash. Each logic line has the following format: name1|name2|name3:string_capability=string:\ :numeric_capability#number:boolean_capability: The leading spaces and colon on the second line are for readability only. A printer can have as many names as you like but conventionally the final name is used as a longhand description of the printer. (Still people are free to say `lpr -P "Fred's grotty teletype"' if that's the description you've given.) The list of capabilities can be as long as needed and the order is not significant. Each ``capability'' is denoted by a two (or three) character code. (The name ``capability'' comes form the file format's termcap heritage - parameter would be a more sensible term.) Cababilities having string value and have a = delimiter between the capability name and the value while those having a numeric value use a #. Boolean ``capablilties'' are true if they appear in the list and false if they do not. Example: lp|bam|BAM's Epson FX-80:lp=/dev/lp1:sd=/usr/spool/lp1:sh:mx#0:\ :df=/usr/local/lib/magic-filter/lp.df:\ :if=/usr/local/lib/magic-filter/lp.if: Name is lp (this is the printer that lpr uses by default). It's also known as bam or "BAM's Epson FX-80". The printer is on /dev/lp1 (aka AT-bus LPT1:). I don't want a burst page. I don't want a file length limit. Files queued by `lpr -d' are passed through /usr/local/lib/magic-filter/epson-dvi-or-ps and those queued by `lpr' through /usr/local/magic-filter/magic-filter. See also the next question. ================================================================== My /usr/etc/printcap looks identical to someone else's but it doesn't work - why? See if lpc stat reports a printer called ` :'. The last character on a continued line must be a \. If there are whitespace characters after the \ then it doesn't register the next line as a continuation. ================================================================== How do I prevent this? Unix terminates each line of a file with a linefeed but not a carriage return. Some printers can be set to treat LF as CRLF, others can't. If yours can then do simply do that. If the printer cannot be fixed create a shell script filter that reads: #!/bin/sh if [ $1 = -c ]; then cat else sed -e s/$/^M/ fi echo -ne \\f where ^M is a carriage return character not a ^ followed by a M. To type ^M in emacs use the sequence C-q C-m. Conventionally this script is called /usr/lib/lpf. Alternatively your printer may have an escape sequence that will set the way it handles linefeed characters. A simple filter that uses an `echo -ne' command to send this sequence may be appropriate. #!/bin/sh # Filter for HP printers to treat LF as CRLF echo -ne \\033&k2G cat echo -ne \\f ====================================================================== How do I get my printer to go back to the default font after each printout? Define the `tr' ``capability'' to be your printer's font reset command. Assuming princap follows termcap's convention you use \E \r \n \t and ^H etc. for ascii-values 27, 13, 10, 9, 8 etc. If you want to send : ^ or \ you put \: \^ or \\ respectively. This may not work if a printout crashes in the middle of an escape sequence - putting a lot of ^@ on the front but this probably won't be enough it you were printing raster graphics when the filter died. ======================================================================== How do I prevent a formfeed at the end of every printout? If you don't have an `if' then lpd will automatically put a formfeed at the end of each file. If you're using a filter then it's up to the filter to decide if it wants to put a formfeed. To disable formfeed completely if you don't have an `if' put :ff=: in your /usr/etc/printcap. But please note this suppresses the formfeed that would usually be printed if the filter dies. If you want formfeeds after text printouts but not on printouts printed with `lpr -l' then create the following `if' filter: #!/bin/sh cat if [ "$1" != -c ]; then echo -ne \\f fi If you want a formfeed after `lpr -l' to be optional you can misuse the `-i' switch to suppress the formfeed with the following trick (after all `lpr -i -l' would usually not be implemented). #!/bin/sh cat # use lpr -i -l to print raw without trailing formfeed if [ "$1" != -c -o "$4" = -i0 ]; then echo -ne \\f fi ====================================================================== How do I get burst/banner pages? For a simple text printer and a simple banner simply take :sh: out of the printcap record. If you want to prevent the banner comming out in whatever font was last used on the printer then define the `tr' ``capability'' to be your printer's font reset command. If you want a fancy banner leave :sh: in the printcap and make each of your filters print the banner. All the information to put on the banner is included in the filter's positional parameters. RTFM(printcap) for details. [ If you're using 's magic-filter package then put the code to print the banners in the config script. ] ====================================================================== Why do files with a lot of graphics get truncated? Usually because you've got a limit set on the maximum size file that can sit in the spool queue. Put `mx#0' in your printcap. ====================================================================== Why doesn't `lpr -i' work? To get lpr -i to work you need a filter istalled as `if' that implements it. The -i switch is simply passed on by lpd to the filter. There is such a filter called /usr/lib/lpf that can be opdtained from bsd sources archives in the directory bsd-source/lpr/filters. ====================================================================== Why doesn't `lpr -p' work? Because its broken. lpd always thinks that the printer is 0 characters wide regardless of what printcap says. ====================================================================== Why does lprm say `too many users'? This was a bug in the C library in the scandir() function which failed when an unsorted directory list was requested. This has been fixed now so just get a new libc.so. Alternatively there is a lprm with a workround (by toy@soho.crd.ge.com) in: sunsite.unc.edu:/pub/Linux/system/Daemons/lprm-fix.tar.z ====================================================================== Why does lpc complain that it hasn't stopped a daemon? There's one lpd that runs all the time and it spawns off children to handle each printer as needed. These children leave lock files lying about so lpc thinks that they are still running and tries to kill them. This is probably a bug but it's not serious. ===================================================================== Network printing? To print on the printer "foo" connected to the machine "bar.baz.net" from the machine "mine.baz.net" you put an entry like this in your /etc/printcap (on mine.baz.net): foo:lp=:rm=bar.baz.net:rp=foo:sd=/usr/lpd/spool/foo: and, of course, create the spool directory /usr/lpd/spool/foo. There's no point specitying filters and the like in mine.baz.net:/etc/printcap as it's the one in bar.baz.net:/etc/printcap that will get used. On the machine bar.baz.foo, you need to put "mine.baz.net" on a line by itself in either /etc/hosts.equiv or /etc/hosts.lpd; note that putting it in /etc/hosts.equiv will allow for unauthenticated logins as well as printing. /etc/hosts.lpd is printing only. [ Editors note: I realise there are more questions about net printing but I don't know them. If you find any let me know (with answers if possible) ] ===================================================================== Which /dev file is my printer? On an XT LPT1: becomes /dev/lp0 (major=6, minor=0), on an AT LPT1: becomes /dev/lp1 (major=6, minor=1). ==================================================================== When the kernel boots it says `using polling driver,' is there an interrupt driven driver? Yes the latest kernels support parrallel port IRQs but to enable them you must use `lpcntl'. If your printer is AT port LPT1: using IRQ 7 put: /etc/lpcntl /dev/lp1 7 in your /etc/rc. If you don't have lpcntl get it from: tsx-11.mit.edu:/pub/Linux/BETA/lp/lpirq.4.tar.Z ===================================================================== How do I write filters? Filters are just programs (so they must have execute permission), for details RTFM(printcap). If you want to write a shell script filter it must have a #!/bin/sh header. lpd filters are not necessarily true filters in that they may assume that their standard input is a file and perform lseek() operations on it. I'm not sure that such filters are strictly conforming but they seem to work OK. It's easier to debug filters if you test them in an immediate shell before you install them. To do this: my-new-filter /dev/lp1 Here for example is my Epson FX-80 dvi filter: #!/bin/sh /usr/TeX/bin/dvips -f | \ /usr/bin/gs -q -sDEVICE=eps9high -r120x216 -dNOPAUSE -sOutputFile=- - ====================================================================== I've written a filter in shell script which works OK when I use it from the shell prompt but fails when I tell lpd to use it? You may need a #!/bin/sh header. You may also need to set PATH within the script since the daemon's PATH may not have everything you need. ====================================================================== When should I define an `of' filter? Never. (Well strictly speaking there are circumstances but you're unlikey to meet them until you're so familar with lpd that you won't need this FAQ.) ====================================================================== Where do I get filters for given printers? >>From BSD source archives (I think). [Editors note: I need a better answer here ]. If you already have a program to print say DVI on your printer then making it into a filter is usually trivial - see this FAQ. Text mode filters are trivial too (see this FAQ) unless you want lpr to have a choice of fonts in which case they are slightly harder than trivial. You will probably want to insert and `echo -ne' command at the beginning and end of your filter to set up the font etc to your liking. ====================================================================== The set of filters supported by lpd seem strange - why aren't there filters for Postscript, GIF, TIFF and so on? History. You can of course use any of the filters (with the possible exception of the default filter) for any reason. If you're never going to use Benson Varian raster files you could use the -v switch for GIF files. To avoid running out of possible types use magic filters. ======================================================================== What are magic filters? Magic filters deduce their input files' types from `magic numbers' (distictive byte patterns at particular offsets). Magic filters are usually perl scripts, shell scripts or C programs that simply identify the file type then call the appropriate non-magic filter. [ Blatent plug:- ] I (B.A.McCauley@bham.ac.uk) have a generic magic filter bash script that selects the right filter to use based on the output of the `file' command. With my magic ``dvi'' filter I can do things like: lpr -d file1.dvi file2.div.Z file3.ps file4.ps.z This is not yet on any anon-ftp sites so e-mail me for a copy. Once its stable I'll upload it. Magic filters should never specified as `of' as the output filter only gets called once if a number of files are printed without a gap. Magic filters as `if' can also be a problem as they may prevent you, say, _listing_ a PostScript file. ====================================================================== -- \\ ( ) No Bullshit! | Email: B.A.McCauley@bham.ac.uk . _\\__[oo from | Voice: +44 21 471 3789 (home) .__/ \\ /\@ /~) /~[ /\/[ | +44 21 627 2171 (work) . l___\\ /~~) /~~[ / [ | Fax: +44 21 627 2175 (work) # ll l\\ ~~~~ ~ ~ ~ ~ | Snail: 197 Harborne Lane, B29 6SS, UK ###LL LL\\ (Brian McCauley) | ICBM: 52.5N 1.9W