[smuxi: 6/10] Frontend-STFL: handle signals



commit c9fccff6802e9312a11f2de03e90cb4550b0be0c
Author: Calvin B <calvin imaginarycode com>
Date:   Sun Feb 23 09:39:32 2014 -0400

    Frontend-STFL: handle signals

 src/Frontend-STFL/Main.cs |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/Frontend-STFL/Main.cs b/src/Frontend-STFL/Main.cs
index 2e1a87d..a7b9c9e 100644
--- a/src/Frontend-STFL/Main.cs
+++ b/src/Frontend-STFL/Main.cs
@@ -23,10 +23,13 @@
 using System;
 using System.IO;
 using System.Reflection;
+using System.Threading;
 using SysDiag = System.Diagnostics;
 using NDesk.Options;
 using Smuxi.Common;
 using Smuxi.Engine;
+using Mono.Unix;
+using Mono.Unix.Native;
 
 namespace Smuxi.Frontend.Stfl
 { 
@@ -123,6 +126,26 @@ namespace Smuxi.Frontend.Stfl
                 return;
             }
 
+            if ((Environment.OSVersion.Platform == PlatformID.Unix) ||
+                (Environment.OSVersion.Platform == PlatformID.MacOSX)) {
+                // Register shutdown handlers
+#if LOG4NET
+                _Logger.Info("Registering signal handlers");
+#endif
+                UnixSignal[] shutdown_signals = {
+                    new UnixSignal(Signum.SIGINT),
+                    new UnixSignal(Signum.SIGTERM),
+                };
+                Thread signal_thread = new Thread(() => {
+                    var index = UnixSignal.WaitAny(shutdown_signals);
+#if LOG4NET
+                    _Logger.Info("Caught signal " + shutdown_signals[index].Signum.ToString() + ", shutting 
down");
+#endif
+                    Frontend.Quit();
+                });
+                signal_thread.Start();
+            }
+
             try {
                 Frontend.Init(engine);
             } catch (Exception e) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]