From 00ddfd4d05be1164bea6e50e84c77da8406336b0 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 3 Jun 2024 18:42:31 -0700 Subject: [PATCH] Also cleanup websockets --- cron/cron-lib.pl | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index 190cde671..7c9b6bcf3 100755 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -1567,28 +1567,31 @@ if (!$gconfig{'tempdelete_days'}) { print STDERR "Temp file clearing is disabled\n"; return; } + +# Cleanup files in /tmp/.webmin if ($gconfig{'tempdir'} && !$gconfig{'tempdirdelete'}) { print STDERR "Temp file clearing is not done for the custom directory $gconfig{'tempdir'}\n"; - return; } - -local $tempdir = &transname(); -$tempdir =~ s/\/([^\/]+)$//; -if (!$tempdir || $tempdir eq "/") { - $tempdir = "/tmp/.webmin"; - } - -local $cutoff = time() - $gconfig{'tempdelete_days'}*24*60*60; -opendir(DIR, $tempdir); -foreach my $f (readdir(DIR)) { - next if ($f eq "." || $f eq ".."); - local @st = lstat("$tempdir/$f"); - if ($st[9] < $cutoff) { - &unlink_file("$tempdir/$f"); +else { + local $tempdir = &transname(); + $tempdir =~ s/\/([^\/]+)$//; + if (!$tempdir || $tempdir eq "/") { + $tempdir = "/tmp/.webmin"; } - } -closedir(DIR); + local $cutoff = time() - $gconfig{'tempdelete_days'}*24*60*60; + opendir(DIR, $tempdir); + foreach my $f (readdir(DIR)) { + next if ($f eq "." || $f eq ".."); + local @st = lstat("$tempdir/$f"); + if ($st[9] < $cutoff) { + &unlink_file("$tempdir/$f"); + } + } + closedir(DIR); + } + +# Delete stale lock files my $lockdir = $var_directory."/locks"; opendir(DIR, $lockdir); foreach my $f (readdir(DIR)) { @@ -1600,6 +1603,12 @@ foreach my $f (readdir(DIR)) { } } closedir(DIR); + +# Cleanup old websockets +if (&foreign_check("xterm")) { + &foreign_require("xterm"); + &xterm::cleanup_miniserv_websockets(); + } } =head2 list_cron_files()