use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $Q $SIG_CODEREF);
BEGIN {
- $VERSION = '0.24';
+ $VERSION = '0.28';
+ $VERSION = eval $VERSION;
@ISA = qw(Exporter);
@EXPORT_OK = qw(pm_manage pm_die pm_wait
pm_write_pid_file pm_remove_pid_file
$this->{PIDS} = {};
# initialize signal constructions.
- unless ($this->no_signals()) {
+ unless ($this->no_signals() or $^O eq 'MSWin32') {
$this->{sigaction_no_sa_restart} =
POSIX::SigAction->new('FCGI::ProcManager::sig_sub');
$this->{sigaction_sa_restart} =
return $this;
}
+sub _set_signal_handler {
+ my ($this, $signal, $restart) = @_;
+
+ if ($^O eq 'MSWin32') {
+ $SIG{$signal} = 'FCGI::ProcManager::sig_sub';
+ } else {
+ no strict 'refs';
+ sigaction(&{"POSIX::SIG$signal"}(), $restart ? $this->{sigaction_sa_restart} : $this->{sigaction_no_sa_restart})
+ or $this->pm_warn("sigaction: SIG$signal: $!");
+ }
+}
+
=head1 Manager methods
=head2 pm_manage
# We do NOT want SA_RESTART in the process manager.
# -- we want start the shutdown sequence immediately upon SIGTERM.
unless ($this->no_signals()) {
- sigaction(SIGTERM, $this->{sigaction_no_sa_restart}) or
- $this->pm_warn("sigaction: SIGTERM: $!");
- sigaction(SIGHUP, $this->{sigaction_no_sa_restart}) or
- $this->pm_warn("sigaction: SIGHUP: $!");
+ $this->_set_signal_handler('TERM', 0);
+ $this->_set_signal_handler('HUP', 0);
$SIG_CODEREF = sub { $this->sig_manager(@_) };
}
# begin to handle signals.
# We'll want accept(2) to return -1(EINTR) on caught signal..
unless ($this->no_signals()) {
- sigaction(SIGTERM, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGTERM: $!");
- sigaction(SIGHUP, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGHUP: $!");
+ $this->_set_signal_handler('TERM', 0);
+ $this->_set_signal_handler('HUP', 0);
$SIG_CODEREF = sub { $this->sig_handler(@_) };
}
# change the name of this process as it appears in ps(1) output.
$this->pm_change_process_name("perl-fcgi");
+
+ # Re-srand in case someone called rand before the fork, so that
+ # children get different random numbers.
+ srand;
}
=head2 pm_pre_dispatch
# Now, we want the request to continue unhindered..
unless ($this->no_signals()) {
- sigaction(SIGTERM, $this->{sigaction_sa_restart}) or $this->pm_warn("sigaction: SIGTERM: $!");
- sigaction(SIGHUP, $this->{sigaction_sa_restart}) or $this->pm_warn("sigaction: SIGHUP: $!");
+ $this->_set_signal_handler('TERM', 1);
+ $this->_set_signal_handler('HUP', 1);
}
}
}
# We'll want accept(2) to return -1(EINTR) on caught signal..
unless ($this->no_signals()) {
- sigaction(SIGTERM, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGTERM: $!");
- sigaction(SIGHUP, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGHUP: $!");
+ $this->_set_signal_handler('TERM', 0);
+ $this->_set_signal_handler('HUP', 0);
}
}