]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/Shm.pl
- kill fork if it has run for too long, and still exists!
[infobot.git] / blootbot / src / Shm.pl
index b9756bce3676b6e42d0e778fb9b1dddd73e60491..6412e4db531d6eac36ea6e1a850eef058204958d 100644 (file)
@@ -96,8 +96,15 @@ sub addForked {
        next unless ($time > $forker_timeout);
 
        ### TODO: use &time2string()?
-       &WARN("Fork: looks like we lost '$_', executed $time ago.");
-       delete $forked{$_};
+       &WARN("Fork: looks like we lost '$_', executed $time ago");
+
+       if ( -d "/proc/$forked{$name}{PID}") {
+           my $pid = $forked{$name}{PID};
+           &status("Fork: killing $name ($pid)");
+           kill 9, $pid;
+       }
+
+       delete $forked{$name};
     }
 
     my $count = 0;
@@ -129,10 +136,12 @@ sub addForked {
        $continue++ if ($forked{$name}{PID} == $$);
 
        if ($continue) {
-           &DEBUG("hrm.. fork pid == mypid == $$; how did this happen?");
+           &WARN("hrm.. fork pid == mypid == $$; how did this happen?");
+
        } elsif ( -d "/proc/$forked{$name}{PID}") {
            &status("fork: still running; good. BAIL OUT.");
            return 0;
+
        } else {
            &WARN("Found dead fork; removing and resetting.");
            $continue = 1;
@@ -140,8 +149,10 @@ sub addForked {
 
        if ($continue) {
            # NOTHING.
+
        } elsif (time() - $time > 900) {        # stale fork > 15m.
            &status("forked: forked{$name} presumably exited without notifying us.");
+
        } else {                                # fresh fork.
            &msg($who, "$name is already running ". &Time2String(time() - $time));
            return 0;