[Rt-commit] r2485 - in HTTP-Server-Simple: . lib/HTTP/Server

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 21 11:48:05 EST 2005


Author: jesse
Date: Mon Mar 21 11:48:05 2005
New Revision: 2485

Modified:
   HTTP-Server-Simple/   (props changed)
   HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
Log:
 r9498 at hualien:  jesse | 2005-03-22 00:09:00 +0800
 * Added support for SIGHUP
 


Modified: HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
==============================================================================
--- HTTP-Server-Simple/lib/HTTP/Server/Simple.pm	(original)
+++ HTTP-Server-Simple/lib/HTTP/Server/Simple.pm	Mon Mar 21 11:48:05 2005
@@ -58,6 +58,29 @@
 
 =cut
 
+# Handle SIGHUP
+
+$SIG{CHLD} = 'IGNORE'; # reap child processes
+$SIG{HUP} = sub {
+    # on a "kill -HUP", we first close our socket handles.
+    close Remote;
+    close HTTPDaemon;
+
+    # and then, on systems implementing fork(), we make sure
+    # we are running with a new pid, so another -HUP will still
+    # work on the new process.
+    require Config;
+    if ($Config::Config{d_fork} and my $pid = fork()) {
+        # finally, allow ^C on the parent process to terminate
+        # the children.
+        waitpid($pid, 0); exit;
+    }
+
+    # do the exec. if $0 is not executable, try running it with $^X.
+    exec { $0 } ( ((-x $0) ? () : ($^X)), $0, @ARGV );
+};
+
+
 
 sub new {
     my ($proto,$port) = @_;


More information about the Rt-commit mailing list