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'.");
$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.
if (&IsParam("useStrict")) { use strict; }
-use POSIX qw(_exit);
-
sub help {
my $topic = shift;
my $file = $bot_misc_dir."/blootbot.help";
}
}
-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);
}
}
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) {
&WARN("Forker: code not defined!");
}
- if (defined $pid) { # child.
- &delForked($label);
- &status("fork finished for '$label'.");
- POSIX::_exit(0);
- }
+ &delForked($label);
}
sub closePID {
if (&IsParam("useStrict")) { use strict; }
+use POSIX qw(_exit);
+
sub openSHM {
my $IPC_PRIVATE = 0;
my $size = 2000;
}
}
-#######
-# 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;
}
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.
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;