Author: jonpryor
Date: 2008-02-08 12:57:47 -0500 (Fri, 08 Feb 2008)
New Revision: 95287
Modified:
branches/mono-1-9/mcs/tools/mono-service/ChangeLog
branches/mono-1-9/mcs/tools/mono-service/mono-service.cs
Log:
* mono-service.cs: Use Mono.Unix.UnixSignal for signal handling, which
is actually safe. As a bonus, it removes the 'wakeup every .5s' code.
- The return value of UnixSignal.WaitAny() changed; cope.
Modified: branches/mono-1-9/mcs/tools/mono-service/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/tools/mono-service/ChangeLog 2008-02-08 17:39:50 UTC
(rev 95286)
+++ branches/mono-1-9/mcs/tools/mono-service/ChangeLog 2008-02-08 17:57:47 UTC
(rev 95287)
@@ -1,3 +1,12 @@
+2008-02-08 Jonathan Pryor <[EMAIL PROTECTED]>
+
+ * mono-service.cs: The return value of UnixSignal.WaitAny() changed;
cope.
+
+2008-02-07 Jonathan Pryor <[EMAIL PROTECTED]>
+
+ * mono-service.cs: Use Mono.Unix.UnixSignal for signal handling, which
+ is actually safe. As a bonus, it removes the 'wakeup every .5s' code.
+
2006-08-30 Robert Jordan <[EMAIL PROTECTED]>
* Makefile: Support the 2.0 profile.
Modified: branches/mono-1-9/mcs/tools/mono-service/mono-service.cs
===================================================================
--- branches/mono-1-9/mcs/tools/mono-service/mono-service.cs 2008-02-08
17:39:50 UTC (rev 95286)
+++ branches/mono-1-9/mcs/tools/mono-service/mono-service.cs 2008-02-08
17:57:47 UTC (rev 95287)
@@ -11,6 +11,7 @@
using System;
using System.IO;
using System.Reflection;
+using Mono.Unix;
using Mono.Unix.Native;
using System.ServiceProcess;
using System.Threading;
@@ -38,13 +39,6 @@
Environment.Exit (1);
}
- int signum;
-
- void my_handler (int sig)
- {
- signum = sig;
- }
-
static void call (object o, string method, object [] arg)
{
MethodInfo m = o.GetType ().GetMethod (method,
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
@@ -163,15 +157,6 @@
public int StartService ()
{
try {
- // Invoke all the code used in the signal handler, so
the JIT does
- // not kick-in inside the signal handler
- my_handler (0);
-
- // Hook up
- Stdlib.signal (Signum.SIGTERM, new SignalHandler
(my_handler));
- Stdlib.signal (Signum.SIGUSR1, new SignalHandler
(my_handler));
- Stdlib.signal (Signum.SIGUSR2, new SignalHandler
(my_handler));
-
// Load service assembly
Assembly a = null;
@@ -250,37 +235,39 @@
call (service, "OnStart", new string [0]);
info (logname, "Service {0} started",
service.ServiceName);
+ UnixSignal intr = new UnixSignal (Signum.SIGINT);
+ UnixSignal term = new UnixSignal (Signum.SIGTERM);
+ UnixSignal usr1 = new UnixSignal (Signum.SIGUSR1);
+ UnixSignal usr2 = new UnixSignal (Signum.SIGUSR2);
+
+ UnixSignal[] sigs = new UnixSignal[]{
+ intr,
+ term,
+ usr1,
+ usr2
+ };
+
for (bool running = true; running; ){
- // Poll only after 500ms
- Thread.Sleep (500);
-
- Signum v;
-
- if (NativeConvert.TryToSignum (signum, out v)){
- signum = 0;
-
- switch (v){
- case Signum.SIGTERM:
- if (service.CanStop) {
- info (logname,
"Stopping service {0}", service.ServiceName);
- call (service,
"OnStop", null);
- running = false;
- }
- break;
- case Signum.SIGUSR1:
- if
(service.CanPauseAndContinue) {
- info (logname, "Pausing
service {0}", service.ServiceName);
- call (service,
"OnPause", null);
- }
- break;
- case Signum.SIGUSR2:
- if
(service.CanPauseAndContinue) {
- info (logname,
"Continuing service {0}", service.ServiceName);
- call (service,
"OnContinue", null);
- }
- break;
- }
+ int idx = UnixSignal.WaitAny (sigs);
+ if (idx < 0 || idx >= sigs.Length)
+ continue;
+ if ((intr.IsSet || term.IsSet) &&
service.CanStop) {
+ intr.Reset ();
+ term.Reset ();
+ info (logname, "Stopping service {0}",
service.ServiceName);
+ call (service, "OnStop", null);
+ running = false;
}
+ else if (usr1.IsSet &&
service.CanPauseAndContinue) {
+ usr1.Reset ();
+ info (logname, "Pausing service {0}",
service.ServiceName);
+ call (service, "OnPause", null);
+ }
+ else if (usr2.IsSet &&
service.CanPauseAndContinue) {
+ usr2.Reset ();
+ info (logname, "Continuing service
{0}", service.ServiceName);
+ call (service, "OnContinue", null);
+ }
}
} finally {
// Clean up
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches