[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 12 Nov 2003 19:51:43 -0000


This is a MIME encoded message

--albertel1068666703
Content-Type: text/plain

albertel		Wed Nov 12 14:51:43 2003 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - converting from Apache::File to open()
  
  
  
--albertel1068666703
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031112145143.txt"

Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.447 loncom/lonnet/perl/lonnet.pm:1.448
--- loncom/lonnet/perl/lonnet.pm:1.447	Tue Nov 11 15:10:32 2003
+++ loncom/lonnet/perl/lonnet.pm	Wed Nov 12 14:51:43 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.447 2003/11/11 20:10:32 www Exp $
+# $Id: lonnet.pm,v 1.448 2003/11/12 19:51:43 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,7 +30,6 @@
 package Apache::lonnet;
 
 use strict;
-use Apache::File;
 use LWP::UserAgent();
 use HTTP::Headers;
 use vars 
@@ -56,8 +55,8 @@
 
 sub logtouch {
     my $execdir=$perlvar{'lonDaemons'};
-    unless (-e "$execdir/logs/lonnet.log") {
-	my $fh=Apache::File->new(">>$execdir/logs/lonnet.log");
+    unless (-e "$execdir/logs/lonnet.log") {	
+	open(my $fh,">>$execdir/logs/lonnet.log");
 	close $fh;
     }
     my ($wwwuid,$wwwgid)=(getpwnam('www'))[2,3];
@@ -69,8 +68,10 @@
     my $execdir=$perlvar{'lonDaemons'};
     my $now=time;
     my $local=localtime($now);
-    my $fh=Apache::File->new(">>$execdir/logs/lonnet.log");
-    print $fh "$local ($$): $message\n";
+    if (open(my $fh,">>$execdir/logs/lonnet.log")) {
+	print $fh "$local ($$): $message\n";
+	close($fh);
+    }
     return 1;
 }
 
@@ -79,8 +80,10 @@
     my $execdir=$perlvar{'lonDaemons'};
     my $now=time;
     my $local=localtime($now);
-    my $fh=Apache::File->new(">>$execdir/logs/lonnet.perm.log");
-    print $fh "$now:$message:$local\n";
+    if (open(my $fh,">>$execdir/logs/lonnet.perm.log")) {
+	print $fh "$now:$message:$local\n";
+	close($fh);
+    }
     return 1;
 }
 
@@ -132,7 +135,7 @@
     my $peerfile=shift;
     &logthis("Trying to reconnect for $peerfile");
     my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
-    if (my $fh=Apache::File->new("$loncfile")) {
+    if (open(my $fh,"<$loncfile")) {
 	my $loncpid=<$fh>;
         chomp($loncpid);
         if (kill 0 => $loncpid) {
@@ -180,18 +183,20 @@
       "$perlvar{'lonSockDir'}/delayed/$now.$dumpcount.$$.$middlename.$server";
             $dumpcount++;
             {
-             my $dfh;
-             if ($dfh=Apache::File->new(">$dfilename")) {
-                print $dfh "$cmd\n";
-	     }
+		my $dfh;
+		if (open($dfh,">$dfilename")) {
+		    print $dfh "$cmd\n"; 
+		    close($dfh);
+		}
             }
             sleep 2;
             my $wcmd='';
             {
-	     my $dfh;
-             if ($dfh=Apache::File->new("$dfilename")) {
-                $wcmd=<$dfh>;
-	     }
+		my $dfh;
+		if (open($dfh,"<$dfilename")) {
+		    $wcmd=<$dfh>; 
+		    close($dfh);
+		}
             }
             chomp($wcmd);
             if ($wcmd eq $cmd) {
@@ -230,10 +235,10 @@
     my ($lonidsdir,$handle)=@_;
     my @profile;
     {
-	my $idf=Apache::File->new("$lonidsdir/$handle.id");
+	open(my $idf,"$lonidsdir/$handle.id");
 	flock($idf,LOCK_SH);
 	@profile=<$idf>;
-	$idf->close();
+	close($idf);
     }
     my $envi;
     my %Remove;
@@ -269,47 +274,47 @@
     }
 
     my $lockfh;
-    unless ($lockfh=Apache::File->new("$ENV{'user.environment'}")) {
-       return 'error: '.$!;
+    unless (open($lockfh,"$ENV{'user.environment'}")) {
+	return 'error: '.$!;
     }
     unless (flock($lockfh,LOCK_EX)) {
          &logthis("<font color=blue>WARNING: ".
                   'Could not obtain exclusive lock in appenv: '.$!);
-         $lockfh->close();
+         close($lockfh);
          return 'error: '.$!;
     }
 
     my @oldenv;
     {
-     my $fh;
-     unless ($fh=Apache::File->new("$ENV{'user.environment'}")) {
-	return 'error: '.$!;
-     }
-     @oldenv=<$fh>;
-     $fh->close();
+	my $fh;
+	unless (open($fh,"$ENV{'user.environment'}")) {
+	    return 'error: '.$!;
+	}
+	@oldenv=<$fh>;
+	close($fh);
     }
     for (my $i=0; $i<=$#oldenv; $i++) {
         chomp($oldenv[$i]);
         if ($oldenv[$i] ne '') {
-           my ($name,$value)=split(/=/,$oldenv[$i]);
-           unless (defined($newenv{$name})) {
-	      $newenv{$name}=$value;
-	   }
+	    my ($name,$value)=split(/=/,$oldenv[$i]);
+	    unless (defined($newenv{$name})) {
+		$newenv{$name}=$value;
+	    }
         }
     }
     {
-     my $fh;
-     unless ($fh=Apache::File->new(">$ENV{'user.environment'}")) {
-	return 'error';
-     }
-     my $newname;
-     foreach $newname (keys %newenv) {
-	 print $fh "$newname=$newenv{$newname}\n";
-     }
-     $fh->close();
+	my $fh;
+	unless (open($fh,">$ENV{'user.environment'}")) {
+	    return 'error';
+	}
+	my $newname;
+	foreach $newname (keys %newenv) {
+	    print $fh "$newname=$newenv{$newname}\n";
+	}
+	close($fh);
     }
-
-    $lockfh->close();
+	
+    close($lockfh);
     return 'ok';
 }
 # ----------------------------------------------------- Delete from Environment
@@ -324,34 +329,34 @@
     }
     my @oldenv;
     {
-     my $fh;
-     unless ($fh=Apache::File->new("$ENV{'user.environment'}")) {
-	return 'error';
-     }
-     unless (flock($fh,LOCK_SH)) {
-         &logthis("<font color=blue>WARNING: ".
-                  'Could not obtain shared lock in delenv: '.$!);
-         $fh->close();
-         return 'error: '.$!;
-     }
-     @oldenv=<$fh>;
-     $fh->close();
+	my $fh;
+	unless (open($fh,"$ENV{'user.environment'}")) {
+	    return 'error';
+	}
+	unless (flock($fh,LOCK_SH)) {
+	    &logthis("<font color=blue>WARNING: ".
+		     'Could not obtain shared lock in delenv: '.$!);
+	    close($fh);
+	    return 'error: '.$!;
+	}
+	@oldenv=<$fh>;
+	close($fh);
     }
     {
-     my $fh;
-     unless ($fh=Apache::File->new(">$ENV{'user.environment'}")) {
-	return 'error';
-     }
-     unless (flock($fh,LOCK_EX)) {
-         &logthis("<font color=blue>WARNING: ".
-                  'Could not obtain exclusive lock in delenv: '.$!);
-         $fh->close();
-         return 'error: '.$!;
-     }
-     foreach (@oldenv) {
-	 unless ($_=~/^$delthis/) { print $fh $_; }
-     }
-     $fh->close();
+	my $fh;
+	unless (open($fh,">$ENV{'user.environment'}")) {
+	    return 'error';
+	}
+	unless (flock($fh,LOCK_EX)) {
+	    &logthis("<font color=blue>WARNING: ".
+		     'Could not obtain exclusive lock in delenv: '.$!);
+	    close($fh);
+	    return 'error: '.$!;
+	}
+	foreach (@oldenv) {
+	    unless ($_=~/^$delthis/) { print $fh $_; }
+	}
+	close($fh);
     }
     return 'ok';
 }
@@ -387,10 +392,11 @@
     unless ($checkserver) { $checkserver=$perlvar{'lonHostID'}; }
     my $loadavg;
     if ($checkserver eq $perlvar{'lonHostID'}) {
-       my $loadfile=Apache::File->new('/proc/loadavg');
+       open(my $loadfile,'/proc/loadavg');
        $loadavg=<$loadfile>;
        $loadavg =~ s/\s.*//g;
        $loadavg = 100*$loadavg/$perlvar{'lonLoadLim'};
+       close($loadfile);
     } else {
        $loadavg=&reply('load',$checkserver);
     }
@@ -1229,8 +1235,9 @@
     }
 # Save the file
     {
-       my $fh=Apache::File->new('>'.$filepath.'/'.$fname);
+       open(my $fh,'>'.$filepath.'/'.$fname);
        print $fh $ENV{'form.'.$formname};
+       close($fh);
     }
 # Notify homeserver to grep it
 #
@@ -1454,10 +1461,11 @@
 }
 
 sub getannounce {
-    if (my $fh=Apache::File->new($perlvar{'lonDocRoot'}.'/announcement.txt')) {
+
+    if (open(my $fh,$perlvar{'lonDocRoot'}.'/announcement.txt')) {
 	my $announcement='';
 	while (<$fh>) { $announcement .=$_; }
-	$fh->close();
+	close($fh);
 	if ($announcement=~/\w/) { 
 	    return 
    '<table bgcolor="#FF5555" cellpadding="5" cellspacing="3">'.
@@ -2844,9 +2852,9 @@
     for (1..100) {
 	sleep 2;
         if (-e $replyfile.'.end') {
-	    if (my $fh=Apache::File->new($replyfile)) {
+	    if (open(my $fh,$replyfile)) {
                $reply.=<$fh>;
-               $fh->close;
+               close($fh);
 	   } else { return 'error: reply_file_error'; }
            return &unescape($reply);
 	}
@@ -4337,7 +4345,8 @@
  } else { # normal file from res space
   &repcopy($file);
   if (! -e $file ) { return -1; };
-  my $fh=Apache::File->new($file);
+  my $fh;
+  open($fh,"<$file");
   my $a='';
   while (<$fh>) { $a .=$_; }
   return $a;
@@ -4453,7 +4462,7 @@
 # ----------------------------------- Read loncapa.conf and loncapa_apache.conf
     unless ($readit) {
 {
-    my $config=Apache::File->new("/etc/httpd/conf/loncapa.conf");
+    open(my $config,"</etc/httpd/conf/loncapa.conf");
 
     while (my $configline=<$config>) {
         if ($configline =~ /^[^\#]*PerlSetVar/) {
@@ -4462,9 +4471,10 @@
            $perlvar{$varname}=$varvalue;
         }
     }
+    close($config);
 }
 {
-    my $config=Apache::File->new("/etc/httpd/conf/loncapa_apache.conf");
+    open(my $config,"</etc/httpd/conf/loncapa_apache.conf");
 
     while (my $configline=<$config>) {
         if ($configline =~ /^[^\#]*PerlSetVar/) {
@@ -4473,16 +4483,16 @@
            $perlvar{$varname}=$varvalue;
         }
     }
+    close($config);
 }
 
 # ------------------------------------------------------------ Read domain file
 {
-    my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
-                            '/domain.tab');
     %domaindescription = ();
     %domain_auth_def = ();
     %domain_auth_arg_def = ();
-    if ($fh) {
+    my $fh;
+    if (open($fh,"<".$Apache::lonnet::perlvar{'lonTabDir'}.'/domain.tab')) {
        while (<$fh>) {
            next if (/^(\#|\s*$)/);
 #           next if /^\#/;
@@ -4497,16 +4507,17 @@
 	   $domain_longi{$domain}=$longi;
 	   $domain_lati{$domain}=$lati;
 
-#          &logthis("Domain.tab: $domain, $domain_auth_def{$domain}, $domain_auth_arg_def{$domain},$domaindescription{$domain}");
+ #         &logthis("Domain.tab: $domain, $domain_auth_def{$domain}, $domain_auth_arg_def{$domain},$domaindescription{$domain}");
 #          &logthis("Domain.tab: $domain ".$domaindescription{$domain} );
-       }
+	}
     }
+    close ($fh);
 }
 
 
 # ------------------------------------------------------------- Read hosts file
 {
-    my $config=Apache::File->new("$perlvar{'lonTabDir'}/hosts.tab");
+    open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab");
 
     while (my $configline=<$config>) {
        next if ($configline =~ /^(\#|\s*$)/);
@@ -4524,11 +4535,12 @@
 	 }
        }
     }
+    close($config);
 }
 
 # ------------------------------------------------------ Read spare server file
 {
-    my $config=Apache::File->new("$perlvar{'lonTabDir'}/spare.tab");
+    open(my $config,"<$perlvar{'lonTabDir'}/spare.tab");
 
     while (my $configline=<$config>) {
        chomp($configline);
@@ -4536,46 +4548,50 @@
           $spareid{$configline}=1;
        }
     }
+    close($config);
 }
 # ------------------------------------------------------------ Read permissions
 {
-    my $config=Apache::File->new("$perlvar{'lonTabDir'}/roles.tab");
+    open(my $config,"<$perlvar{'lonTabDir'}/roles.tab");
 
     while (my $configline=<$config>) {
-       chomp($configline);
-      if ($configline) {
-       my ($role,$perm)=split(/ /,$configline);
-       if ($perm ne '') { $pr{$role}=$perm; }
-      }
+	chomp($configline);
+	if ($configline) {
+	    my ($role,$perm)=split(/ /,$configline);
+	    if ($perm ne '') { $pr{$role}=$perm; }
+	}
     }
+    close($config);
 }
 
 # -------------------------------------------- Read plain texts for permissions
 {
-    my $config=Apache::File->new("$perlvar{'lonTabDir'}/rolesplain.tab");
+    open(my $config,"<$perlvar{'lonTabDir'}/rolesplain.tab");
 
     while (my $configline=<$config>) {
-       chomp($configline);
-      if ($configline) {
-       my ($short,$plain)=split(/:/,$configline);
-       if ($plain ne '') { $prp{$short}=$plain; }
-      }
+	chomp($configline);
+	if ($configline) {
+	    my ($short,$plain)=split(/:/,$configline);
+	    if ($plain ne '') { $prp{$short}=$plain; }
+	}
     }
+    close($config);
 }
 
 # ---------------------------------------------------------- Read package table
 {
-    my $config=Apache::File->new("$perlvar{'lonTabDir'}/packages.tab");
+    open(my $config,"<$perlvar{'lonTabDir'}/packages.tab");
 
     while (my $configline=<$config>) {
-       chomp($configline);
-       my ($short,$plain)=split(/:/,$configline);
-       my ($pack,$name)=split(/\&/,$short);
-       if ($plain ne '') {
-          $packagetab{$pack.'&'.$name.'&name'}=$name; 
-          $packagetab{$short}=$plain; 
-       }
+	chomp($configline);
+	my ($short,$plain)=split(/:/,$configline);
+	my ($pack,$name)=split(/\&/,$short);
+	if ($plain ne '') {
+	    $packagetab{$pack.'&'.$name.'&name'}=$name; 
+	    $packagetab{$short}=$plain; 
+	}
     }
+    close($config);
 }
 
 # ------------- set up temporary directory

--albertel1068666703--