Attempt not doing any sigaction stuff on win32
Andrew Rodland [Wed, 26 Nov 2014 18:16:24 +0000 (13:16 -0500)]
lib/FCGI/ProcManager.pm

index 52619a4..5566142 100644 (file)
@@ -144,7 +144,7 @@ sub new {
   $this->{PIDS} = {};
 
   # initialize signal constructions.
-  unless ($this->no_signals()) {
+  unless ($this->no_signals() or $^O eq 'Win32') {
     $this->{sigaction_no_sa_restart} =
     POSIX::SigAction->new('FCGI::ProcManager::sig_sub');
     $this->{sigaction_sa_restart} =
@@ -154,6 +154,18 @@ sub new {
   return $this;
 }
 
+sub _set_signal_handler {
+  my ($this, $signal, $restart);
+
+  if ($^O eq 'Win32') {
+    $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
@@ -258,10 +270,8 @@ sub managing_init {
   # 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(@_) };
   }
 
@@ -449,8 +459,8 @@ sub handling_init {
   # 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(@_) };
   }
 
@@ -476,8 +486,8 @@ sub 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);
   }
 }
 
@@ -503,8 +513,8 @@ sub pm_post_dispatch {
   }
   # 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);
   }
 }