Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
//
// AssemblyInfo.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the System.Web assembly
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyTitle("mono-service.exe")]
[assembly: AssemblyDescription("mono-service.exe")]
[assembly: AssemblyConfiguration("Development version")]
[assembly: AssemblyCompany("MONO development team")]
[assembly: AssemblyProduct("MONO CLI")]
[assembly: AssemblyCopyright("(c) 2003 Various Authors")]
[assembly: AssemblyTrademark("")]
#if TARGET_JVM
[assembly: CLSCompliant(false)]
#else
[assembly: CLSCompliant(true)]
#endif
[assembly: ComVisible(false)]
[assembly: AssemblyDefaultAlias("mono-service.exe")]
[assembly: AssemblyInformationalVersion("0.0.0.1")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AllowPartiallyTrustedCallers()]
#if !TARGET_JVM
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("../../class/mono.snk")]
#endif

View File

@@ -0,0 +1,74 @@
2008-02-08 Jonathan Pryor <pryorj@novell.com>
* mono-service.cs: The return value of UnixSignal.WaitAny() changed; cope.
2008-02-07 Jonathan Pryor <pryorj@novell.com>
* 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 <robertj@gmx.net>
* Makefile: Support the 2.0 profile.
* Makefile: Install the program into the GAC.
* AssemblyInfo.cs: Create, configure.
* mono-service.exe.sources: Add AssemblyInfo.cs.
Fixes #79207.
2006-07-30 Miguel de Icaza <miguel@novell.com>
* mono-service.cs: Create/open the lockfile exclusively to avoid
attacks. Fixes #77340.
2006-06-07 Kornél Pál <kornelpal@gmail.com>
* mono-service.cs: Run service using AppDomain.ExecuteAssembly ()
to ensure EntryPoint signature compatibility with the runtime.
2005-12-27 Jonathan Pryor <jonpryor@vt.edu>
* mono-service.cs: Use non-obsolete Mono.Posix.dll types.
2005-06-16 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs: Remove lock file when service is
terminated.
2005-06-10 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs: Removed AutoResetEvent code from signal
handler because it was unsafe and not guaranteed to work.
Use polling in main loop instead.
Use signal functions from Mono.Unix instead of self defined ones.
2005-06-01 Raja R Harinath <rharinath@novell.com>
* mono-service.cs (MonoServiceRunner.Main): Replace LockFlags with
LockfCommand to reflect the rename in Mono.Posix.dll.
2005-04-12 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs: Service runs in its own AppDomain now.
Improved exception handling.
2005-04-09 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs: Fixed dynamic loading of assemblies
from services. Cleaned up callback code.
2005-04-08 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs: Restructured code to run service main loop
in callback called by ServiceBase.Run. This matches Windows
service behaviour better.
2005-04-07 Zoltan Varga <vargaz@freemail.hu>
* mono-service.cs: Fix compilation with csc.
2005-04-06 Joerg Rosenkranz <joergr@voelcker.com>
* mono-service.cs:
Pay attention to CanStop and CanPauseAndContinue.
Call Dispose of service. Fixed exe name in usage output.
Filling and using lock file to prevent multiple instances.

View File

@@ -0,0 +1,36 @@
thisdir = tools/mono-service
SUBDIRS =
include ../../build/rules.make
PROGRAM = mono-service.exe
include ../../build/executable.make
LOCAL_MCS_FLAGS = -r:System.ServiceProcess.dll -r:Mono.Posix.dll -unsafe
# Copied from library.make
# -- begin --
ifeq ($(PLATFORM), win32)
GACDIR = `cygpath -w $(mono_libdir)`
GACROOT = `cygpath -w $(DESTDIR)$(mono_libdir)`
test_flags += -d:WINDOWS
else
GACDIR = $(mono_libdir)
GACROOT = $(DESTDIR)$(mono_libdir)
endif
ifndef RUNTIME_HAS_CONSISTENT_GACDIR
gacdir_flag = /gacdir $(GACDIR)
endif
# -- end --
install-local: install-extras
uninstall-local: uninstall-extras
install-extras: $(gacutil)
$(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT)
uninstall-extras: $(gacutil)
-$(GACUTIL) /u $(the_lib:.exe=) $(gacdir_flag) /root $(GACROOT)

View File

@@ -0,0 +1,294 @@
/*
* monod.cs: Mono daemon for running services based on System.ServiceProcess
*
* Author:
* Joerg Rosenkranz (joergr@voelcker.com)
* Miguel de Icaza (miguel@novell.com)
*
* (C) 2005 Voelcker Informatik AG
* (C) 2005 Novell Inc
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Mono.Unix;
using Mono.Unix.Native;
using System.ServiceProcess;
using System.Threading;
using System.Runtime.InteropServices;
class MonoServiceRunner : MarshalByRefObject
{
string assembly, name, logname;
string[] args;
static void info (string prefix, string format, params object [] args)
{
Syscall.syslog (SyslogLevel.LOG_INFO, String.Format ("{0}: {1}", prefix, String.Format (format, args)));
}
static void error (string prefix, string format, params object [] args)
{
Syscall.syslog (SyslogLevel.LOG_ERR, String.Format ("{0}: {1}", prefix, String.Format (format, args)));
}
static void Usage ()
{
Console.Error.WriteLine (
"Usage is:\n" +
"mono-service [-d:DIRECTORY] [-l:LOCKFILE] [-n:NAME] [-m:LOGNAME] service.exe\n");
Environment.Exit (1);
}
static void call (object o, string method, object [] arg)
{
MethodInfo m = o.GetType ().GetMethod (method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (arg != null)
m.Invoke (o, new object [1] { arg });
else
m.Invoke (o, null);
}
static int Main (string [] args)
{
string assembly = null;
string directory = null;
string lockfile = null;
string name = null;
string logname = null;
var assebmlyArgs = new List<string>();
foreach (string s in args){
if (s.Length > 3 && s [0] == '-' && s [2] == ':'){
string arg = s.Substring (3);
switch (Char.ToLower (s [1])){
case 'd': directory = arg; break;
case 'l': lockfile = arg; break;
case 'n': name = arg; break;
case 'm': logname = arg; break;
default: Usage (); break;
}
} else {
if (assembly != null)
{
assebmlyArgs.Add(s);
}
else
{
assembly = s;
}
}
}
if (logname == null)
logname = assembly;
if (assembly == null){
error (logname, "Assembly name is missing");
Usage ();
}
if (directory != null){
if (Syscall.chdir (directory) != 0){
error (logname, "Could not change to directory {0}", directory);
return 1;
}
}
// Use lockfile to allow only one instance
if (lockfile == null)
lockfile = String.Format ("/tmp/{0}.lock", Path.GetFileName (assembly));
int lfp = Syscall.open (lockfile, OpenFlags.O_RDWR|OpenFlags.O_CREAT|OpenFlags.O_EXCL,
FilePermissions.S_IRUSR|FilePermissions.S_IWUSR|FilePermissions.S_IRGRP);
if (lfp<0) {
// Provide some useful info
if (File.Exists (lockfile))
error (logname, String.Format ("Lock file already exists: {0}", lockfile));
else
error (logname, String.Format ("Cannot open/create lock file exclusively: {0}", lockfile));
return 1;
}
if (Syscall.lockf(lfp, LockfCommand.F_TLOCK,0)<0) {
info (logname, "Daemon is already running.");
return 0;
}
try {
// Write pid to lock file
string pid = Syscall.getpid ().ToString () + Environment.NewLine;
IntPtr buf = Marshal.StringToCoTaskMemAnsi (pid);
Syscall.write (lfp, buf, (ulong)pid.Length);
Marshal.FreeCoTaskMem (buf);
// Create new AppDomain to run service
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = Environment.CurrentDirectory;
setup.ConfigurationFile = Path.Combine (Environment.CurrentDirectory, assembly + ".config");
setup.ApplicationName = logname;
AppDomain newDomain = AppDomain.CreateDomain (logname, AppDomain.CurrentDomain.Evidence, setup);
MonoServiceRunner rnr = newDomain.CreateInstanceAndUnwrap(
typeof (MonoServiceRunner).Assembly.FullName,
typeof (MonoServiceRunner).FullName,
true,
BindingFlags.Default,
null,
new object [] {assembly, name, logname, assebmlyArgs.ToArray()},
null, null, null) as MonoServiceRunner;
if (rnr == null) {
error (logname, "Internal Mono Error: Could not create MonoServiceRunner.");
return 1;
}
return rnr.StartService ();
} finally {
// Remove lock file when done
if (File.Exists(lockfile))
File.Delete (lockfile);
}
}
public MonoServiceRunner (string assembly, string name, string logname, string[] args)
{
this.assembly = assembly;
this.name = name;
this.logname = logname;
this.args = args;
}
public int StartService ()
{
try {
// Load service assembly
Assembly a = null;
try {
a = Assembly.LoadFrom (assembly);
} catch (FileNotFoundException) {
error (logname, "Could not find assembly {0}", assembly);
return 1;
} catch (BadImageFormatException){
error (logname, "File {0} is not a valid assembly", assembly);
return 1;
} catch { }
if (a == null){
error (logname, "Could not load assembly {0}", assembly);
return 1;
}
if (a.EntryPoint == null){
error (logname, "Entry point not defined in service");
return 1;
}
// Hook up RunService callback
Type cbType = Type.GetType ("System.ServiceProcess.ServiceBase+RunServiceCallback, System.ServiceProcess");
if (cbType == null){
error (logname, "Internal Mono Error: Could not find RunServiceCallback in ServiceBase");
return 1;
}
FieldInfo fi = typeof (ServiceBase).GetField ("RunService", BindingFlags.Static | BindingFlags.NonPublic);
if (fi == null){
error (logname, "Internal Mono Error: Could not find RunService in ServiceBase");
return 1;
}
fi.SetValue (null, Delegate.CreateDelegate(cbType, this, "MainLoop"));
// And run its Main. Our RunService handler is invoked from
// ServiceBase.Run.
return AppDomain.CurrentDomain.ExecuteAssembly (assembly, AppDomain.CurrentDomain.Evidence, args);
} catch ( Exception ex ) {
for (Exception e = ex; e != null; e = e.InnerException) {
error (logname, e.Message);
}
return 1;
}
}
// The main service loop
private void MainLoop (ServiceBase [] services)
{
try {
ServiceBase service;
if (services == null || services.Length == 0){
error (logname, "No services were registered by this service");
return;
}
// Start up the service.
service = null;
if (name != null){
foreach (ServiceBase svc in services){
if (svc.ServiceName == name){
service = svc;
break;
}
}
} else {
service = services [0];
}
if (service.ExitCode != 0) {
//likely due to a previous execution, so we need to reset it to default
service.ExitCode = 0;
}
call (service, "OnStart", args);
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; ){
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);
if (service.ExitCode != 0)
error (logname, "Service {0} stopped returning a non-zero ExitCode: {1}",
service.ServiceName, service.ExitCode);
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
foreach (ServiceBase svc in services){
svc.Dispose ();
}
}
}
}

View File

@@ -0,0 +1,3 @@
../../build/common/Consts.cs
AssemblyInfo.cs
mono-service.cs