From 69e12f537fb31b8d7e1af97d326922270094e49a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 30 Sep 2020 02:28:40 +0100 Subject: [PATCH] test: try handle cntr-c another way --- OpenSim/Framework/Console/CommandConsole.cs | 26 +++++++- OpenSim/Framework/Console/LocalConsole.cs | 9 ++- OpenSim/Framework/Console/MockConsole.cs | 1 + OpenSim/Framework/ICommandConsole.cs | 2 + OpenSim/Region/Application/OpenSim.cs | 44 ++----------- OpenSim/Server/Base/ServicesServerBase.cs | 71 ++++++++------------- 6 files changed, 65 insertions(+), 88 deletions(-) diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index d2b66189a9..b2c35a6fec 100755 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs @@ -720,9 +720,10 @@ namespace OpenSim.Framework.Console /// public class CommandConsole : ConsoleBase, ICommandConsole { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public event OnOutputDelegate OnOutput; + public static event OnCntrCCelegate OnCntrC; public ICommands Commands { get; private set; } @@ -794,5 +795,28 @@ namespace OpenSim.Framework.Console public virtual void ReadConfig(IConfigSource configSource) { } + + public virtual void SetCntrCHandler(OnCntrCCelegate handler) + { + if(OnCntrC == null) + { + OnCntrC += handler; + System.Console.CancelKeyPress += CancelKeyPressed; + } + } + + protected static void CancelKeyPressed(object sender, ConsoleCancelEventArgs args) + { + if (OnCntrC != null && args.SpecialKey == ConsoleSpecialKey.ControlC) + { + OnCntrC?.Invoke(); + args.Cancel = false; + } + } + + protected static void LocalCancelKeyPressed() + { + OnCntrC?.Invoke(); + } } } diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index 0cc290c31b..570f418344 100755 --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -150,6 +150,8 @@ namespace OpenSim.Framework.Console m_log.InfoFormat("[LOCAL CONSOLE]: Creating new empty command line history file {0}", m_historyPath); File.Create(m_historyPath).Dispose(); } + + System.Console.TreatControlCAsInput = true; } private void AddToHistory(string text) @@ -413,7 +415,6 @@ namespace OpenSim.Framework.Console else components = null; } - } string text; if (components == null || components.Length == 0) @@ -492,6 +493,12 @@ namespace OpenSim.Framework.Console Show(); ConsoleKeyInfo key = System.Console.ReadKey(true); + + if((key.Modifiers & ConsoleModifiers.Control) != 0 && key.Key == ConsoleKey.C) + { + LocalCancelKeyPressed(); + return string.Empty; + } char enteredChar = key.KeyChar; if (!Char.IsControl(enteredChar)) diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs index d314047a7d..83069eb58b 100755 --- a/OpenSim/Framework/Console/MockConsole.cs +++ b/OpenSim/Framework/Console/MockConsole.cs @@ -75,6 +75,7 @@ namespace OpenSim.Framework.Console public string PasswdPrompt(string p) { return ""; } public void ReadConfig(IConfigSource configSource) { } + public void SetCntrCHandler(OnCntrCCelegate handler) { } } public class MockCommands : ICommands diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs index 043056fd1d..fdc70b6ed9 100755 --- a/OpenSim/Framework/ICommandConsole.cs +++ b/OpenSim/Framework/ICommandConsole.cs @@ -83,6 +83,7 @@ namespace OpenSim.Framework } public delegate void OnOutputDelegate(string message); + public delegate void OnCntrCCelegate(); public interface ICommandConsole : IConsole { @@ -105,5 +106,6 @@ namespace OpenSim.Framework string ReadLine(string p, bool isCommand, bool e); void ReadConfig(IConfigSource configSource); + void SetCntrCHandler(OnCntrCCelegate handler); } } diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 65370840e3..a71b71017f 100755 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -134,23 +134,6 @@ namespace OpenSim m_log.InfoFormat("[OPENSIM MAIN] Running GC in {0} mode", GCSettings.IsServerGC ? "server":"workstation"); } -#if (_MONO) - private static Mono.Unix.UnixSignal[] signals; - - - private Thread signal_thread = new Thread (delegate () - { - while (true) - { - // Wait for a signal to be delivered - int index = Mono.Unix.UnixSignal.WaitAny (signals, -1); - - //Mono.Unix.Native.Signum signal = signals [index].Signum; - MainConsole.Instance.RunCommand("shutdown"); - } - }); -#endif - /// /// Performs initialisation of the scene, such as loading configuration from disk. /// @@ -160,27 +143,6 @@ namespace OpenSim m_log.Info("========================= STARTING OPENSIM ========================="); m_log.Info("===================================================================="); -#if (_MONO) - if(!Util.IsWindows()) - { - try - { - // linux mac os specifics - signals = new Mono.Unix.UnixSignal[] - { - new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM) - }; - signal_thread.IsBackground = true; - signal_thread.Start(); - } - catch (Exception e) - { - m_log.Info("Could not set up UNIX signal handlers. SIGTERM will not"); - m_log.InfoFormat("shut down gracefully: {0}", e.Message); - m_log.Debug("Exception was: ", e); - } - } -#endif //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString()); // http://msdn.microsoft.com/en-us/library/bb384202.aspx //GCSettings.LatencyMode = GCLatencyMode.Batch; @@ -1109,6 +1071,7 @@ namespace OpenSim cdt.AddColumn("Code", 10); cdt.AddColumn("IP", 16); cdt.AddColumn("Viewer Name", 24); + cdt.AddColumn("Svc Urls", 8); foreach (AgentCircuitData aCircuit in circuits) cdt.AddRow( @@ -1116,8 +1079,9 @@ namespace OpenSim aCircuit.child ? "child" : "root", aCircuit.circuitcode.ToString(), aCircuit.IPAddress != null ? aCircuit.IPAddress.ToString() : "not set", - Util.GetViewerName(aCircuit)); - + Util.GetViewerName(aCircuit), + aCircuit.ServiceURLs != null ? aCircuit.ServiceURLs.Count : 0 + ); MainConsole.Instance.Output(cdt.ToString()); } }); diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 3bede4576c..2f1f4fc8d8 100755 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs @@ -61,10 +61,6 @@ namespace OpenSim.Server.Base // private bool m_Running = true; -#if (_MONO) - private static Mono.Unix.UnixSignal[] signals; -#endif - // Handle all the automagical stuff // public ServicesServerBase(string prompt, string[] args) : base() @@ -179,42 +175,6 @@ namespace OpenSim.Server.Base RegisterCommonCommands(); RegisterCommonComponents(Config); -#if (_MONO) - Thread signal_thread = new Thread (delegate () - { - while (true) - { - // Wait for a signal to be delivered - int index = Mono.Unix.UnixSignal.WaitAny (signals, -1); - - //Mono.Unix.Native.Signum signal = signals [index].Signum; - ShutdownSpecific(); - m_Running = false; - Environment.Exit(0); - } - }); - - if(!Util.IsWindows()) - { - try - { - // linux mac os specifics - signals = new Mono.Unix.UnixSignal[] - { - new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM) - }; - ignal_thread.IsBackground = true; - signal_thread.Start(); - } - catch (Exception e) - { - m_log.Info("Could not set up UNIX signal handlers. SIGTERM will not"); - m_log.InfoFormat("shut down gracefully: {0}", e.Message); - m_log.Debug("Exception was: ", e); - } - } -#endif - // Allow derived classes to perform initialization that // needs to be done after the console has opened Initialise(); @@ -225,6 +185,8 @@ namespace OpenSim.Server.Base get { return m_Running; } } + private bool DoneShutdown = false; + public virtual int Run() { Watchdog.Enabled = true; @@ -242,13 +204,16 @@ namespace OpenSim.Server.Base } } - MainServer.Stop(); - - MemoryWatchdog.Enabled = false; - Watchdog.Enabled = false; - WorkManager.Stop(); - RemovePIDFile(); + if (!DoneShutdown) + { + DoneShutdown = true; + MainServer.Stop(); + MemoryWatchdog.Enabled = false; + Watchdog.Enabled = false; + WorkManager.Stop(); + RemovePIDFile(); + } return 0; } @@ -260,6 +225,20 @@ namespace OpenSim.Server.Base m_log.Info("[CONSOLE] Quitting"); base.ShutdownSpecific(); + + if (!DoneShutdown) + { + DoneShutdown = true; + MainServer.Stop(); + + MemoryWatchdog.Enabled = false; + Watchdog.Enabled = false; + WorkManager.Stop(); + RemovePIDFile(); + Util.StopThreadPool(); + + Environment.Exit(0); + } } protected virtual void ReadConfig()