summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Kamppeter <tkamppeter@mandriva.com>2002-01-28 23:19:40 +0000
committerTill Kamppeter <tkamppeter@mandriva.com>2002-01-28 23:19:40 +0000
commit8de8e2529e3f8742014d2a3fffb851eb036a9da9 (patch)
tree8f28274ec5016580d8eca7568662f98ce51b89ce
parent0da9a4e3256d2bd1e2351cdc06a26ab0d001cba5 (diff)
downloaddrakx-8de8e2529e3f8742014d2a3fffb851eb036a9da9.tar
drakx-8de8e2529e3f8742014d2a3fffb851eb036a9da9.tar.gz
drakx-8de8e2529e3f8742014d2a3fffb851eb036a9da9.tar.bz2
drakx-8de8e2529e3f8742014d2a3fffb851eb036a9da9.tar.xz
drakx-8de8e2529e3f8742014d2a3fffb851eb036a9da9.zip
Replaced "sleep" commands by a subroutine which waits exactly until CUPS is ready.
CUPS >= 1.1.12 needs to "know" all devices, let CUPS restart if a device is not "known" to it.
-rw-r--r--perl-install/printer.pm71
-rw-r--r--perl-install/printerdrake.pm9
2 files changed, 73 insertions, 7 deletions
diff --git a/perl-install/printer.pm b/perl-install/printer.pm
index 8e50cc043..7ebf478d5 100644
--- a/perl-install/printer.pm
+++ b/perl-install/printer.pm
@@ -126,13 +126,29 @@ sub set_permissions {
sub restart_service ($) {
my ($service) = @_;
run_program::rooted($prefix, "/etc/rc.d/init.d/$service", "restart");
- if (($? >> 8) != 0) {return 0;} else {return 1;}
+ if (($? >> 8) != 0) {
+ return 0;
+ } else {
+ # CUPS needs some time to come up.
+ if ($service eq "cups") {
+ wait_for_cups();
+ }
+ return 1;
+ }
}
sub start_service ($) {
my ($service) = @_;
run_program::rooted($prefix, "/etc/rc.d/init.d/$service", "start");
- if (($? >> 8) != 0) {return 0;} else {return 1;}
+ if (($? >> 8) != 0) {
+ return 0;
+ } else {
+ # CUPS needs some time to come up.
+ if ($service eq "cups") {
+ wait_for_cups();
+ }
+ return 1;
+ }
}
sub stop_service ($) {
@@ -182,17 +198,62 @@ sub SIGHUP_daemon {
} elsif ($service eq "devfs") {
$daemon = "devfsd";
} else {
- return 1;
+ $daemon = $service;
}
# Send the SIGHUP
run_program::rooted($prefix, "/usr/bin/killall", "-HUP", $daemon);
# CUPS needs some time to come up.
if ($service eq "cups") {
- sleep 5;
+ wait_for_cups();
}
return 1;
}
+sub wait_for_cups {
+ # CUPS needs some time to come up. Wait up to 30 seconds, checking
+ # whether CUPS is ready.
+ my $cupsready = 0;
+ my $i;
+ for ($i = 0; $i < 30; $i++) {
+ run_program::rooted($prefix, "/usr/bin/lpstat", "-r");
+ if (($? >> 8) != 0) {
+ # CUPS is not ready, continue
+ sleep 1;
+ } else {
+ # CUPS is ready, quit
+ $cupsready = 1;
+ last;
+ }
+ }
+ return cupsready;
+}
+
+sub assure_device_is_available_for_cups {
+ # Checks whether CUPS already "knows" a certain port, it does not
+ # know it usually when the appropriate kernel module is loaded
+ # after CUPS was started or when the printer is turned on after
+ # CUPS was started. CUPS 1.1.12 and newer refuses to set up queues
+ # on devices which it does not know, it points these queues to
+ # file:/dev/null instead. Restart CUPS if necessary to assure that
+ # CUPS knows the device.
+ my ($device) = @_;
+ local *F;
+ open F, ($::testing ? "$prefix" : "chroot $prefix/ ") .
+ "/bin/sh -c \"export LC_ALL=C; /usr/sbin/lpinfo -v\" |" ||
+ die "Could not run \"lpinfo\"!";
+ while (<F>) {
+ print "##### $device $_";
+ if ($_ =~ /$device/) { # Found a line containing the device name,
+ # so CUPS knows it.
+ close F;
+ return 1;
+ }
+ }
+ close F;
+ return SIGHUP_daemon("cups");
+}
+
+
sub network_running {
# If the network is not running return 0, otherwise 1.
local *F;
@@ -1168,7 +1229,7 @@ sub restart_queue($) {
for ($printer->{SPOOLER}) {
/cups/ && do {
#- restart cups.
- restart_service("cups"); sleep 1;
+ restart_service("cups");
last };
/lpr|lprng/ && do {
#- restart lpd.
diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm
index 87138b37b..c572a0e87 100644
--- a/perl-install/printerdrake.pm
+++ b/perl-install/printerdrake.pm
@@ -159,7 +159,6 @@ Normally, CUPS is automatically configured according to your network environment
$_ } @cupsd_conf;
}
printer::write_cupsd_conf(@cupsd_conf);
- sleep 3;
}
# Set auto-configuration state
if ($autoconf != $oldautoconf) {
@@ -344,6 +343,13 @@ _(" (Parallel Ports: /dev/lp0, /dev/lp1, ..., equivalent to LPT1:, LPT2:, ..., 1
$device = $menuchoice;
}
+ #- if CUPS is the spooler, make sure that CUPS knows the device
+ if ($printer->{SPOOLER} eq "cups") {
+ my $w = $in->wait_message
+ ('', _("Making printer port available for CUPS ..."));
+ printer::assure_device_is_available_for_cups($device);
+ }
+
#- make the DeviceURI from $device.
$printer->{currentqueue}{'connect'} = "file:" . $device;
@@ -2004,7 +2010,6 @@ sub main {
# is shown directly after having done an operation.
$menushown = 1;
# Initialize the cursor position
- #print "##### |$cursorpos|$printer->{DEFAULT}|\n";
if (($cursorpos eq "::") &&
($printer->{DEFAULT}) &&
($printer->{DEFAULT} ne "")) {