--- AnyEvent-Watchdog/Watchdog.pm 2009/08/14 23:08:54 1.5 +++ AnyEvent-Watchdog/Watchdog.pm 2009/08/30 17:20:27 1.6 @@ -40,9 +40,9 @@ use AnyEvent::Watchdog qw(autorestart heartbeat=300); -=head1 FUNCTIONS +=head1 VARIABLES/FUNCTIONS -The module supports the following functions: +The module supports the following variables and functions: =over 4 @@ -57,8 +57,26 @@ our $VERSION = '0.9'; +=item $AnyEvent::Watchdog::ENABLED + +This is true when the program is running under the regime of +AnyEvent::Watchdog. Semi-obviously, you should I C or C +this module before looking at this variable, and neither should you try +to load this module unless in the main program, rather use an idiom like +this: + + $AnyEvent::Watchdog::ENABLED + or die "watchdog not enabled..."; + AnyEvent::Watchdog::restart (60); # MUST use () + +Note that if this variable is defined, but false, then AnyEvent::Watchdog +is running, but you are in the watchdog process - you probably did +something very wrong in this case. + +=cut + our $PID; # child pid -our $ENABLED = 1; +our $ENABLED = 0; our $AUTORESTART; # actually exit our $HEARTBEAT; our ($P, $C); @@ -205,9 +223,13 @@ warn "AnyEvent::Watchdog: '$!', retrying in one second...\n"; sleep 1; } elsif ($PID) { + # parent code close $C; server; } else { + # child code + $ENABLED = 1; + # restore seek offsets while (my ($k, $v) = each %SEEKPOS) { open my $fh, "<&$k" or next;