[cups.development] [RFE] STR #3591: Socket backend will loop "forever"

Jon Peatfield jp107 at cam.ac.uk
Thu May 27 14:25:49 PDT 2010


DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

None of what I'm about to say disagres with what you suggest, but this may
be a work-around you can live with if timescales mean that no patch is
likely in the short term.

While it isn't for the same reason, we have some code which 'checks' all
of our printers (by extracting the socket URI from the cups server and
trying to talk to them), and if they arn't responding down/disables the
queue.

In our case this is for updating a 'web page' which contains details of
the printers and stuff we can tell about them so is actually embedded in a
horrid piece of code called from some CGI, but the logic is essentially:

for a given queue

  run lpstat.cups -v $printer  and extract the socket address

  check if the printer is well (via snmp in our case)

  if all is ok then update our status info
  else run cupsdisable on the printer (and inform someone)

It should be quite possible to simply process the output of lpstat -v
(showing all queues) instead, and/or look to see if a queue is already
disabled)...

In fact atm we actually do (perm I'm afraid):

....
open (IN, "lpstat.cups -v $printer -p $printer -a $printer 2>/dev/null |")
||
    dprin(0, "ERROR can't run lpstat: $!");
while (<IN>) {
    chomp;
    if (/^device.*$printer:\s*(.*)/) {
	$uri=$1;
	if ($uri =~ /socket:\/\/([\w\.\-_]+):/) {
	    $phost=$1;
	}
    } elsif (/^printer.*$printer.*(enabled|disabled)/) {
	$lpstat=$1;
    } elsif (/^$printer\s+((not\s+|)accepting requests)/) {
	my $stat=$1;
	$stat =~ s/not\s+accepting/rejecting/;
	$stat =~ s/requests/jobs/;
	$lpstat.=", $stat";
    } elsif (/^\s+([\w\s\,\.\!\-\_]+)/) {
	$lpstat.=" [$1]";
    }
}
....

to extract the host uri, socket hostname and cups-queue-status, but there
are probably cleaner ways to do this directly with the cups API...

 -- Jon

Link: http://www.cups.org/str.php?L3591
Version:  -feature





More information about the cups mailing list