diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index bd60759fe4..b5cbd2582e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -28,6 +28,8 @@ using System; using System.Reflection; using System.Globalization; +using System.Runtime.Remoting; +using System.Runtime.Remoting.Lifetime; using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -39,6 +41,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Threading; +using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Shared.CodeTools; @@ -56,6 +59,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine public Dictionary Apis; public Dictionary, KeyValuePair> LineMap; + public ISponsor ScriptSponsor; } public class ScriptManager @@ -164,6 +168,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript( CompiledScriptFile, out id.AppDomain); + //Register the sponsor + ISponsor scriptSponsor = new ScriptSponsor(); + ILease lease = (ILease)RemotingServices.GetLifetimeService(CompiledScript as MarshalByRefObject); + lease.Register(scriptSponsor); + id.ScriptSponsor = scriptSponsor; id.LineMap = LSLCompiler.LineMap(); id.Script = CompiledScript; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 17dca986eb..cbd99bb7c6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -29,6 +29,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Remoting.Lifetime; +using System.Security.Permissions; using System.Text; using System.Threading; using Nini.Config; @@ -64,7 +65,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// /// Contains all LSL ll-functions. This class will be in Default AppDomain. /// - public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi + public class LSL_Api : ILSL_Api, IScriptApi { protected IScriptEngine m_ScriptEngine; protected SceneObjectPart m_host; @@ -98,17 +99,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api AsyncCommands = new AsyncCommandManager(ScriptEngine); } - // Object never expires - public override Object InitializeLifetimeService() - { - ILease lease = (ILease)base.InitializeLifetimeService(); - if (lease.CurrentState == LeaseState.Initial) - { - lease.InitialLeaseTime = TimeSpan.Zero; - } - return lease; - } + protected void ScriptSleep(int delay) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index 25c823d0b9..06307bb2c8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs @@ -27,6 +27,7 @@ using System; using System.Runtime.Remoting.Lifetime; +using System.Security.Permissions; using System.Threading; using System.Reflection; using System.Collections; @@ -40,16 +41,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { private Dictionary inits = new Dictionary(); - // - // Never expire this object - // + // Object expires if we don't keep it alive + // sponsor will be added on object load + [SecurityPermissionAttribute(SecurityAction.Demand, + Flags = SecurityPermissionFlag.Infrastructure)] public override Object InitializeLifetimeService() { ILease lease = (ILease)base.InitializeLifetimeService(); - if (lease.CurrentState == LeaseState.Initial) { - lease.InitialLeaseTime = TimeSpan.Zero; + lease.InitialLeaseTime = TimeSpan.FromMinutes(1); + lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); + lease.RenewOnCallTime = TimeSpan.FromSeconds(2); } return lease; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs new file mode 100644 index 0000000000..87401bbfd9 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Remoting.Lifetime; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.Shared.Api.Runtime +{ + public class ScriptSponsor: ISponsor + { + // In theory: I execute, therefore I am. + // If GC collects this class then sponsorship will expire + public TimeSpan Renewal(ILease lease) + { + return TimeSpan.FromMinutes(2); + } + } +} diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index ad86494445..2a8bba88f6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -27,6 +27,8 @@ using System; using System.IO; +using System.Runtime.Remoting; +using System.Runtime.Remoting.Lifetime; using System.Threading; using System.Collections; using System.Collections.Generic; @@ -44,6 +46,7 @@ using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.ScriptEngine.Shared; using OpenSim.Region.ScriptEngine.Shared.Api; +using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Interfaces; @@ -80,6 +83,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private int m_ControlEventsInQueue = 0; private int m_LastControlLevel = 0; private bool m_CollisionInQueue = false; + private ISponsor m_ScriptSponsor; private Dictionary, KeyValuePair> m_LineMap; @@ -204,6 +208,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_Script = (IScript)dom.CreateInstanceAndUnwrap( Path.GetFileNameWithoutExtension(assembly), "SecondLife.Script"); + + // Add a sponsor to the script + ISponsor scriptSponsor = new ScriptSponsor(); + ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as MarshalByRefObject); + lease.Register(scriptSponsor); + m_ScriptSponsor = scriptSponsor; + } catch (Exception e) {