]> git.donarmstrong.com Git - infobot.git/commitdiff
- forker (POSIX::_exit) fixes.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 6 Jan 2001 12:51:33 +0000 (12:51 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 6 Jan 2001 12:51:33 +0000 (12:51 +0000)
- Misc.pl: added timedelta(renamed from gettimeofday),timeget.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@226 c11ca15a-4712-0410-83d8-924469b57eb5

src/IRC/IrcHooks.pl
src/Misc.pl
src/Shm.pl

index 8be2723da9f2dfe39238a57a771a6027229afaa3..3b51c60d357a2ce07b0b11fb4abceadde5af57d5 100644 (file)
@@ -189,7 +189,10 @@ sub on_dcc_close {
     my $sock = ($event->to)[0];
 
     # DCC CHAT close on fork exit workaround.
-    return if ($bot_pid != $$);
+    if ($bot_pid != $$) {
+       &WARN("run-away fork; exiting.");
+       &delForked($forker);
+    }
 
     &DEBUG("dcc_close: nick => '$nick'.");
 
@@ -611,9 +614,9 @@ sub on_public {
     $nuh     = $nick."!".$uh;
     ($user,$host) = split(/\@/, $uh);
 
-    if ($$ != $bot_pid) {
-       &ERROR("SHOULD NEVER HAPPEN.");
-       exit(0);
+    if ($bot_pid != $$) {
+       &ERROR("run-away fork; exiting.");
+       &delForked($forker);
     }
 
     ### DEBUGGING.
index 3ec5fb5eaf26df2d36bf38120b7c55d16f6e7264..ce25d77b8eb9a14d8088fa987be03539f54d05f7 100644 (file)
@@ -7,8 +7,6 @@
 
 if (&IsParam("useStrict")) { use strict; }
 
-use POSIX qw(_exit);
-
 sub help {
     my $topic = shift;
     my $file  = $bot_misc_dir."/blootbot.help";
@@ -85,16 +83,21 @@ sub getPath {
     }
 }
 
-sub gettimeofday {
-    if ($no_syscall) {         # fallback.
+sub timeget {
+    if ($no_timehires) {       # fallback.
        return time();
     } else {                   # the real thing.
-       my $time = pack("LL", 0);
+       return gettimeofday();
+    }
+}    
 
-       syscall(&SYS_gettimeofday, $time, 0);
-       my @time = unpack("LL",$time);
+sub timedelta {
+    my($start_time) = shift;
 
-       return sprintf("%d.%d", @time);
+    if ($no_timehires) {       # fallback.
+       return time() - $start_time;
+    } else {                   # the real thing.
+       return tv_interval ($start_time);
     }
 }
 
@@ -604,18 +607,21 @@ sub Forker {
 
     if (&IsParam("forking") and $$ == $bot_pid) {
        return $noreply unless (&addForked($label));
-       ### use select(undef,undef,undef,0.2); ...
+
        $SIG{CHLD} = 'IGNORE';
        $pid = eval { fork() };
        return $noreply if $pid;        # parent does nothing
        &status("fork starting for '$label', PID == $$.");
        &shmWrite($shm,"SET FORKPID $label $$");
+
+       sleep 1;
     }
 
     ### TODO: use AUTOLOAD
-    if (!&loadMyModule($myModules{$label})) {
+    ### very lame hack.
+    if ($label !~ /-/ and !&loadMyModule($myModules{$label})) {
        &DEBUG("Forker: failed?");
-       return;
+       &delForked($label);
     }
 
     if (defined $code) {
@@ -624,11 +630,7 @@ sub Forker {
        &WARN("Forker: code not defined!");
     }
 
-    if (defined $pid) {                # child.
-       &delForked($label);
-       &status("fork finished for '$label'.");
-       POSIX::_exit(0);
-    }
+    &delForked($label);
 }
 
 sub closePID {
index 6ece24808cef92880f85affafae497e38df065df..27b95198e02ba6f2ef39fd92ca5440db7c4d9abf 100644 (file)
@@ -7,6 +7,8 @@
 
 if (&IsParam("useStrict")) { use strict; }
 
+use POSIX qw(_exit);
+
 sub openSHM {
     my $IPC_PRIVATE = 0;
     my $size = 2000;
@@ -64,15 +66,17 @@ sub shmWrite {
     }
 }
 
-#######
-# Helpers
-#
+##############
+### Helpers
+###
 
 # Usage: &addForked($name);
 # Return: 1 for success, 0 for failure.
 sub addForked {
-    my ($name) = @_;
+    my ($name)         = @_;
     my $forker_timeout = 360;  # 6mins, in seconds.
+    $forker            = $name;
+
     if (!defined $name) {
        &WARN("addForked: name == NULL.");
        return 0;
@@ -129,10 +133,13 @@ sub addForked {
 }
 
 sub delForked {
-    my ($name) = @_;
+    my ($name) = @_;
+
+    return if ($$ == $bot_pid);
+
     if (!defined $name) {
        &WARN("delForked: name == NULL.");
-       return 0;
+       POSIX::_exit(0);
     }
 
     &showProc();       # just for informational purposes.
@@ -141,11 +148,13 @@ sub delForked {
        my $timestr = &Time2String(time() - $forked{$name}{Time});
        &status("fork: took $timestr for $name.");
        &shmWrite($shm,"DELETE FORK $name");
-       return 1;
     } else {
        &ERROR("delForked: forked{$name} does not exist. should not happen.");
-       return 0;
     }
+
+    &status("fork finished for '$name'.");
+
+    POSIX::_exit(0);
 }
 
 1;