[LON-CAPA-cvs] cvs: loncom / loncron

raeburn raeburn at source.lon-capa.org
Thu Oct 24 16:50:05 EDT 2024


raeburn		Thu Oct 24 20:50:05 2024 EDT

  Modified files:              
    /loncom	loncron 
  Log:
  - Use three-argument open() to separate file mode from the filename.
  - Report if a file could not be opened for writing.
  
  
Index: loncom/loncron
diff -u loncom/loncron:1.134 loncom/loncron:1.135
--- loncom/loncron:1.134	Thu Oct 24 19:48:51 2024
+++ loncom/loncron	Thu Oct 24 20:50:05 2024
@@ -2,7 +2,7 @@
 
 # Housekeeping program, started by cron, loncontrol and loncron.pl
 #
-# $Id: loncron,v 1.134 2024/10/24 19:48:51 raeburn Exp $
+# $Id: loncron,v 1.135 2024/10/24 20:50:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1030,10 +1030,12 @@
         }
     }
     if ($output) {
-        if (open(my $fh,">$perlvar{'lonTabDir'}/loncaparevs.tab")) {
+        if (open(my $fh,'>',"$perlvar{'lonTabDir'}/loncaparevs.tab")) {
             print $fh $output;
             close($fh);
             &Apache::lonnet::load_loncaparevs();
+        } else {
+            print "Could not write to $perlvar{'lonTabDir'}/loncaparevs.tab\n"; 
         }
     }
     return;
@@ -1066,10 +1068,12 @@
         }
     }
     if ($output) {
-        if (open(my $fh,">$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
+        if (open(my $fh,'>',"$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
             print $fh $output;
             close($fh);
             &Apache::lonnet::load_serverhomeIDs();
+        } else {
+            print "Could not write to $perlvar{'lonTabDir'}/serverhomeIDs.tab\n";
         }
     }
     return;
@@ -1130,6 +1134,8 @@
             }
             close($fh);
             chmod(0644,$newfile);
+        } else {
+            print "Could not write to $lontabdir/currhostips.tab\n";
         }
     }
     if (keys(%prevhosts) && keys(%currhosts)) {
@@ -1155,6 +1161,8 @@
                 }
                 print $fh "\n*******************\n\n";
                 close($fh);
+            } else {
+                print "Could not write to $perlvar{'lonDaemons'}/logs/hostip.log\n";
             }
             my $emailto = &Apache::loncommon::build_recipient_list(undef,
                                    'hostipmail',$defdom);
@@ -1258,6 +1266,8 @@
                 }
                 close($fh);
                 print "Completed writing SSL options for lonc/lond for $count items.\n";
+            } else {
+                print "Could not write to $perlvar{'lonTabDir'}/connectionrules.tab\n";
             }
         } else {
             print "Writing of SSL options skipped - no connection rules in domain configuration.\n";
@@ -1363,6 +1373,8 @@
                 }
                 close($fh);
                 print "Completed writing host type data for $count hosts.\n";
+            } else {
+                print "Could not write to $perlvar{'lonTabDir'}/hosttypes.tab\n";
             }
         } else {
             print "Writing of host types skipped - no hosts found.\n";
@@ -1668,7 +1680,7 @@
                       "Subject: ".$subj."\n".
                       "Content-type: text/html\; charset=UTF-8\n".
                       "MIME-Version: 1.0\n\n";
-    if (open(my $fh,"<$statusdir/index.html")) {
+    if (open(my $fh,'<',$statusdir/index.html")) {
         while (<$fh>) {
             $loncronmail .= $_;
         }
@@ -1784,7 +1796,7 @@
         my $now = time;
         my $tmpfile = $perlvar{'lonDaemons'}.'/tmp/lciptables_iphost_'.
                       $now.$$.int(rand(10000));
-        if (open(my $fh,">$tmpfile")) {
+        if (open(my $fh,'>',"$tmpfile")) {
             my %iphosts = &Apache::lonnet::get_iphost();
             foreach my $key (keys(%iphosts)) {
                 print $fh "$key\n";




More information about the LON-CAPA-cvs mailing list