From d7561cab0b1601866ce993b6557b2c8c2cb545b8 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Thu, 16 Mar 2023 18:37:46 +0400 Subject: [PATCH] Graceful Softnet termination (#434) --- Sources/tart/Commands/Run.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 61f5960..2040fcf 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -363,7 +363,13 @@ struct Run: AsyncParsableCommand { VMView(vm: vm!).onAppear { NSWindow.allowsAutomaticWindowTabbing = false }.onDisappear { - NSApplication.shared.terminate(self) + let ret = kill(getpid(), SIGINT) + if ret != 0 { + // Fallback to the old termination method that doesn't + // propagate the cancellation to Task's in case graceful + // termination via kill(2) is not successful + NSApplication.shared.terminate(self) + } } }.frame(width: CGFloat(vm!.config.display.width), height: CGFloat(vm!.config.display.height)) }.commands {