From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <168443d47fcd8dd22e9612ab9a18d540@collyer.net> From: Geoff Collyer To: 9fans@collyer.net MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Subject: [9fans] lp improvements Date: Wed, 16 Apr 2003 20:07:46 -0700 Topicbox-Message-UUID: 91ab0c2e-eacb-11e9-9e20-41e7f4b1d025 Since Plan 9 systems at a site typically share a file server, I've modified lp to not send jobs (via port 515) to the machine responsible for the printer, just to enqueue the job, but rather to just put the job in the spooler queue and start the appropriate dæmon or kick the responsible machine to start the dæmon. (It's still possible to queue jobs on non-plan-9 systems using non-generic daemon or spooler scripts in the devices file.) I've made the last field ("FIFO") of /sys/lib/lp/devices optional. If omitted, it now defaults to "generic". In /sys/lib/lp/spooler, smart is my improved version of generic. You could copy or rename it to generic, but I wanted to avoid at least that one replica conflict. : cpu; cat /sys/lib/lp/devices # device_name loc dest_host phys_dev_name speed class def_proc spooler stat kill daemon sched foo home cpu.collyer.net foo.collyer.net - post+HPJCL+nohead+300dpi generic smart hp generic hp ; history -D lp Apr 12 21:23:25 PDT 2003 lp 5454 [geoff] lp:137,138 d /n/dump/2003/0412/rc/bin/lp:136 < < # parse devices lp:155,159 d /n/dump/2003/0412/rc/bin/lp:152 < < # supply defaults < if (~ $#SCHED 0 || ~ $SCHED '') < SCHED=generic # was FIFO < # To unbundle, cd to /sys/lib/lp and run the rest of this file echo sched/generic sed 's/^X//' >sched/generic <<'!' X#!/bin/rc ls -ptr $* | sed -n -e '/^[^.].*\.[0-9][0-9]*\.[1-9][0-9]*$/p' ! echo spooler/smart sed 's/^X//' >spooler/smart <<'!' X#!/bin/rc X# a smarter version of the `generic' spooler. X# all our Plan 9 systems share a common file system, thus a common lp spool. X# so stop this crazy business of sending jobs around via port 515; X# just stick the job in the queue and kick the guy who runs the printer. rfork en if (! ~ $DEBUG '') X flag x + pfx=`{echo $LPMACHID | sed 's/\..*//'}^.$pid qdir=$LPSPOOL/$LPDEST X{ mkdir $qdir && chmod 777 $qdir } >[2]/dev/null X# Process and enqueue files to be printed. take arguments as input files. i=0 if (~ $#* 0) X * = /fd/0 for (f) { X i = `{echo $i + 1 | hoc} X # check access to the file so that you know that a failure in the X # processing is a drastic error which will cause an exit from lp. X if (! test -r $f) X echo $f: not readable or missing >[1=2] X if not { X job=$pfx.$i X @ { X rfork n X bind -b $LPLIB/process /bin X $LPPROC X } <$f >$qdir/.$job # temporary name X if (~ $status '') @ { X cd $qdir X echo $LPMACHID $LPUSERID $job 0 >$job^id X mv .$job $job # convert to real name X } X if not { X rm -f $qdir/.$job X exit 'preprocessing failed' X } X } X} X# kick remote daemon if needed; lp -R just runs the daemon if (! ~ $THIS_HOST $DEST_HOST && ! ~ $DAEMON -) X rx $DEST_HOST 'LPDEST='^$LPDEST^' lp -R' X# lp will start the appropriate daemon (not lpdaemon) locally when we return exit '' !