@@ -602,9 +602,9 @@ sub install_yaboot { open F, ">$::prefix/boot/message" and print F $lilo->{message} or $lilo->{message} = 0; } { - local *F; local $\ = "\n"; my $f = "$::prefix/etc/yaboot.conf"; + local *F; open F, ">$f" or die "cannot create yaboot config file: $f"; log::l("writing yaboot config to $f"); @@ -701,10 +701,10 @@ sub install_silo { open F, ">$::prefix/boot/message" and print F $silo->{message} or $silo->{message} = 0; } { - local *F; local $\ = "\n"; my $f = "$::prefix/boot/silo.conf"; #- always write the silo.conf file in /boot ... symlinkf "../boot/silo.conf", "$::prefix/etc/silo.conf"; #- ... and make a symlink from /etc. + local *F; open F, ">$f" or die "cannot create silo config file: $f"; log::l("writing silo config to $f"); @@ -788,10 +788,10 @@ sub write_lilo_conf { } { - local *F; local $\ = "\n"; my $f = arch() =~ /ia64/ ? "$::prefix/boot/efi/elilo.conf" : "$::prefix/etc/lilo.conf"; + local *F; open F, ">$f" or die "cannot create lilo config file: $f"; log::l("writing lilo config to $f"); @@ -912,9 +912,9 @@ sub write_grub_config { dev2grub($part->{device}, \%dev2bios) . $file; }; { - local *F; local $\ = "\n"; my $f = "$::prefix/boot/grub/menu.lst"; + local *F; open F, ">$f" or die "cannot create grub config file: $f"; log::l("writing grub config to $f"); @@ -235,6 +235,7 @@ sub ps { require c; my $page = c::getpagesize() / 1024; + local *PS; open PS, ">&STDOUT"; format PS_TOP = PID RSS %CPU CMD @@ -426,7 +427,7 @@ sub route { my ($titles, @l) = cat_("/proc/net/route"); my @titles = split ' ', $titles; my %l; - open ROUTE, ">&STDOUT"; + open ROUTE, ">&STDOUT"; #-# ROUTE must be not be localised otherwise the "format ROUTE" fails format ROUTE_TOP = Destination Gateway Mask Iface . @@ -447,6 +448,7 @@ $l{Destination}, $l{Gateway}, $l{Mask}, $l{Iface} sub df { my ($h) = getopts(\@_, qw(h)); my ($dev, $size, $free, $used, $use, $mntpoint); + local *DF; open DF, ">&STDOUT"; format DF_TOP = Filesystem Size Used Avail Use Mounted on @@ -619,6 +619,7 @@ sub whatUsbport() { my $realport = devices::make($port); next if !$realport; next if ! -r $realport; + local *PORT; open PORT, $realport or do next; my $idstr = ""; # Calculation of IOCTL function 0x84005001 (to get device ID @@ -127,7 +127,7 @@ sub getFile { #- to other to avoid media change... my $f2 = "$postinstall_rpms/$f"; $f2 = "/tmp/image/$rel" if !$postinstall_rpms || !-e $f2; - open GETFILE, $f2 and *GETFILE; + local *F; open F, $f2 and *F; } } || errorOpeningFile($f); } @@ -586,8 +586,8 @@ sub install_urpmi { foreach (sort { $a->{medium} <=> $b->{medium} } values %$mediums) { my $name = $_->{fakemedium}; if ($_->{ignored} || $_->{selected}) { - local *LIST; my $mask = umask 077; + local *LIST; open LIST, ">$prefix/var/lib/urpmi/list.$name" or log::l("failed to write list.$name"); umask $mask; @@ -608,9 +608,9 @@ sub install_urpmi { } } else { #- need to use another method here to build synthesis. - local (*F, $_); - open F, "parsehdlist '$prefix/var/lib/urpmi/hdlist.$name.cz' |"; - while ($_ = <F>) { + local *F; open F, "parsehdlist '$prefix/var/lib/urpmi/hdlist.$name.cz' |"; + local $_; + while (<F>) { print LIST "$dir/$_"; } close F; @@ -39,9 +39,8 @@ sub new($$) { install_gtk::createXconf($f, @{$o->{mouse}}{"XMOUSETYPE", "device"}, $o->{mouse}{wacom}[0]); devices::make("/dev/kbd"); - local (*T1, *T2); - open T1, ">/dev/tty5"; - open T2, ">/dev/tty6"; + local *T1; open T1, ">/dev/tty5"; + local *T2; open T2, ">/dev/tty6"; my $launchX = sub { my $ok = 1; @@ -36,11 +36,11 @@ sub w { &l } sub openLog(;$) { if ($::isInstall) { if ($_[0]) { #- useLocal - open LOG, "> $_[0]"; + open LOG, "> $_[0]"; #-# } else { - open LOG, "> /dev/tty3"; + open LOG, "> /dev/tty3"; #-# } - open LOG2, ">> /tmp/ddebug.log"; + open LOG2, ">> /tmp/ddebug.log"; #-# select((select(LOG), $| = 1)[0]); select((select(LOG2), $| = 1)[0]); } @@ -146,17 +146,13 @@ sub add2hosts { my %l; $l{$_} = $hostname foreach @ips; - local *F; - if (-e $file) { - open F, $file or die "cannot open $file: $!"; - #/\s*(\S+)(.*)/ and $l{$1} ||= $2 foreach <F>; - foreach (<F>) { - m/\s*(\S+)(.*)/; - my ($ip, $host) = ($1, $2); - $l{$ip} ||= $host if $host !~ /^\s*$hostname\s*$/; - } + foreach (cat_($file)) { + m/\s*(\S+)(.*)/; + my ($ip, $host) = ($1, $2); + $l{$ip} ||= $host if $host !~ /^\s*$hostname\s*$/; } log::l("writing host information to $file"); + local *F; open F, ">$file" or die "cannot write $file: $!"; while (my ($ip, $v) = each %l) { $ip or next; @@ -207,6 +207,7 @@ sub test_connected { } sub connected2 { + local *KID_TO_READ; my $pid = open(KID_TO_READ, "-|"); if ($pid) { # parent $kid_pid = $pid; @@ -792,8 +792,8 @@ sub load { sub save { my ($hd, $file) = @_; my @h = @{$hd}{@fields2save}; - local *F; require Data::Dumper; + local *F; open F, ">$file" and print F Data::Dumper->Dump([\@h], ['$h']), "\0" or die N("Error writing to file %s", $file); @@ -725,7 +725,7 @@ sub openInstallLog { my ($prefix) = @_; my $f = "$prefix/root/drakx/install.log"; - open(LOG, ">> $f") ? log::l("opened $f") : log::l("Failed to open $f. No install log will be kept."); + open(LOG, ">> $f") ? log::l("opened $f") : log::l("Failed to open $f. No install log will be kept."); #-# *LOG or *LOG = log::F() or *LOG = *STDERR; CORE::select((CORE::select(LOG), $| = 1)[0]); c::rpmErrorSetCallback(fileno LOG); @@ -106,23 +106,16 @@ sub printer_type($) { sub get_default_spooler () { if (-f "$prefix$FOOMATIC_DEFAULT_SPOOLER") { - open DEFSPOOL, "< $prefix$FOOMATIC_DEFAULT_SPOOLER"; - my $spool = <DEFSPOOL>; + my $spool = cat_("$prefix$FOOMATIC_DEFAULT_SPOOLER") chomp $spool; - close DEFSPOOL; - return $spool if ($spool =~ /cups|lpd|lprng|pdq/); + return $spool if $spool =~ /cups|lpd|lprng|pdq/; } } sub set_default_spooler ($) { my ($printer) = @_; - # Make Foomatic config directory if it does not exist yet - mkdir "$prefix$FOOMATICCONFDIR" if !(-d "$prefix$FOOMATICCONFDIR"); # Mark the default driver in a file - open DEFSPOOL, "> $prefix$FOOMATIC_DEFAULT_SPOOLER" or - die "Cannot create $prefix$FOOMATIC_DEFAULT_SPOOLER!"; - print DEFSPOOL $printer->{SPOOLER}; - close DEFSPOOL; + output_p("$prefix$FOOMATIC_DEFAULT_SPOOLER", $printer->{SPOOLER}); } sub set_permissions { @@ -497,13 +490,13 @@ sub getIPsInLocalNetworks { while (<F>) { chomp; push @addresses, $_ } close F; if (-x "/usr/bin/nmblookup") { + local *F; open F, ($::testing ? "" : "chroot $prefix/ ") . "/bin/sh -c \"export LC_ALL=C; nmblookup -B $bcast \\* | cut -f 1 -d ' ' | egrep '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' | uniq | sort\" |" or next; local $_; while (<F>) { chomp; push @addresses, $_ if !(member($_,@addresses)) } - close F; } } @@ -884,11 +877,11 @@ sub read_printer_db(;$) { # Generate the Foomatic printer/driver overview, read it from the # appropriate file when it is already generated if (!(-f $dbpath)) { - open DBPATH, ($::testing ? $prefix : "chroot $prefix/ ") . + open DBPATH, ($::testing ? $prefix : "chroot $prefix/ ") . #-# "foomatic-configure -O -q |" or die "Could not run foomatic-configure"; } else { - open DBPATH, $dbpath or die "An error occurred on $dbpath : $!"; + open DBPATH, $dbpath or die "An error occurred on $dbpath : $!"; #-# } my $entry = {}; @@ -1036,10 +1029,10 @@ sub read_cups_options ($) { # reuse the dialog local *F; if ($queue_or_file =~ /.ppd.gz$/) { # compressed PPD file - open F, ($::testing ? $prefix : "chroot $prefix/ ") . + open F, ($::testing ? $prefix : "chroot $prefix/ ") . #-# "gunzip -cd $queue_or_file | lphelp - |" or return 0; } else { # PPD file not compressed or queue - open F, ($::testing ? $prefix : "chroot $prefix/ ") . + open F, ($::testing ? $prefix : "chroot $prefix/ ") . #-# "lphelp $queue_or_file |" or return 0; } my $i; @@ -1199,15 +1192,8 @@ sub set_cups_autoconf { my $autoconf = $_[0]; # Read config file - local *F; my $file = "$prefix/etc/sysconfig/printing"; - if (!(-f $file)) { - @file_content = (); - } else { - open F, "< $file" or die "Cannot open $file!"; - @file_content = <F>; - close F; - } + @file_content = cat_($file); # Remove all valid "CUPS_CONFIG" lines (/^\s*CUPS_CONFIG/ and $_ = "") foreach @file_content; @@ -1219,10 +1205,7 @@ sub set_cups_autoconf { push @file_content, "CUPS_CONFIG=manual\n"; } - # Write back modified file - open F, "> $file" or die "Cannot open $file!"; - print F @file_content; - close F; + output($file, @file_content); # Restart CUPS restart_service("cups"); @@ -1247,15 +1230,8 @@ sub set_usermode { $::expert = $usermode; # Read config file - local *F; my $file = "$prefix/etc/sysconfig/printing"; - if (!(-f $file)) { - @file_content = (); - } else { - open F, "< $file" or die "Cannot open $file!"; - @file_content = <F>; - close F; - } + @file_content = cat_($file); # Remove all valid "USER_MODE" lines (/^\s*USER_MODE/ and $_ = "") foreach @file_content; @@ -1267,10 +1243,7 @@ sub set_usermode { push @file_content, "USER_MODE=recommended\n"; } - # Write back modified file - open F, "> $file" or die "Cannot open $file!"; - print F @file_content; - close F; + output($file, @file_content); return 1; } @@ -1312,22 +1285,12 @@ sub get_default_printer { } sub read_cupsd_conf { - my @cupsd_conf; - local *F; - - open F, "$prefix/etc/cups/cupsd.conf"; - @cupsd_conf = <F>; - close F; - - @cupsd_conf; + cat_("$prefix/etc/cups/cupsd.conf"); } sub write_cupsd_conf { my (@cupsd_conf) = @_; - local *F; - open F, ">$prefix/etc/cups/cupsd.conf"; - print F @cupsd_conf; - close F; + output("$prefix/etc/cups/cupsd.conf", @cupsd_conf); #- restart cups after updating configuration. restart_service("cups"); @@ -1481,7 +1444,6 @@ sub poll_ppd_base { sub configure_queue($) { my ($printer) = @_; - local *F; if ($printer->{currentqueue}{foomatic}) { #- Create the queue with "foomatic-configure", in case of queue @@ -1520,9 +1482,9 @@ sub configure_queue($) { # Add a comment line containing the path of the used PPD file to the # end of the PPD file if ($printer->{currentqueue}{ppd} ne '1') { + local *F; open F, ">> $prefix/etc/cups/ppd/$printer->{currentqueue}{queue}.ppd"; print F "*%MDKMODELCHOICE:$printer->{currentqueue}{ppd}\n"; - close F; } # Copy the old queue's PPD file to the new queue when it is renamed, # to conserve the option settings @@ -1730,10 +1692,9 @@ sub print_optionlist { sub get_copiable_queues { my ($oldspooler, $newspooler) = @_; - local *QUEUEOUTPUT; #- don't have to do close ... and don't modify globals - #- at least my @queuelist; #- here we will list all Foomatic-generated queues # Get queue list with foomatic-configure + local *QUEUEOUTPUT; open QUEUEOUTPUT, ($::testing ? $prefix : "chroot $prefix/ ") . "foomatic-configure -Q -q -s $oldspooler |" or die "Could not run foomatic-configure"; @@ -1925,14 +1886,14 @@ sub configure_hpoj { $device, split(' ',$address_arg)); } $device_ok = 0; + my $ptalprobedevice = $bus eq "hpjd" ? "hpjd:$hostname" : "mlc:$bus:probe"; local *F; - my $ptalprobedevice = - ($bus eq "hpjd" ? "hpjd:$hostname" : "mlc:$bus:probe"); if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid $ptalprobedevice |") { my $devid = join("", <F>); close F; if ($devid) { $device_ok = 1; + local *F; if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid $ptalprobedevice -long -mdl 2>/dev/null |") { $model_long = join("", <F>); close F; @@ -1947,7 +1908,7 @@ sub configure_hpoj { } } } - if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid $ptalprobedevice -long -sern 2>/dev/null |") { + if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid $ptalprobedevice -long -sern 2>/dev/null |") { #-# $serialnumber_long = join("", <F>); close F; chomp $serialnumber_long; @@ -1959,6 +1920,7 @@ sub configure_hpoj { } if ($bus ne "hpjd") { # Stop ptal-mlcd daemon for locally connected devices + local *F; if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "ps auxwww | grep \"ptal-mlcd $bus:probe\" | grep -v grep | ") { my $line = <F>; if ($line =~ /^\s*\S+\s+(\d+)\s+/) { @@ -2184,6 +2146,7 @@ drive s: file=\":3\" remote # for some photo cards. mtools_skip_check=1 "; + local *F open F, ">> $prefix/etc/mtools.conf" or die "can't write mtools config in /etc/mtools.conf: $!"; print F $mtoolsconf_append; @@ -2193,10 +2156,7 @@ mtools_skip_check=1
|