From 40940f28baf71ef5de03c1dbd0dc0a582e31a5fb Mon Sep 17 00:00:00 2001 From: wolfff Date: Thu, 20 Aug 2015 13:57:43 +0200 Subject: [PATCH] changed asp_state to listen for signals to quit instead reading from console --- tools/asp_state/Makefile.am | 2 +- tools/asp_state/asp_state.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/asp_state/Makefile.am b/tools/asp_state/Makefile.am index 0391ba0b..3ee78a20 100644 --- a/tools/asp_state/Makefile.am +++ b/tools/asp_state/Makefile.am @@ -1,4 +1,4 @@ -MCSFLAGS= -debug+ -debug:full -nologo +MCSFLAGS= -debug+ -debug:full -nologo -r:Mono.Posix.dll if NET_4_0 scripts4 = asp-state4.exe diff --git a/tools/asp_state/asp_state.cs b/tools/asp_state/asp_state.cs index 8ba8b628..0157ff57 100644 --- a/tools/asp_state/asp_state.cs +++ b/tools/asp_state/asp_state.cs @@ -11,6 +11,8 @@ using System.IO; using System.Reflection; using System.Runtime.Remoting; +using Mono.Unix; +using Mono.Unix.Native; namespace Mono.ASPNET.Tools { @@ -64,10 +66,22 @@ private static void ShowVerboseConfigurationInfo(string filename) public static void Main (string [] args) { if (args.Length == 0) { + UnixSignal [] signals = new UnixSignal[] { + new UnixSignal(Signum.SIGINT), + new UnixSignal(Signum.SIGTERM), + }; RemotingConfiguration.Configure (ConfigurationFileName, false); ShowVerboseConfigurationInfo(ConfigurationFileName); - Console.Write("Press to stop..."); - Console.ReadLine (); + + // Wait for a unix signal to exit + for (bool exit = false; !exit; ) + { + int id = UnixSignal.WaitAny(signals); + if (id >= 0 && id < signals.Length) + { + if (signals[id].IsSet) exit = true; + } + } } else { ShowUsage(); }