Next | Welcome to my ~/bin | 90 |
Caution: system programming ahead
use strict; use Sys::Syslog; use Fcntl ':flock'; use lib '/home/mjd/lib'; use MJD::Print; my %CONF = load_conf($CONFIG); my $NEXTOP = 0;
open STDERR, ">>", '/tmp/printd.err' if $CONF{debug_printd}; print STDERR "printd $$ running\n" if $CONF{debug_printd}; close STDOUT; chdir $CONF{spooldir} or die "Couldn't chdir to spool directory $CONF{spooldir}: $!; aborting"; open D, "." or die "Couldn't open .: $!; aborting"; flock D, LOCK_EX | LOCK_NB or exit 0; print STDERR "Got lock.\n" if $CONF{debug_printd}; mainloop();
The only interesting item here is flock
This ensures that only one printd is running at a time
The printd might exit if there is nothing for it to do
When print wants to print, it should also start printd
If printd is already running, that is OK
open D, "." is highly nonportable
open D, "<", $0 would have been a better choice
Next | Menu | Copyright © 2005 M. J. Dominus |