From 5e835479ae86e65b6dbd429d39ddf3a0c9eeb82e Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Wed, 30 Nov 2016 12:36:03 +0100 Subject: [PATCH] Generalize usage of System environment variables for processes --- src/Core/WinSWCore/ServiceDescriptor.cs | 6 ++++- src/Core/WinSWCore/WinSWCore.csproj | 1 + src/Core/WinSWCore/WinSWSystem.cs | 29 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Core/WinSWCore/WinSWSystem.cs diff --git a/src/Core/WinSWCore/ServiceDescriptor.cs b/src/Core/WinSWCore/ServiceDescriptor.cs index 11da27b..8dc3c40 100755 --- a/src/Core/WinSWCore/ServiceDescriptor.cs +++ b/src/Core/WinSWCore/ServiceDescriptor.cs @@ -72,7 +72,11 @@ namespace winsw Environment.SetEnvironmentVariable("BASE", d.FullName); // ditto for ID Environment.SetEnvironmentVariable("SERVICE_ID", Id); - Environment.SetEnvironmentVariable("WINSW_EXECUTABLE", ExecutablePath); + + // New name + Environment.SetEnvironmentVariable(WinSWSystem.ENVVAR_NAME_EXECUTABLE_PATH, ExecutablePath); + // Also inject system environment variables + Environment.SetEnvironmentVariable(WinSWSystem.ENVVAR_NAME_SERVICE_ID, Id); } /// diff --git a/src/Core/WinSWCore/WinSWCore.csproj b/src/Core/WinSWCore/WinSWCore.csproj index fd8b153..48f925d 100644 --- a/src/Core/WinSWCore/WinSWCore.csproj +++ b/src/Core/WinSWCore/WinSWCore.csproj @@ -66,6 +66,7 @@ + diff --git a/src/Core/WinSWCore/WinSWSystem.cs b/src/Core/WinSWCore/WinSWSystem.cs new file mode 100644 index 0000000..2e853f3 --- /dev/null +++ b/src/Core/WinSWCore/WinSWSystem.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace winsw +{ + /// + /// Class, which contains generic information about WinSW runtime. + /// This information can be used by the service and extensions. + /// + public class WinSWSystem + { + /// + /// Prefix for all environment variables being injected for WinSW + /// + public static readonly string SYSTEM_EVNVVAR_PREFIX = "WINSW_"; + + /// + /// Variable, which points to the service ID. + /// It may be used to determine runaway processes. + /// + public static string ENVVAR_NAME_SERVICE_ID { get { return SYSTEM_EVNVVAR_PREFIX + "SERVICE_ID"; } } + + /// + /// Variable, which specifies path to the executable being launched by WinSW. + /// + public static string ENVVAR_NAME_EXECUTABLE_PATH { get { return SYSTEM_EVNVVAR_PREFIX + "EXECUTABLE"; } } + } +}