Sfoglia il codice sorgente

test: try handle cntr-c another way

UbitUmarov 3 anni fa
parent
commit
69e12f537f

+ 25 - 1
OpenSim/Framework/Console/CommandConsole.cs

@@ -720,9 +720,10 @@ namespace OpenSim.Framework.Console
     /// </summary>
     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();
+        }
     }
 }

+ 8 - 1
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))

+ 1 - 0
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

+ 2 - 0
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);
     }
 }

+ 4 - 40
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
-
         /// <summary>
         /// Performs initialisation of the scene, such as loading configuration from disk.
         /// </summary>
@@ -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());
                     }
                 });

+ 25 - 46
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()