1
0
forked from pool/cups-backends
OBS User unknown 2009-05-28 22:51:44 +00:00 committed by Git OBS Bridge
parent 7354f8df12
commit 7027fb0845
6 changed files with 133 additions and 446 deletions

View File

@ -1,156 +0,0 @@
<html><head>
<meta name="description" content="&lt;!-- content: undefined tag: description --&gt;"><title>beh - The Backend Error Handler</title></head><body bgcolor="#ffffff">
<table border="0" cellpadding="6" cellspacing="0" width="100%">
<tbody><tr>
<td bgcolor="#ffffff" width="100%"> <!-- top bar -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td><font size="+3">
<a href="http://www.linuxprinting.org/beh.html">beh</a> -
The Backend Error Handler</font></td>
<!-- could put other stuff here flush right in with title -->
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td height="100%" valign="top" width="100%"> <!-- contents -->
<!-- header/announcementy things go here -->
Very annoying with CUPS is that when an error on the communication
between the CUPS backend and the printer occurs, CUPS disables the
print queue and to be able to continue printing an administrator (root
access required) has to re-enable the queue. It is not enough to
simply fix the printer's communication problem (like turning it on,
fixing the network connection, ...).<p>
This is especially a very bad design for desktop/home users. They
often only turn on their printers when they really want to print (to
save energy). Then it happens easily that they send a job and forget
to turn on the printer. CUPS disables the queue and the annoying
re-enabling procedure has to be done. And many users even do not know
about the problem. So the printer does not print and the queue gets
nuked and re-created. Or the people cry on the help forums or at the
installation support of their distributions.</p><p>
This problem can be easily worked around by installing <tt><a href="http://www.linuxprinting.org/download.cgi?filename=beh&amp;show=0">beh</a></tt>, the
<b>B</b>ackend <b>E</b>rror <b>H</b>andler. This script makes the
handling of such backend errors configurable, so that the problem can
easily be worked around. The new possibilities are:</p><p>
</p><ul>
<li> Let queues simply not being disabled. Simple approach, but job gets
lost.
</li><li> Repeat a given number of times.
</li><li> Repeat infinitely often, until the job gets finally through. This
is the standard of LPRng, and it eliminates loss of the job.
</li><li> The interval between two attempts to run the backend can also be
configured.
</li><li> Configuration is done independently for each print queue. So local
printers and network printers can be treated differently.
</li></ul><p>
Simply <a href="http://www.linuxprinting.org/download.cgi?filename=beh&amp;show=0">download</a> the
script, copy it into the CUPS backend directory (normally
<tt>/usr/lib/cups/backend/</tt>), and make it executable with
"<tt>chmod 755 beh</tt>. Then restart CUPS that it registers the new
backend, usually with "<tt>killall -HUP cupsd</tt>" or
"/etc/init.d/cups restart". If you did all correctly, there must be a
line containing "<tt>beh</tt>" in the output of "<tt>lpinfo
-v</tt>".</p><p>
<tt>beh</tt> is a wrapper which is called by CUPS in place of the usual backend, which is called by <tt>beh</tt> now. This way <tt>beh</tt>
can, depending on its configuration, repeat the call of the backend or
simply hide the error status of the backend from being seen by the CUPS
daemon.</p><p>
To make a print queue usinf <tt>beh</tt>, get root and call a command as follows:</p><p>
<tt>lpadmin -p &lt;queue name&gt; -E -v beh:/&lt;dd&gt;/&lt;att&gt;/&lt;delay&gt;/&lt;originaluri&gt;</tt></p><p>
with</p><p>
</p><dl>
<dt><tt>&lt;queue name&gt;</tt>:
</dt><dd>The name of your print queue<p>
</p></dd><dt><tt>&lt;dd&gt;</tt>:
</dt><dd>Don't Disable, if "<tt>1</tt>", <tt>beh</tt> always exits with
zero status, so the queue gets never disabled when the original
backend exits with an error. "<tt>0</tt>" carries the error
status of the last call of the backend (after
<tt>&lt;att&gt;</tt> retries) on to CUPS, so the queue usually
gets disabled.<p>
</p></dd><dt><tt>&lt;att&gt;</tt>:
</dt><dd>Attempts, number of attempts to recall the backend in case of
an error. "<tt>0</tt>" means infinite retries. In this case
<tt>&lt;dd&gt;</tt> gets meaningless.<p>
</p></dd><dt><tt>&lt;delay&gt;</tt>:
</dt><dd>Delay between two attempts to call the beckend, to be given in
seconds and as an integer number. Meaningless if
<tt>&lt;att&gt;</tt> is one.<p>
</p></dd><dt><tt>&lt;originaluri&gt;</tt>:
</dt><dd>The original URI, which your queue had before (use "<tt>lpstat
-v</tt>" to get your queue's URI shown).<p>
</p></dd></dl><p>
All parameters, especially, <tt>&lt;dd&gt;</tt>,
<tt>&lt;att&gt;</tt>, and <tt>&lt;delay&gt;</tt> have always to be
specified, even if one of them is meaningless due to the setting of
the others.</p><p>
<tt>beh</tt> works with every backend except the <tt>hp</tt> backend
from <a href="http://hpinkjet.sf.net/">HPLIP</a>. If <tt>beh</tt> is
used with the <tt>hp</tt> backend, the HP Toolbox will not find the
printers any more.</p><p>
Example URIs:</p><p>
</p><dl>
<dt><tt>beh:/1/3/5/socket://printer:9100</tt>
</dt><dd>On the network printer with host name "<tt>printer</tt>" it is
tried to access 3 times with 5 second delays between the
attempts. If the job still fails, the queue is not disabled
(and the job discarded).<p>
</p></dd><dt><tt>beh:/0/10/60/socket://printer:9100</tt>
</dt><dd>Retry 10 times in one minute intervals, disable the queue when
still not succeeding.<p>
</p></dd><dt><tt>beh:/1/0/60/usb://Brother/HL-5040%20series</tt>
</dt><dd>On a Brother HL-5040 on the USB try infinitely often until the
printer comes back, in intervals of one minute. This way the
job does not get lost when the printer is turned off and one
can intendedly delay printing by simply switching off the
printer. The ideal configuration for desktop printers and/or
home users.<p>
</p></dd></dl><p>
Report bugs in <tt><a href="http://www.linuxprinting.org/forums.cgi?group=linuxprinting.foomatic.devel">linuxprinting.foomatic.devel</a></tt>.
</p></td>
</tr>
</tbody></table>
</body></html>

203
beh
View File

@ -1,203 +0,0 @@
#!/usr/bin/perl
# The above Perl path may vary on your system; fix it!!! -*- perl -*-
# beh - Backend Error Handler
# A wrapper for CUPS backends to make error handling configurable
# Usually, if a CUPS backend exits with an error status other than zero
# (for example if a printer is not turned on or not reachable on the
# network), CUPS disables the print queue and one can only print again
# if a system administrator re-enables the queue manually. Even restarting
# CUPS (or rebooting) does not re-enable disabled queues.
#
# For system administrators this can get annoying, for newbie users
# who are not aware of this problem it looks like that CUPS is severely
# broken. They remove and re-install print queues, getting on the nerves
# of distro install support, people, or even switch back to a proprietary
# operating system.
#
# This script makes the handling of such backend errors configurable, so
# that the problem can easily be worked around. The new possibilities are:
#
# - Let queues simply not being disabled. Simple approach, but job gets
# lost.
#
# - Repeat a given number of times.
#
# - Repeat infinitely often, until the job gets finally through. This
# is the standard of LPRng, and it eliminates loss of the job.
#
# - The interval between two attemts to run the backend can also be
# configured.
#
# - Configuration is done independently for each print queue. So local
# printers and network printers can be treated differently.
# Save this file in your CUPS backend directory, usually
# /usr/lib/cups/backend/ or /usr/local/lib/cups/backend/
#
# Mark this filter world-readable and world-executable. Restart CUPS to
# make the new backend known to the spooler.
#
# See http://www.linuxprinting.org/cups-doc.html and the additional
# instructions below.
# beh - Backend Error Handler
#
# Copyright 2005 Till Kamppeter <till.kamppeter@gmx.net>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
# Usage:
#
# cp beh /usr/lib/cups/backend/
# chmod 755 /usr/lib/cups/backend/beh
# killall -HUP cupsd (or "/etc/init.d/cups restart")
# lpadmin -p <queue name> -E -v beh:/<dd>/<att>/<delay>/<originaluri>
#
# with
# <queue name>: The name of your print queue
# <dd>: Don't Disable, if "1", beh always exits with zero
# status, so the queue gets never disabled when the
# original backend exits with an error. "0" carries
# the error status of the last call of the backend
# (after <att> retries) on to CUPS, so the queue
# usually gets disabled.
# <att>: Attempts, number of attempts to recall the backend
# in case of an error. "0" means infinite retries. In
# this case <dd> gets meaningless.
# <delay>: Delay between two attempts to call the beckend, to
# be given in seconds and as an integer number.
# Meaningless if <att> is one.
# <originaluri>: The original URI, which your queue had before.
#
# All parameters, especially, <dd>, <att>, and <delay> have always to
# be specified, even if one of them is meaningless due to the setting of
# the others.
#
# beh works with every backend except the "hp" backend of HPLIP.
#
# Example URIs:
#
# beh:/1/3/5/socket://printer:9100
#
# On the network printer with host name "printer" it is tried to access
# 3 times with 5 second delays between the attempts. If the job still
# fails, the queue is not disabled (and the job discarded).
#
# beh:/0/10/60/socket://printer:9100
#
# Retry 10 times in one minute intervals, disable the queue when still
# not succeeding.
#
# beh:/1/0/60/usb://Brother/HL-5040%20series
#
# On a Brother HL-5040 on the USB try infinitely often until the printer
# comes back, in intervals of one minute. This way the job does not get
# lost when the printer is turned off and one can intendedly delay
# printing by simply switching off the printer. The ideal configuration
# for desktop printers and/or home users.
# Acknowledgement
#
# Thanks to Jeff Hardy (hardyjm at potsdam dot edu) for writing the
# "accsnmp" wrapper backend (http://fritz.potsdam.edu/projects/cupsapps/).
# This backend showed me the trick how to write a universal wrapper
# backend in a scripting language.
use strict;
$0 =~ m!^(.*)/([^/]+)\s*$!;
my $progname = ($2 || $0);
my $progpath = ($1 || "/usr/lib/cups/backend");
if (!$ARGV[0]){
print "network $progname \"Unknown\" \"Backend Error Handler\"\n";
exit 0;
}
if (scalar(@ARGV) < 5 || scalar(@ARGV) > 6){
print STDERR "ERROR: Usage: $progname job-id user title copies options [file]\n";
exit 1;
}
my ($jobID, $userName, $jobTitle, $copies, $printOptions, $printFile) =
@ARGV;
my $tempFile;
if (!$printFile) {
my $jid = $jobID;
my $uid = $userName;
$jid =~ s/\W//g; #sanity check
$uid =~ s/\W//g; #sanity check
$tempFile = "$ENV{TMPDIR}/$jid-$uid-cupsjob$$";
open (OUT, ">$tempFile") or die "ERROR: Cannot write $tempFile: $!\n";
while(<STDIN>){
print OUT "$_";
}
close OUT;
$printFile = $tempFile;
# Backends should only produce multiple copies if a file name is
# supplied (see CUPS Software Programmers Manual)
$copies = 1;
}
my $uri = $ENV{DEVICE_URI};
$uri =~ m!^$progname:/(\d+)/(\d+)/(\d+)/(\S+)$! or
die "URI must be \"beh:/<dd>/<att>/<delay>/<original uri>\"!\n";
my $dontdisable = $1;
my $attempts = $2;
my $delay = $3;
$uri = $4;
$uri =~ m!^([^:\s]+):!;
my $backend = $1;
$ENV{DEVICE_URI} = $uri;
# Control by "lpr" command line options, commented out for security
# reasons (user could intendedly make queues being disabled)
#$printOptions =~ m/\bBackendErrorDisableQueue=(\S*)\b/ &&
# ($dontdisable = ($1 =~ /no/i ? 1 : 0));
#$printOptions =~ m/\bBackendErrorRetries=(\S*)\b/ && ($attempts = $1);
#$printOptions =~ m/\bBackendErrorRetryDelay=(\S*)\b/ && ($delay = $1);
#$printOptions =~ m/\bBackendErrorRetryForever=(\S*)\b/ &&
# ($delay = ($1 =~ /yes/i ? 0 : $delay));
my $exitvalue;
while($exitvalue = (($uri !~ m!^file:(.*)$!) && ($uri !~ m!^(/.*)$!) ?
system {"$progpath/$backend"}
($uri, $jobID, $userName, $jobTitle, $copies,
$printOptions, $printFile) :
system ("cat $printFile > $1")) >> 8) {
if ($attempts > 0) {
$attempts --;
last if $attempts == 0;
}
sleep $delay if $delay > 0;
}
unlink $tempFile if $tempFile;
$exitvalue = 0 if $dontdisable;
exit $exitvalue;

View File

@ -1,3 +1,15 @@
-------------------------------------------------------------------
Thu May 28 12:58:50 CEST 2009 - jsmeix@suse.de
- Removed the beh backend because it is now provided
in the upgraded foomatic-filters version 4.0.1 package.
- Replaced the pipe backend source cups-pipe.pl perl script
with a new source cups-pipe.sh bash script which works
in much better compliance to CUPS and which also fixes
a bug that it did not get signals from the cupsd
so that it did not terminate pipe when removing jobs
(see Novell/Suse Bugzilla bnc#499735).
-------------------------------------------------------------------
Mon Jul 30 20:31:55 CEST 2007 - crivera@suse.de

View File

@ -1,28 +1,34 @@
#
# spec file for package cups-backends (Version 1.0)
#
# Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany.
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
# norootforbuild
Name: cups-backends
BuildRequires: cups-devel hal-devel
Summary: Various Free Backends for the cups Package
License: GPL v2 or later
Group: Hardware/Printing
Version: 1.0
Release: 103
Release: 253
Source0: http://www.srz.de/Members/bla/cups/backend/hpnpf/hpnpf.tgz
Source1: http://www.srz.de/Members/bla/cups/backend/hpnpf/hpnpf.txt
Source2: cups-pipe.pl
Source2: cups-pipe.sh
Source4: hal.c
Source5: http://www.linuxprinting.org/download/printing/beh
Source6: README-beh.html
Patch0: hpnpf.patch
Patch1: cups-backends-silenct-hal.patch
Requires: cups-libs, dbus-1, hal
@ -37,6 +43,8 @@ Authors:
--------
Jiri Srain <jsrain@suse.cz>
Jeffrey Stedfast <fejj@novell.com>
Klaus Singvogel <kssingvo@suse.de>
Johannes Meixner <jsmeix@suse.de>
%prep
%setup -c -T
@ -45,8 +53,6 @@ cd hpnpf
tar xzvvf %{SOURCE0}
cd ..
cp -a %{SOURCE4} .
cp -a %{SOURCE5} beh
cp -a %{SOURCE6} .
%patch1 -p0
%build
@ -56,35 +62,42 @@ gcc $RPM_OPT_FLAGS -fPIC -fPIE -pie -DDBUS_API_SUBJECT_TO_CHANGE \
%install
mkdir -p $RPM_BUILD_ROOT/%{_libdir}/cups/backend
install -m 755 -D ${RPM_SOURCE_DIR}/cups-pipe.pl $RPM_BUILD_ROOT%{_libdir}/cups/backend/pipe
install -m 755 -D ${RPM_SOURCE_DIR}/cups-pipe.sh $RPM_BUILD_ROOT%{_libdir}/cups/backend/pipe
install -m 755 -D hal $RPM_BUILD_ROOT%{_libdir}/cups/backend/hal
install -m 755 -D beh $RPM_BUILD_ROOT%{_libdir}/cups/backend/beh
%files
%defattr(-, root,root)
%dir %{_libdir}/cups
%dir %{_libdir}/cups/backend
%{_libdir}/cups/backend/*
%doc README-beh.html
%changelog
* Mon Jul 30 2007 - crivera@suse.de
* Thu May 28 2009 jsmeix@suse.de
- Removed the beh backend because it is now provided
in the upgraded foomatic-filters version 4.0.1 package.
- Replaced the pipe backend source cups-pipe.pl perl script
with a new source cups-pipe.sh bash script which works
in much better compliance to CUPS and which also fixes
a bug that it did not get signals from the cupsd
so that it did not terminate pipe when removing jobs
(see Novell/Suse Bugzilla bnc#499735).
* Mon Jul 30 2007 crivera@suse.de
- Silence the hal backend. This will allow current printers
that use the hal backend to work, but it will not report new
printers. This is the first step toward removing the backend
completely.
* Wed Mar 22 2006 - lmuelle@suse.de
* Wed Mar 22 2006 lmuelle@suse.de
- Update beh backend to the current version.
- Add beh documentation derivated from http://www.linuxprinting.org/beh.html.
- Move ncp backend to the ncpfs package.
* Wed Jan 25 2006 - mls@suse.de
* Wed Jan 25 2006 mls@suse.de
- converted neededforbuild to BuildRequires
* Thu Jan 12 2006 - kssingvo@suse.de
* Thu Jan 12 2006 kssingvo@suse.de
- added backend error handler (beh) (bugzilla#132002)
* Tue Oct 04 2005 - jsrain@suse.cz
* Tue Oct 04 2005 jsrain@suse.cz
- fixed the error handling in the pipe backend (#93480)
* Mon Sep 19 2005 - lmuelle@suse.de
* Mon Sep 19 2005 lmuelle@suse.de
- Don't redirect stdout to stderr in the pipe backend.
- Install the right files, [#117887].
* Tue Jul 26 2005 - kssingvo@suse.de
* Tue Jul 26 2005 kssingvo@suse.de
- initial version

View File

@ -1,68 +0,0 @@
#!/usr/bin/perl -w
#
# CUPS backend for printing to any program via pipe
#
# Copyright (c) 2003 SuSE Linux AG, Nuernberg, Germany.
#
# Author: Jiri Srain <jsrain@suse.cz>, 2003
#
$scheme = "pipe";
if (@ARGV == 0)
{
print "file $scheme \"Unknown\" \"Printing to any command via pipe\"\n";
exit 0;
}
# in case of wrong number of arguments: print usage hint
if (@ARGV != 5 && @ARGV != 6)
{
print STDERR "
Usage: pipe job-id user title copies options [file]
example for device-URI: 'pipe:/path/to/targetcommand'
Install a printqueue with 'lpadmin -p <pipe-printer-name>
-v pipe:/</path/to/targetcommand> -E
";
exit 1;
}
if (defined ($ARGV[5]))
{
$file = $ARGV[5];
}
else
{
$file = "-";
}
# get file to which the job is "printed" from device URI, so
# so that you can use this backend multiple times, for various
# "pipe" printers...
$uri = $ENV{"DEVICE_URI"};
$arg = $uri;
$arg =~ s/$scheme:(.*)/$1/;
$cmdln = "/bin/cat $file | $arg";
if ($> == 0)
{
$cmdln = "su -c \"$cmdln \" lp";
}
my $exit = system ($cmdln);
if ($exit != 0)
{
print STDERR "ERROR: Error occurred while executing $cmdln";
}
exit $exit >> 8;

89
cups-pipe.sh Normal file
View File

@ -0,0 +1,89 @@
#! /bin/bash
# CUPS wrapper backend "pipe" for printing to any program.
# It forwards the print job data like a pipe into another command.
# Author: Johannes Meixner <jsmeix@suse.de>, 2009
# For basic information see "man 7 backend" and "man 7 filter".
# Activate the "set -x" line to get debugging info in /var/log/cups/error_log:
#set -x
# Output "Device Discovery" information on stdout:
if test "$#" = "0"
then
echo 'direct pipe "Unknown" "Forward print job data like a pipe to another command"'
exit 0
fi
# Output usage information in case of wrong number of parameters:
if test "$#" != "5" -a "$#" != "6"
then
echo 'Usage: pipe job-id user title copies options [file]' 1>&2
echo 'Queue setup example:' 1>&2
echo 'lpadmin -p queue_name -v "pipe:/path/to/command?option1=value1&-option2&value2" -E' 1>&2
echo 'The command is called with the specified options as:' 1>&2
echo '/path/to/command option1=value1 -option2 value2' 1>&2
echo 'The original command line parameters (... job-id user ...)' 1>&2
echo 'are provided as environment variables PIPE_BACKEND_ARGV[0-6]' 1>&2
exit 1
fi
# Keep the original command line parameters (... job-id user ...)
# in environment variables to make them available for the command:
export PIPE_BACKEND_ARGV0="$0"
export PIPE_BACKEND_ARGV1="$1"
export PIPE_BACKEND_ARGV2="$2"
export PIPE_BACKEND_ARGV3="$3"
export PIPE_BACKEND_ARGV4="$4"
export PIPE_BACKEND_ARGV5="$5"
export PIPE_BACKEND_ARGV6="$6"
# Have the input at fd0 (stdin) in any case:
if test -n "$6"
then
exec <"$6"
fi
# To be on the safe side clip anything after the first space character
# because spaces are excluded characters in a URI (see RFC 2396):
URI=${DEVICE_URI%% *}
# Extract the command to which the job schould be sent from the URI.
# Clip the URI scheme (anything up to the first ':' character) and
# clip anything after the first '?' character
# because anything after the first '?' character are options:
COMMAND=${URI#*:}
COMMAND=${COMMAND%%\?*}
# Extract the options (e.g. from 'pipe:/path/to/command?option1=value1&-option2&value2'
# clip anything up to the first '?' character and
# replace the options separator '&' character by a space:
OPTIONS=${URI#*\?}
if test "$OPTIONS" = "$URI"
then
OPTIONS=""
fi
OPTIONS=$( echo "$OPTIONS" | tr '&' ' ' )
# Options could have been specified in a wrong way
# as addendum to the DeviceURI separated by spaces
# (spaces are excluded characters in a URI, see RFC 2396)
# which works by luck at least for some CUPS versions
# see https://bugzilla.novell.com/show_bug.cgi?id=499735
# like 'pipe:/path/to/command option1=value1 -option2 value2'
# nevertheless use additionally those kind of options too:
MORE_OPTIONS=${DEVICE_URI#* }
if test "$MORE_OPTIONS" = "$DEVICE_URI"
then
MORE_OPTIONS=""
fi
OPTIONS=$( echo "$OPTIONS" "$MORE_OPTIONS" | tr -s ' ' )
# Test if the command is executable:
if ! test -x "$COMMAND"
then
echo "Cannot execute $COMMAND" 1>&2
exit 1
fi
# Replace this wrapper with the actual command
# so that it exits with the exit code of the command
# and that the command gets any signals directly.
exec "$COMMAND" $OPTIONS