mirror of https://github.com/winsw/winsw
Fix service crashes (#680)
parent
bff88217d3
commit
7c61b9c43c
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||
using System.Management;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using WinSW.Native;
|
||||
|
||||
namespace WinSW.Util
|
||||
{
|
||||
|
@ -168,7 +169,19 @@ namespace WinSW.Util
|
|||
}
|
||||
}
|
||||
|
||||
processToStart.Start();
|
||||
bool succeeded = ConsoleApis.SetConsoleCtrlHandler(null, false); // inherited
|
||||
Debug.Assert(succeeded);
|
||||
|
||||
try
|
||||
{
|
||||
processToStart.Start();
|
||||
}
|
||||
finally
|
||||
{
|
||||
succeeded = ConsoleApis.SetConsoleCtrlHandler(null, true);
|
||||
Debug.Assert(succeeded);
|
||||
}
|
||||
|
||||
Logger.Info("Started process " + processToStart.Id);
|
||||
|
||||
if (priority != null)
|
||||
|
|
|
@ -29,9 +29,10 @@ namespace WinSW.Util
|
|||
return new KeyValuePair<bool, bool>(false, error == Errors.ERROR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
_ = ConsoleApis.SetConsoleCtrlHandler(null, true);
|
||||
// Don't call GenerateConsoleCtrlEvent immediately after SetConsoleCtrlHandler.
|
||||
// A delay was observed as of Windows 10, version 2004 and Windows Server 2019.
|
||||
_ = ConsoleApis.GenerateConsoleCtrlEvent(ConsoleApis.CtrlEvents.CTRL_C_EVENT, 0);
|
||||
_ = ConsoleApis.SetConsoleCtrlHandler(null, false);
|
||||
|
||||
bool succeeded = ConsoleApis.FreeConsole();
|
||||
Debug.Assert(succeeded);
|
||||
|
||||
|
|
|
@ -182,6 +182,9 @@ namespace WinSW
|
|||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
bool succeeded = ConsoleApis.SetConsoleCtrlHandler(null, true);
|
||||
Debug.Assert(succeeded);
|
||||
|
||||
this.envs = this.descriptor.EnvironmentVariables;
|
||||
|
||||
// TODO: Disabled according to security concerns in https://github.com/kohsuke/winsw/issues/54
|
||||
|
|
Loading…
Reference in New Issue