changeset 1005:f650ae251d8c

Add signal handling.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 29 Mar 2015 15:55:54 +0300
parents 76e26fc5d544
children cb23b23a2d8b
files faptool.php
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Mon Mar 23 23:56:43 2015 +0200
+++ b/faptool.php	Sun Mar 29 15:55:54 2015 +0300
@@ -9,7 +9,6 @@
 require_once "msite.inc.php";
 
 
-
 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv)
 {
   global $setPreviewPath;
@@ -670,6 +669,23 @@
     "\n";
 }
 
+
+function wtSigHandler($signo)
+{
+  global $flagQuit;
+  switch ($signo)
+  {
+    case SIGTERM:
+      mgFatal("Received SIGTERM.\n");
+      break;
+
+    case SIGQUIT:
+    case SIGINT:
+      $flagQuit = TRUE;
+      break;
+}
+
+
 //
 // Main program starts
 //
@@ -680,6 +696,10 @@
   exit;
 }
 
+pcntl_signal(SIGTERM, "wtSigHandler");
+pcntl_signal(SIGHUP,  "wtSigHandler");
+pcntl_signal(SIGQUIT, "wtSigHandler");
+pcntl_signal(SIGINT,  "wtSigHandler");
 
 // Try to connect to database
 $spec = stGetSetting("sqlDB");