4.2BSDLinePrinterSpoolerManual RevisedJuly27,1983 RalphCampbell ComputerSystemsResearchGroup ComputerScienceDivision DepartmentofElectricalEngineeringandComputerScience UniversityofCalifornia,Berkeley Berkeley,CA94720 (415)642-7780 ABSTRACT Thisdocumentdescribesthestructureandinstallationprocedureforthe lineprinterspoolingsystemdevelopedforthe4.2BSDversionoftheUNIX*operatingsystem. 1.Overview Thelineprintersystemsupports: •multipleprinters, •multiplespoolingqueues, •bothlocalandremoteprinters,and •printersattachedviaseriallineswhichrequirelineinitializationsuchasthebaudrate. RasteroutputdevicessuchasaVarianorVersatec,andlaserprinterssuchasanImagen,arealso supportedbythelineprintersystem. Thelineprintersystemconsistsmainlyofthefollowingfilesandcommands: /etc/printcapprinterconfigurationandcapabilitydatabase /usr/lib/lpdlineprinterdaemon,doesalltherealwork /usr/ucb/lprprogramtoenterajobinaprinterqueue /usr/ucb/lpqspoolingqueueexaminationprogram /usr/ucb/lprmprogramtodeletejobsfromaqueue /etc/lpcprogramtoadministerprintersandspoolingqueues /dev/printersocketonwhichlpdlistens Thefile/etc/printcapisamasterdatabasedescribinglineprintersdirectlyattachedtoamachine and,also,printersaccessibleacrossanetwork.Themanualpageentryprintcap(5)providesthe ultimatedefinitionoftheformatofthisdatabase,aswellasindicatingdefaultvaluesforimportantitemssuchasthedirectoryinwhichspoolingisperformed.Thisdocumenthighlightsthe importantinformationwhichmaybeplacedprintcap. *UNIXisatrademarkofBellLaboratories.

-2-2.Commands 2.1.lpd−lineprinterdameon Theprogramlpd(8),usuallyinvokedatboottimefromthe/etc/rcfile,actsasamaster serverforcoordinatingandcontrollingthespoolingqueuesconfiguredintheprintcapfile.When lpdisstarteditmakesasinglepassthroughtheprintcapdatabaserestartinganyprinterswhich havejobs.Innormaloperationlpdlistensforservicerequestsonmultiplesockets,oneinthe UNIXdomain(named‘‘/dev/printer’’)forlocalrequests,andoneintheInternetdomain(under the‘‘printer’’servicespecification)forrequestsforprinteraccessfromoffmachine;seesocket(2) andservices(5)formoreinformationonsocketsandservicespecifications,respectively.Lpd spawnsacopyofitselftoprocesstherequest;themasterdaemoncontinuestolistenfornew requests. Clientscommunicatewithlpdusingasimpletransactionorientedprotocol.Authentication ofremoteclientsisdonebasedonthe‘‘privilegeport’’schemeemployedbyrshd(8C)and rcmd(3X).Thefollowingtableshowstherequestsunderstoodbylpd.Ineachrequestthefirst byteindicatesthe‘‘meaning’’oftherequest,followedbythenameoftheprintertowhichit shouldbeapplied.Additionalqualifiersmayfollow,dependingontherequest. Request Interpretation ˆ Aprinter\n checkthequeueforjobsandprintanyfound ˆ Bprinter\n receiveandqueueajobfromanothermachine ˆ Cprinter[users...][jobs...]\nreturnshortlistofcurrentqueuestate ˆ Dprinter[users...][jobs...]\nreturnlonglistofcurrentqueuestate ˆ Eprinterperson[users...][jobs...]\nremovejobsfromaqueue Thelpr(1)commandisusedbyuserstoenteraprintjobinalocalqueueandtonotifythe locallpdthattherearenewjobsinthespoolingarea.Lpdeitherschedulesthejobtobeprinted locally,orinthecaseofremoteprinting,attemptstoforwardthejobtotheappropriatemachine. Iftheprintercannotbeopenedorthedestinationmachineisunreachable,thejobwillremain queueduntilitispossibletocompletethework. 2.2.lpq−showlineprinterqueue Thelpq(1)programworksrecursivelybackwardsdisplayingthequeueofthemachinewith theprinterandthenthequeue(s)ofthemachine(s)thatleadtoit.Lpqhastwoformsofoutput: inthedefault,short,formatitgivesasinglelineofoutputperqueuedjob;inthelongformatit showsthelistoffiles,andtheirsizes,whichcompriseajob. 2.3.lprm−removejobsfromaqueue Thelprm(1)commanddeletesjobsfromaspoolingqueue.Ifnecessary,lprmwillfirstkill offarunningdaemonwhichisservicingthequeue,restartingitaftertherequiredfilesare removed.Whenremovingjobsdestinedforaremoteprinter,lprmactssimilarlytolpqexceptit firstcheckslocallyforjobstoremoveandthentriestoremovefilesinqueuesoff-machine. 2.4.lpc−lineprintercontrolprogram Thelpc(8)programisusedbythesystemadministratortocontroltheoperationoftheline printersystem.Foreachlineprinterconfiguredin/etc/printcap,lpcmaybeusedto: •disableorenableaprinter, •disableorenableaprinter’sspoolingqueue, •rearrangetheorderofjobsinaspoolingqueue, •findthestatusofprinters,andtheirassociatedspoolingqueuesandprinterdameons.

-3-3.Accesscontrol Theprintersystemmaintainsprotectedspoolingareassothatuserscannotcircumvent printeraccountingorremovefilesotherthantheirown.Thestrategyusedtomaintainprotected spoolingareasisasfollows: •Thespoolingareaiswritableonlybyadaemonuserandspoolinggroup. •Thelprprogramrunssetuidrootandsetgidspooling.Therootaccessisusedtoreadanyfile required,verifyingaccessibilitywithanaccess(2)call.ThegroupIDisusedinsettingup properownershipoffilesinthespoolingareaforlprm. •Controlfilesinaspoolingareaaremadewithdaemonownershipandgroupownershipspooling.Theirmodeis0660.Thisinsurescontrolfilesarenotmodifiedbyauserandthatnouser canremovefilesexceptthroughlprm. •Thespoolingprograms,lpd,lpq,andlprmrunsetuidrootandsetgidspoolingtoaccessspool filesandprinters. •Theprinterserver,lpd,usesthesameverificationproceduresasrshd(8C)inauthenticating remoteclients.Thehostonwhichaclientresidesmustbepresentinthefile/etc/hosts.equiv, usedtocreateclustersofmachinesunderasingleadministration. Inpractice,noneoflpd,lpq,orlprmwouldhavetorunasuserrootifremotespoolingwere notsupported.Inpreviousincarnationsoftheprintersystemlpdransetuiddaemon,setgidspooling,andlpqandlprmransetgidspooling. 4.Settingup The4.2BSDreleasecomeswiththenecessaryprogramsinstalledandwiththedefaultline printerqueuecreated.Ifthesystemmustbemodified,themakefileinthedirectory /usr/src/usr.lib/lprshouldbeusedinrecompilingandreinstallingthenecessaryprograms. Therealworkinsettingupistocreatetheprintcapfileandanyprinterfiltersforprinters notsupportedinthedistributionsystem. 4.1.Creatingaprintcapfile Theprintcapdatabasecontainsoneormoreentriesperprinter.Aprintershouldhavea separatespoolingdirectory;otherwise,jobswillbeprintedondifferentprintersdependingon whichprinterdaemonstartsfirst.Thissectiondescribeshowtocreateentriesforprinterswhich donotconformtothedefaultprinterdescription(anLP-11styleinterfacetoastandard,band printer). 4.1.1.Printersonseriallines Whenaprinterisconnectedviaaserialcommunicationlineitmusthavetheproperbaud rateandterminalmodesset.ThefollowingexampleisforaDecWriterIIIprinterconnected locallyviaa1200baudserialline. lp|LA-180DecWriterIII:\ :lp=/dev/lp:br#1200:fs#06320:\ :tr=\f:of=/usr/lib/lpf:lf=/usr/adm/lpd-errs: Thelpentryspecifiesthefilenametoopenforoutput.Inthiscaseitcouldbeleftoutsince ‘‘/dev/lp’’isthedefault.Thebrentrysetsthebaudrateforthettylineandthefsentrysets CRMOD,noparity,andXTABS(seetty(4)).Thetrentryindicatesaform-feedshouldbe printedwhenthequeueemptiessothepapercanbetornoffwithoutturningtheprinteroff-line andpressingformfeed.Theofentryspecifiesthefilterprogramlpfshouldbeusedforprinting thefiles;morewillbesaidaboutfilterslater.Thelastentrycauseserrorstobewrittentothefile ‘‘/usr/adm/lpd-errs’’insteadoftheconsole.

-4-4.1.2.Remoteprinters Printerswhichresideonremotehostsshouldhaveanemptylpentry.Forexample,thefollowingprintcapentrywouldsendoutputtotheprinternamed‘‘lp’’onthemachine‘‘ucbvax’’. lp|defaultlineprinter:\ :lp=:rm=ucbvax:rp=lp:sd=/usr/spool/vaxlpd: Thermentryisthenameoftheremotemachinetoconnectto;thisnamemustappearinthe /etc/hostsdatabase,seehosts(5).Therpcapabilityindicatesthenameoftheprinteronthe remotemachineis‘‘lp’’;inthiscaseitcouldbeleftoutsincethisisthedefaultvalue.Thesd entryspecifies‘‘/usr/spool/vaxlpd’’asthespoolingdirectoryinsteadofthedefaultvalueof ‘‘/usr/spool/lpd’’. 4.2.Outputfilters Filtersareusedtohandledevicedependenciesandtoperformaccountingfunctions.The outputfilterofisusedtofiltertextdatatotheprinterdevicewhenaccountingisnotusedor whenalltextdatamustbepassedthroughafilter.Itisnotintendedtoperformaccountingsince itisstartedonlyonce,alltextfilesarefilteredthroughit,andnoprovisionismadeforpassing owners’loginname,identifyingthebeginingandendingofjobs,etc.Theotherfilters(ifspecified)arestartedforeachfileprintedandperformaccountingifthereisanafentry.Ifentriesfor bothofandoneoftheotherfiltersarespecified,theoutputfilterisusedonlytoprintthebanner page;itisthenstoppedtoallowotherfiltersaccesstotheprinter.Anexampleofaprinterwhich requiresoutputfiltersistheBenson-Varian. va|varian|Benson-Varian:\ :lp=/dev/va0:sd=/usr/spool/vad:of=/usr/lib/vpf:\ :tf=/usr/lib/rvcat:mx#2000:pl#58:tr=\f: Thetfentryspecifies‘‘/usr/lib/rvcat’’asthefiltertobeusedinprintingtroff(1)output.Thisfilterisneededtosetthedeviceintoprintmodefortext,andplotmodeforprintingtrofffilesand rasterimages(seeva(4V)).Notethatthepagelengthissetto58linesbytheplentryfor8.5" by11"fan-foldpaper.Toenableaccounting,thevarianentrywouldbeaugmentedwithanaffil-terasshownbelow. va|varian|Benson-Varian:\ :lp=/dev/va0:sd=/usr/spool/vad:of=/usr/lib/vpf:\ :if=/usr/lib/vpf:tf=/usr/lib/rvcat:af=/usr/adm/vaacct:\ :mx#2000:pl#58:tr=\f: 5.Outputfilterspecifications Thefilterssuppliedwith4.2BSDhandleprintingandaccountingformostcommonline printers,theBenson-Varian,thewide(36")andnarrow(11")Versatecprinter/plotters.Forother devicesoraccountingmethods,itmaybenecessarytocreateanewfilter. Filtersarespawnedbylpdwiththeirstandardinputthedatatobeprinted,andstandard outputtheprinter.Thestandarderrorisattachedtothelffileforloggingerrors.Afiltermust returna0exitcodeiftherewerenoerrors,1ifthejobshouldbereprinted,and2ifthejob shouldbethrownaway.Whenlprmsendsakillsignaltothelpdprocesscontrollingprinting,it sendsaSIGINTsignaltoallfiltersanddescendentsoffilters.Thissignalcanbetrappedbyfilterswhichneedtoperformcleanupoperationssuchasdeletingtemporaryfiles. Argumentspassedtoafilterdependonitstype.Theoffilteriscalledwiththefollowing arguments. ofiler−wwidth−llength Thewidthandlengthvaluescomefromthepwandplentriesintheprintcapdatabase.Theiffilterispassedthefollowingparameters.

-5-filter[−c]−wwidth−llength−iindent−nlogin−hhostaccountingfile The−cflagisoptional,andonlysuppliedwhencontrolcharactersaretobepasseduninterpreted totheprinter(whenthe−loptionoflprisusedtoprintthefile).The−wand−lparameters arethesameasfortheoffilter.The−nand−hparametersspecifytheloginnameandhost nameofthejobowner.Thelastargumentisthenameoftheaccountingfilefromprintcap. Allotherfiltersarecalledwiththefollowingarguments: filter−xwidth−ylength−nlogin−hhostaccountingfile The−xand−yoptionsspecifythehorizontalandverticalpagesizeinpixels(fromthepxand pyentriesintheprintcapfile).Therestoftheargumentsarethesameasfortheiffilter. 6.LineprinterAdministration Thelpcprogramprovideslocalcontroloverlineprinteractivity.Themajorcommandsand theirintendedusewillbedescribed.Thecommandformatandremainingcommandsare describedinlpc(8). abortandstart Abortterminatesanactivespoolingdaemononthelocalhostimmediatelyandthendisables printing(preventingnewdaemonsfrombeingstartedbylpr).Thisisnormallyusedto forcibllyrestartahunglineprinterdaemon(i.e.,lpqreportsthatthereisadaemonpresent butnothingishappening).Itdoesnotremoveanyjobsfromthequeue(usethelprmcommandinstead).Startenablesprintingandrequestslpdtostartprintingjobs. enableanddisable Enableanddisableallowspoolinginthelocalqueuetobeturnedon/off.Thiswill allow/preventlprfromputtingnewjobsinthespoolqueue.Itisfrequentlyconvenientto turnspoolingoffwhiletestingnewlineprinterfilterssincetherootusercanstilluselprto putjobsinthequeuebutnooneelsecan.Theothermainuseistopreventusersfrom puttingjobsinthequeuewhentheprinterisexpectedtobeunavailableforalongtime. restart Restartallowsordinaryuserstorestartprinterdaemonswhenlpqreportsthatthereisno daemonpresent. stop Stopisusedtohaltaspoolingdaemonafterthecurrentjobcompletes;thisalsodisables printing.Thisisacleanwaytoshutdownaprinterinordertoperformmaintenence,etc. Notethatuserscanstillenterjobsinaspoolqueuewhileaprinterisstopped. topq Topqplacesjobsatthetopofaprinterqueue.Thiscanbeusedtoreorderhighpriority jobssincelpronlyonlyprovidesfirst-come-first-serveorderingofjobs. 7.Troubleshooting Thereareanumberofmessageswhichmaybegeneratedbythethelineprintersystem. Thissectioncategorizesthemostcommonandexplainsthecausefortheirgeneration.Wherethe messageindicatesafailure,directionsaregiventoremedytheproblem. Intheexamplesbelow,thenameprinteristhenameoftheprinter.Thiswouldbeoneof thenamesfromtheprintcapdatabase. 7.1.LPR lpr:printer:unknownprinter Theprinterwasnotfoundintheprintcapdatabase.Usuallythisisatypingmistake;however,itmayindicateamissingorincorrectentryinthe/etc/printcapfile.

-6-lpr:printer:jobsqueued,butcannotstartdaemon. Theconnectiontolpdonthelocalmachinefailed.Thisusuallymeanstheprinterserver startedatboottimehasdiedorishung.Checkthelocalsocket/dev/printertobesureit stillexists(ifitdoesnotexist,thereisnolpdprocessrunning).Use %psax|fgreplpd togetalistofprocessidentifiersofrunninglpd’s.Thelpdtokillistheonewhichisnot listedinanyofthe‘‘lock"files(thelockfileiscontainedinthespooldirectoryofeach printer).Killthemasterdaemonusingthefollowingcommand. %killpid Thenremove/dev/printerandrestartthedaemon(andprinter)withthefollowingcommands. %rm/dev/printer %/usr/lib/lpd Anotherpossibilityisthatthelprprogramisnotsetuidroot,setgidspooling.Thiscanbe checkedwith %ls−lg/usr/ucb/lpr lpr:printer:printerqueueisdisabled Thismeansthequeuewasturnedoffwith %lpcdisableprinter topreventlprfromputtingfilesinthequeue.Thisisnormallydonebythesystemmanager whenaprinterisgoingtobedownforalongtime.Theprintercanbeturnedbackonbya super-userwithlpc. 7.2.LPQ waitingforprintertobecomeready(offline?) Theprinterdevicecouldnotbeopenedbythedaemon.Thiscanhappenforanumberof reasons,themostcommonbeingthattheprinteristurnedoff-line.Thismessagecanalso begeneratediftheprinterisoutofpaper,thepaperisjammed,etc.Theactualreasonis dependentonthemeaningoferrorcodesreturnedbysystemdevicedriver.Notallprinters supplysufficientinformationtodistinguishwhenaprinterisoff-lineorhavingtrouble(e.g.a printerconnectedthroughaserialline).Anotherpossiblecauseofthismessageissome otherprocess,suchasanoutputfilter,hasanexclusiveopenonthedevice.Youronly recoursehereistokillofftheoffendingprogram(s)andrestarttheprinterwithlpc. printerisreadyandprinting Thelpqprogramcheckstoseeifadaemonprocessexistsforprinterandprintsthefilestatus.Ifthedaemonishung,asuperusercanuselpctoabortthecurrentdaemonandstarta newone. waitingforhosttocomeup Thisindicatesthereisadaemontryingtoconnecttotheremotemachinenamedhostin ordertosendthefilesinthelocalqueue.Iftheremotemachineisup,lpdontheremote machineisprobablydeadorhungandshouldberestartedasmentionedforlpr.

-7-sendingtohost Thefilesshouldbeintheprocessofbeingtransferredtotheremotehost.Ifnot,thelocal daemonshouldbeabortedandstartedwithlpc. Warning:printerisdown Theprinterhasbeenmarkedasbeingunavailablewithlpc. Warning:nodaemonpresent Thelpdprocessoverseeingthespoolingqueue,asindicatedinthe‘‘lock’’fileinthatdirectory,doesnotexist.Thisnormallyoccursonlywhenthedaemonhasunexpectedlydied. Theerrorlogfilefortheprintershouldbecheckedforadiagnosticfromthedeceasedprocess.Torestartanlpd,use %lpcrestartprinter 7.3.LPRM lprm:printer:cannotrestartprinterdaemon Thiscaseisthesameaswhenlprprintsthatthedaemoncannotbestarted. 7.4.LPD Thelpdprogramcanwritemanydifferentmessagestotheerrorlogfile(thefilespecifiedin thelfentryinprintcap).Mostofthesemessagesareaboutfileswhichcannotbeopenedand usuallyindicatetheprintcapfileortheprotectionmodesofthefilesarenotcorrect.Filesmay alsobeinaccessibleifpeoplemanuallymanipulatethelineprintersystem(i.e.theybypassthelpr program). Inadditiontomessagesgeneratedbylpd,anyofthefiltersthatlpdspawnsmayalsolog messagestothisfile. 7.5.LPC could’tstartprinter Thiscaseisthesameaswhenlprreportsthatthedaemoncannotbestarted. cannotexaminespooldirectory Errormessagesbeginningwith‘‘cannot...’’areusuallyduetoincorrectownershipand/or protectionmodeofthelockfile,spoolingdirectoryorthelpcprogram.