[LON-CAPA-cvs] cvs: loncom(version_2_11_X) / loncron

raeburn raeburn at source.lon-capa.org
Wed May 6 10:40:08 EDT 2020


raeburn		Wed May  6 14:40:08 2020 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom	loncron 
  Log:
  - For 2.11
    Backport 1.122 1.123
  
  
Index: loncom/loncron
diff -u loncom/loncron:1.103.2.6 loncom/loncron:1.103.2.7
--- loncom/loncron:1.103.2.6	Sat Jan 11 22:39:55 2020
+++ loncom/loncron	Wed May  6 14:40:08 2020
@@ -2,7 +2,7 @@
 
 # Housekeeping program, started by cron, loncontrol and loncron.pl
 #
-# $Id: loncron,v 1.103.2.6 2020/01/11 22:39:55 raeburn Exp $
+# $Id: loncron,v 1.103.2.7 2020/05/06 14:40:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -42,6 +42,8 @@
 use HTML::Entities;
 use Getopt::Long;
 use File::Copy;
+use Sys::Hostname::FQDN();
+
 #globals
 use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount);
 
@@ -488,19 +490,38 @@
     my $cleaned=0;
     my $active=0;
     while (my $fname=<$perlvar{'lonIDsDir'}/*>) {
-	my ($dev,$ino,$mode,$nlink,
-	    $uid,$gid,$rdev,$size,
-	    $atime,$mtime,$ctime,
-	    $blksize,$blocks)=stat($fname);
-	my $now=time;
-	my $since=$now-$mtime;
-	if ($since>$perlvar{'lonExpire'}) {
-	    $cleaned++;
-	    &log($fh,"Unlinking $fname<br />");
-	    unlink("$fname");
-	} else {
-	    $active++;
-	}
+        my $now=time;
+        if (-l $fname) {
+            my $linkfname = readlink($fname);
+            if (-f $linkfname) {
+                if ($linkfname =~ m{^$perlvar{'lonIDsDir'}/[^/]+\.id$}) {
+                    my @data = stat($linkfname);
+                    my $mtime = $data[9];
+                    my $since=$now-$mtime;
+                    if ($since>$perlvar{'lonExpire'}) {
+                        if (unlink($linkfname)) {
+                            $cleaned++;
+                            &log($fh,"Unlinking $linkfname<br />");
+                            unlink($fname);
+                        }
+                    }
+                }
+            } else {
+               unlink($fname);
+            }
+        } elsif (-f $fname) {
+            my @data = stat($fname);
+            my $mtime = $data[9];
+            my $since=$now-$mtime;
+            if ($since>$perlvar{'lonExpire'}) {
+                if (unlink($fname)) {
+                    $cleaned++;
+                    &log($fh,"Unlinking $fname<br />");
+                }
+            } else {
+                $active++;
+            }
+        }
     }
     &log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>");
     &log($fh,"<h3>$active open session(s)</h3>");
@@ -1030,9 +1051,10 @@
     if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
 	print("Unconfigured machine.\n");
 	my $emailto=$perlvar{'lonSysEMail'};
-	my $hostname=`/bin/hostname`;
-	chop $hostname;
-	$hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
+	my $hostname = Sys::Hostname::FQDN::fqdn();
+	$hostname=~s/\.+/./g;
+	$hostname=~s/\-+/-/g;
+	$hostname=~s/[^\w\.-]//g; # make sure is safe to pass through shell
 	my $subj="LON: Unconfigured machine $hostname";
 	system("echo 'Unconfigured machine $hostname.' |".
                " mail -s '$subj' $emailto > /dev/null");




More information about the LON-CAPA-cvs mailing list