]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
- now support verstats for those who don't reply to "CTCP VERSION
[infobot.git] / src / IRC / Schedulers.pl
index 5851b642c40fd8b996759cd500800533ad991ad6..c325ab32e22afa416fa8c60ccc43a7dc8ff66678 100644 (file)
@@ -29,7 +29,7 @@ sub setupSchedulers {
     &leakCheck(2);     # mandatory
     &ignoreCheck(1);   # mandatory
     &seenFlushOld(2);
-    &ircCheck(2);      # mandatory
+    &ircCheck(1);      # mandatory
     &miscCheck(1);     # mandatory
     &miscCheck2(2);    # mandatory
     &shmFlush(1);      # mandatory
@@ -37,7 +37,7 @@ sub setupSchedulers {
     &freshmeatLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
-    &factoidCheck(2);
+    &factoidCheck(1);
     &newsFlush(1);
 
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
@@ -74,7 +74,7 @@ sub ScheduleThis {
     my $retval = $conn->schedule($waittime, \&$codename, @args);
     $sched{$codename}{LABEL}   = $retval;
     $sched{$codename}{TIME}    = time()+$waittime;
-    $sched{$codename}{RUNNING} = 1;
+    $sched{$codename}{LOOP}    = 1;
 }
 
 ####
@@ -86,11 +86,9 @@ sub randomQuote {
     if (@_) {
        &ScheduleThis($interval, "randomQuote");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"randomQuote"}{RUNNING};
     }
 
-    my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.randtext");
+    my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
     if (!defined $line) {
        &ERROR("random Quote: weird error?");
        return;
@@ -114,8 +112,6 @@ sub randomFactoid {
     if (@_) {
        &ScheduleThis($interval, "randomFactoid");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"randomFactoid"}{RUNNING};
     }
 
     while (1) {
@@ -146,8 +142,6 @@ sub randomFreshmeat {
     if (@_) {
        &ScheduleThis($interval, "randomFreshmeat");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"randomFreshmeat"}{RUNNING};
     }
 
     my @chans = &ChanConfList("randomFreshmeat");
@@ -169,8 +163,6 @@ sub logLoop {
     if (@_) {
        &ScheduleThis(60, "logLoop");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"logLoop"}{RUNNING};
     }
 
     return unless (defined fileno LOG);
@@ -202,13 +194,12 @@ sub logLoop {
     }
 
     ### check if all the logs exceed size.
-    my $logdir = "$bot_base_dir/log/";
-    if (opendir(LOGS, $logdir)) {
+    if (opendir(LOGS, $bot_log_dir)) {
        my $tsize = 0;
        my (%age, %size);
 
        while (defined($_ = readdir LOGS)) {
-           my $logfile         = "$logdir/$_";
+           my $logfile         = "$bot_log_dir/$_";
 
            next unless ( -f $logfile);
            my $size            = -s $logfile;
@@ -234,7 +225,7 @@ sub logLoop {
        ### TODO: add how many b,kb,mb removed?
        &status("LOG: removed $delete logs.") if ($delete);
     } else {
-       &WARN("could not open dir $logdir");
+       &WARN("could not open dir $bot_log_dir");
     }
 
 }
@@ -243,8 +234,6 @@ sub seenFlushOld {
     if (@_) {
        &ScheduleThis(1440, "seenFlushOld");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"seenFlushOld"}{RUNNING};
     }
 
     # is this global-only?
@@ -255,8 +244,17 @@ sub seenFlushOld {
     my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
     my $delete   = 0;
 
-    if ($param{'DBType'} =~ /^pg|postgres|mysql/i) {
-       my $query = "SELECT nick,time FROM seen GROUP BY nick HAVING UNIX_TIMESTAMP() - time > $max_time";
+    if ($param{'DBType'} =~ /^pgsql|mysql/i) {
+       my $query;
+
+       if ($param{'DBType'} =~ /^mysql$/i) {
+           $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
+                       "UNIX_TIMESTAMP() - time > $max_time";
+       } else {        # pgsql.
+           $query = "SELECT nick,time FROM seen WHERE ".
+               "extract(epoch from timestamp 'now') - time > $max_time";
+       }
+
        my $sth = $dbh->prepare($query);
        $sth->execute;
 
@@ -271,7 +269,7 @@ sub seenFlushOld {
        my $time = time();
 
        foreach (keys %seen) {
-           my $delta_time = $time - &dbGet("seen", "NULL", $_, "time");
+           my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
            next unless ($delta_time > $max_time);
 
            &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
@@ -287,17 +285,27 @@ sub seenFlushOld {
 
 sub newsFlush {
     if (@_) {
-       &ScheduleThis(1440, "newsFlush");
+       &ScheduleThis(60, "newsFlush");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"newsFlush"}{RUNNING};
     }
 
-    return unless (&IsChanConf("news") > 0);
+    if (!&ChanConfList("news")) {
+       &DEBUG("newsFlush: news disabled? (chan => $chan)");
+       return;
+    }
 
     my $delete = 0;
     my $oldest = time();
+    my %none;
     foreach $chan (keys %::news) {
+       my $i           = 0;
+       my $total       = scalar(keys %{ $::news{$chan} });
+
+       if (!$total) {
+           delete $::news{$chan};
+           next;
+       }
+
        foreach $item (keys %{ $::news{$chan} }) {
            my $t = $::news{$chan}{$item}{Expire};
 
@@ -311,17 +319,26 @@ sub newsFlush {
                next;
            }
 
+           my $delta = $t - time();
+
            next unless (time() > $t);
+
            # todo: show how old it was.
            delete $::news{$chan}{$item};
-           &VERB("NEWS: deleted '$item'", 2);
+           &status("NEWS: (newsflush) deleted '$item'");
            $delete++;
+           $i++;
        }
+
+       &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
+       $none{$chan} = 1 if ($total == $i);
     }
 
     # todo: flush users aswell.
     my $duser  = 0;
     foreach $chan (keys %::newsuser) {
+       next if (exists $none{$chan});
+
        foreach (keys %{ $::newsuser{$chan} }) {
            my $t = $::newsuser{$chan}{$_};
            if (!defined $t or ($t > 2 and $t < 1000)) {
@@ -334,12 +351,15 @@ sub newsFlush {
            delete $::newsuser{$chan}{$_};
            $duser++;
        }
-    }
 
-#    &VERB("NEWS deleted $delete seen entries.",2);
-    &status("NEWS deleted: $delete news entries; $duser user cache.");
+       my $i = scalar(keys %{ $::newsuser{$chan} });
+       delete $::newsuser{$chan} unless ($i);
+    }
 
-    &News::writeNews();
+    if ($delete or $duser) {
+       &News::writeNews();
+       &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
+    }
 }
 
 sub chanlimitCheck {
@@ -348,23 +368,42 @@ sub chanlimitCheck {
     if (@_) {
        &ScheduleThis($interval, "chanlimitCheck");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"chanlimitCheck"}{RUNNING};
     }
 
+    my $str = join(' ', &ChanConfList("chanlimitcheck") );
+
     foreach $chan ( &ChanConfList("chanlimitcheck") ) {
        next unless (&validChan($chan));
 
+       if ($chan eq "_default") {
+           &WARN("chanlimit: we're doing $chan!! HELP ME!");
+           next;
+       }
+
        my $limitplus   = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
        my $newlimit    = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
        my $limit       = $channels{$chan}{'l'};
 
+       if (scalar keys %netsplitservers) {
+           if (defined $limit) {
+               &status("chanlimit: netsplit; removing it for $chan.");
+               &rawout("MODE $chan -l");
+               $cache{chanlimitChange}{$chan} = time();
+               &status("chanlimit: netsplit; removed.");
+           }
+
+           next;
+       }
+
        if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
            &FIXME("LIMIT: set too low!!! FIXME");
            ### run NAMES again and flush it.
        }
 
-       next unless (!defined $limit or $limit != $newlimit);
+       if (defined $limit and $limit == $newlimit) {
+           $cache{chanlimitChange}{$chan} = time();
+           next;
+       }
 
        if (!exists $channels{$chan}{'o'}{$ident}) {
            &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
@@ -375,13 +414,13 @@ sub chanlimitCheck {
        delete $cache{warn}{chanlimit}{$chan};
 
        if (!defined $limit) {
-           &status("ChanLimit: setting for first time or from netsplit, for $chan");
+           &status("chanLimit: setting for first time or from netsplit, for $chan");
        }
 
        if (exists $cache{chanlimitChange}{$chan}) {
            my $delta = time() - $cache{chanlimitChange}{$chan};
            if ($delta < $interval*60) {
-               &DEBUG("not going to change chanlimit! ($delta<$interval*60)");
+               &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
                return;
            }
        }
@@ -395,37 +434,74 @@ sub netsplitCheck {
     my ($s1,$s2);
 
     if (@_) {
-       &ScheduleThis(30, "netsplitCheck");
+       &ScheduleThis(15, "netsplitCheck");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"netsplitCheck"}{RUNNING};
     }
 
+    $cache{'netsplitCache'}++;
+#    &DEBUG("running netsplitCheck... $cache{netsplitCache}");
+
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
+       undef %netsplitservers;
+       return;
+    }
+
+    # well... this shouldn't happen since %netsplit code does it anyway.
     foreach $s1 (keys %netsplitservers) {
+
        foreach $s2 (keys %{ $netsplitservers{$s1} }) {
-           if (time() - $netsplitservers{$s1}{$s2} > 3600) {
+           my $delta = time() - $netsplitservers{$s1}{$s2};
+
+           if ($delta > 60*30) {
                &status("netsplit between $s1 and $s2 appears to be stale.");
                delete $netsplitservers{$s1}{$s2};
+               &chanlimitCheck();
            }
        }
+
+       my $i = scalar(keys %{ $netsplitservers{$s1} });
+       delete $netsplitservers{$s1} unless ($i);
     }
 
     # %netsplit hash checker.
     my $count  = scalar keys %netsplit;
+    my $delete = 0;
     foreach (keys %netsplit) {
-       if (&IsNickInAnyChan($_)) {
-           &DEBUG("netsplitC: $_ is in some chan; removing from netsplit list.");
+       if (&IsNickInAnyChan($_)) {     # why would this happen?
+#          &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
            delete $netsplit{$_};
+           $delete++;
            next;
        }
-       next unless (time() - $netsplit{$_} > 60*10);
 
-       &DEBUG("netsplitC: $_ didn't come back from netsplit; removing from netsplit list.");
+       next unless (time() - $netsplit{$_} > 60*15);
+
+       $delete++;
        delete $netsplit{$_};
     }
 
+    # yet another hack.
+    foreach (keys %channels) {
+       my $i = $cache{maxpeeps}{$chan} || 0;
+       my $j = scalar(keys %{ $channels{$chan} });
+       next unless ($i > 10 and 0.25*$i > $j);
+
+       &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
+    }
+
+    if ($delete) {
+       my $j = scalar(keys %netsplit);
+       &status("nsC: removed from netsplit list: (before: $count; after: $j)");
+    }
+
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
+       undef %netsplitservers;
+    }
+
     if ($count and !scalar keys %netsplit) {
-       &DEBUG("ok, netsplit is hopefully gone. reinstating chanlimit check.");
+       &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
        &chanlimitCheck();
     }
 }
@@ -437,8 +513,6 @@ sub floodLoop {
     if (@_) {
        &ScheduleThis(60, "floodLoop"); # minutes.
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"floodLoop"}{RUNNING};
     }
 
     my $time           = time();
@@ -465,8 +539,6 @@ sub seenFlush {
        my $interval = &getChanConfDefault("seenFlushInterval", 60);
        &ScheduleThis($interval, "seenFlush");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"seenFlush"}{RUNNING};
     }
 
     my %stats;
@@ -476,26 +548,25 @@ sub seenFlush {
     $stats{'new'}      = 0;
     $stats{'old'}      = 0;
 
-    if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
+    if ($param{'DBType'} =~ /^(mysql|pgsql)$/i) {
        foreach $nick (keys %seencache) {
-           if (0) {
-           #BROKEN#
-           my $retval = &dbReplace("seen", "nick", $nick, (
-                       "nick" => $seencache{$nick}{'nick'},
+           my $retval = &dbReplace("seen", "nick", (
+                       "nick" => lc $seencache{$nick}{'nick'},
                        "time" => $seencache{$nick}{'time'},
                        "host" => $seencache{$nick}{'host'},
                        "channel" => $seencache{$nick}{'chan'},
                        "message" => $seencache{$nick}{'msg'},
            ) );
-           &DEBUG("retval => $retval.");
            delete $seencache{$nick};
            $flushed++;
 
            next;
-           }
-           ### OLD CODE...
 
-           my $exists = &dbGet("seen","nick", $nick, "nick");
+           ###
+           ### old code.
+           ###
+
+           my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
 
            if (defined $exists and $exists) {
                &dbUpdate("seen", "nick", $nick, (
@@ -544,12 +615,12 @@ sub seenFlush {
        &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
     }
 
-    &status("Flushed $flushed seen entries.")          if ($flushed);
+    &status("Seen: Flushed $flushed entries.") if ($flushed);
     &VERB(sprintf("  new seen: %03.01f%% (%d/%d)",
        $stats{'new'}*100/($stats{'count_old'} || 1),
-       $stats{'new'}, $stats{'count_old'} ), 2)        if ($stats{'new'});
+       $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
     &VERB(sprintf("  now seen: %3.1f%% (%d/%d)",
-       $stats{'old'}*100/&countKeys("seen"),
+       $stats{'old'}*100 / ( &countKeys("seen") || 1),
        $stats{'old'}, &countKeys("seen") ), 2)         if ($stats{'old'});
 
     &WARN("scalar keys seenflush != 0!")       if (scalar keys %seenflush);
@@ -562,17 +633,15 @@ sub leakCheck {
     if (@_) {
        &ScheduleThis(240, "leakCheck");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"leakCheck"}{RUNNING};
     }
 
-    # flood.
+    # flood. this is dealt with in floodLoop()
     foreach $blah1 (keys %flood) {
        foreach $blah2 (keys %{ $flood{$blah1} }) {
            $count += scalar(keys %{ $flood{$blah1}{$blah2} });
        }
     }
-    &DEBUG("leak: hash flood has $count total keys.",2);
+    &VERB("leak: hash flood has $count total keys.",2);
 
     # floodjoin.
     $count = 0;
@@ -581,11 +650,11 @@ sub leakCheck {
            $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
        }
     }
-    &DEBUG("leak: hash flood has $count total keys.",2);
+    &VERB("leak: hash floodjoin has $count total keys.",2);
 
     # floodwarn.
     $count = scalar(keys %floodwarn);
-    &DEBUG("leak: hash floodwarn has $count total keys.",2);
+    &VERB("leak: hash floodwarn has $count total keys.",2);
 
     my $chan;
     foreach $chan (grep /[A-Z]/, keys %channels) {
@@ -598,6 +667,11 @@ sub leakCheck {
        }
     }
 
+    # chanstats
+    $count = scalar(keys %chanstats);
+    &VERB("leak: hash chanstats has $count total keys.",2);
+
+    # nuh.
     my $delete = 0;
     foreach (keys %nuh) {
        next if (&IsNickInAnyChan($_));
@@ -615,8 +689,6 @@ sub ignoreCheck {
     if (@_) {
        &ScheduleThis(60, "ignoreCheck");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"ignoreCheck"}{RUNNING};
     }
 
     my $time   = time();
@@ -635,22 +707,27 @@ sub ignoreCheck {
            $count++;
        }
     }
+
+    $cache{ignoreCheckTime} = time();
+
     &VERB("ignore: $count items deleted.",2);
 }
 
 sub ircCheck {
     if (@_) {
-       &ScheduleThis(60, "ircCheck");
+       &ScheduleThis(15, "ircCheck");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"ircCheck"}{RUNNING};
     }
 
-    my @array = grep !/^_default$/, keys %chanconf;
-    my $iconf = scalar(@array);
-    my $inow  = scalar(keys %channels);
+    $cache{statusSafe} = 1;
+
+    my @x      = &getJoinChans();
+    my $iconf  = scalar( @x );
+    my $inow   = scalar( keys %channels );
     if ($iconf > 2 and $inow * 2 <= $iconf) {
        &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
+       @joinchan       = @x;
+       &joinNextChan();
     }
 
     if (!$conn->connected or time() - $msgtime > 3600) {
@@ -683,19 +760,14 @@ sub ircCheck {
 
     if (grep /^\s*$/, keys %channels) {
        &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
-       if (exists $channels{''}) {
-           &DEBUG("ircCheck: ok it existed!");
-       } else {
-           &DEBUG("ircCheck: this hsould never happen!");
+       if (!exists $channels{''}) {
+           &DEBUG("ircCheck: this should never happen!");
        }
 
        delete $channels{''};
     }
 
-    &DEBUG("ircstats...");
-    &DEBUG("  pubsleep: $pubsleep");
-    &DEBUG("  msgsleep: $msgsleep");
-    &DEBUG("  notsleep: $notsleep");
+    $cache{statusSafe} = 0;
 
     ### USER FILE.
     if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
@@ -711,12 +783,21 @@ sub ircCheck {
 
 sub miscCheck {
     if (@_) {
-       &ScheduleThis(240, "miscCheck");
+       &ScheduleThis(120, "miscCheck");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"miscCheck"}{RUNNING};
     }
 
+    # debian check.
+    opendir(DEBIAN, "$bot_state_dir/debian");
+    foreach ( grep /gz$/, readdir(DEBIAN) ) {
+       my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
+       next unless ($exit);
+
+       &status("debian: unlinking file => $_");
+       unlink "$bot_state_dir/debian/$_";
+    }
+    closedir DEBIAN;
+
     # SHM check.
     my @ipcs;
     if ( -x "/usr/bin/ipcs") {
@@ -750,8 +831,8 @@ sub miscCheck {
     }
 
     # make backup of important files.
-    &mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*3);
-    &mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*3);
+    &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
+    &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
     &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
 
     # flush cache{lobotomy}
@@ -768,36 +849,26 @@ sub miscCheck2 {
     if (@_) {
        &ScheduleThis(240, "miscCheck2");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"miscCheck2"}{RUNNING};
     }
 
-    &DEBUG("miscCheck2: Doing debian checking...");
-
-    # debian check.
-    opendir(DEBIAN, "$bot_base_dir/debian");
-    foreach ( grep /gz$/, readdir(DEBIAN) ) {
-       my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
-       next unless ($exit);
-
-       &status("debian: unlinking file => $_");
-       unlink "$bot_base_dir/debian/$_";
-    }
-    closedir DEBIAN;
-
     # compress logs that should have been compressed.
     # todo: use strftime?
     my ($day,$month,$year) = (localtime(time()))[3,4,5];
     my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
 
-    opendir(DIR,"$bot_base_dir/log");
+    if (!opendir(DIR,"$bot_log_dir")) {
+       &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
+       closedir DIR;
+       return -1;
+    }
+
     while (my $f = readdir(DIR)) {
-       next unless ( -f "$bot_base_dir/log/$f");
+       next unless ( -f "$bot_log_dir/$f");
        next if ($f =~ /gz|bz2/);
        next unless ($f =~ /(\d{8})/);
        next if ($date eq $1);
 
-       &compress("$bot_base_dir/log/$f");
+       &compress("$bot_log_dir/$f");
     }
     closedir DIR;
 }
@@ -808,8 +879,6 @@ sub shmFlush {
     if (@_) {
        &ScheduleThis(5, "shmFlush");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"shmFlush"}{RUNNING};
     }
 
     my $time;
@@ -857,11 +926,8 @@ sub getNickInUse {
     if (@_) {
        &ScheduleThis(30, "getNickInUse");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"getNickInUse"}{RUNNING};
     }
 
-    &status("Trying to get my nick back.");
     &nick( $param{'ircNick'} );
 }
 
@@ -871,8 +937,6 @@ sub uptimeLoop {
     if (@_) {
        &ScheduleThis(60, "uptimeLoop");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"uptimeLoop"}{RUNNING};
     }
 
     &uptimeWriteFile();
@@ -883,8 +947,6 @@ sub slashdotLoop {
     if (@_) {
        &ScheduleThis(60, "slashdotLoop");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"slashdotLoop"}{RUNNING};
     }
 
     my @chans = &ChanConfList("slashdotAnnounce");
@@ -907,8 +969,6 @@ sub freshmeatLoop {
     if (@_) {
        &ScheduleThis(60, "freshmeatLoop");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"freshmeatLoop"}{RUNNING};
     }
 
     my @chans = &ChanConfList("freshmeatAnnounce");
@@ -930,8 +990,6 @@ sub kernelLoop {
     if (@_) {
        &ScheduleThis(240, "kernelLoop");
        return if ($_[0] eq "2");
-    } else {
-       delete $sched{"kernelLoop"}{RUNNING};
     }
 
     my @chans = &ChanConfList("kernelAnnounce");
@@ -990,8 +1048,6 @@ sub wingateWriteFile {
     if (@_) {
        &ScheduleThis(60, "wingateWriteFile");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"wingateWriteFile"}{RUNNING};
     }
 
     return unless (scalar @wingateCache);
@@ -1018,19 +1074,21 @@ sub wingateWriteFile {
        print OUT "$_\n";
     }
     close OUT;
-
 }
 
 sub factoidCheck {
     if (@_) {
-       &ScheduleThis(1440, "factoidCheck");
+       &ScheduleThis(720, "factoidCheck");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"factoidCheck"}{RUNNING};
     }
 
     my @list   = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
-    my $stale  = &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+    my $stale  = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
+    if ($stale < 1) {
+       # disable it since it's "illegal".
+       return;
+    }
+
     my $time   = time();
 
     foreach (@list) {
@@ -1045,7 +1103,7 @@ sub factoidCheck {
                }
            }
 
-           &WARN("old cruft (no time): $_");
+           &WARN("del factoid: old cruft (no time): $_");
            &delFactoid($_);
            next;
        }
@@ -1054,11 +1112,11 @@ sub factoidCheck {
 
        my $fix = $_;
        $fix =~ s/ #DEL#$//g;
-       &DEBUG("safedel: Removing $fix ($_) for good.");
+       my $agestr = &Time2String($time - $age);
+       &status("safedel: Removing '$_' for good. [$agestr old]");
 
        &delFactoid($_);
     }
-
 }
 
 sub dccStatus {
@@ -1067,8 +1125,6 @@ sub dccStatus {
     if (@_) {
        &ScheduleThis(10, "dccStatus");
        return if ($_[0] eq "2");       # defer.
-    } else {
-       delete $sched{"dccStatus"}{RUNNING};
     }
 
     my $time = strftime("%H:%M", localtime(time()) );
@@ -1143,23 +1199,27 @@ sub getChanConfDefault {
 }
 
 sub mkBackup {
-    my($file, $time) = @_;
-    my $backup = 0;
+    my($file, $time)   = @_;
+    my $backup         = 0;
 
     if (! -f $file) {
-       &WARN("mkB: file $file don't exist.");
+       &VERB("mkB: file '$file' does not exist.",2);
        return;
     }
 
+    my $age    = "New";
     if ( -e "$file~" ) {
-       $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
+       $backup++       if ((stat $file)[9] - (stat "$file~")[9] > $time);
+       my $delta       = time() - (stat "$file~")[9];
+       $age            = &Time2String($delta);
     } else {
        $backup++;
     }
+
     return unless ($backup);
 
     ### TODO: do internal copying.
-    &status("Backup: $file to $file~");
+    &status("Backup: $file ($age)");
     CORE::system("/bin/cp $file $file~");
 }