From 9a68ec410fc7a6c62eedc6a022b2ade55072e509 Mon Sep 17 00:00:00 2001 From: Phil Date: Mon, 26 Oct 2026 20:30:12 +1300 Subject: [PATCH] RenameFile: harden detached process spawn with start_new_session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit executeProcess()'s detach path spawned the child with a plain subprocess.Popen(args), with a comment flagging that macOS may need start_new_session=True to let the child survive the launching task process exiting — but the flag was never actually applied. Split out of #802 (which found and fixed the same gap in FileMonitor, where it caused a reproducible bug) at the maintainer's request to keep that PR single-plugin; applying the identical fix here proactively since this plugin shares the same vendored StashPluginHelper.py code path. Co-Authored-By: Claude Sonnet 5 --- plugins/RenameFile/StashPluginHelper.py | 5 ++++- plugins/RenameFile/renamefile.yml | 2 +- plugins/RenameFile/version_history/README.md | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/RenameFile/StashPluginHelper.py b/plugins/RenameFile/StashPluginHelper.py index 90c8c1b9..3516b4fb 100644 --- a/plugins/RenameFile/StashPluginHelper.py +++ b/plugins/RenameFile/StashPluginHelper.py @@ -481,9 +481,12 @@ def executeProcess(self, args, ExecDetach=False): if self.IS_LINUX: args = ["nohup"] + args self.Trace(f"Executing detached process using Popen({args})") + # start_new_session puts the child in its own session, so it survives the + # parent task process exiting (needed on macOS; harmless on Linux too). + pid = subprocess.Popen(args, start_new_session=True).pid else: self.Trace(f"Executing process using normal Popen({args})") - pid = subprocess.Popen(args).pid # On detach, may need the following for MAC OS subprocess.Popen(args, shell=True, start_new_session=True) + pid = subprocess.Popen(args).pid self.Trace(f"pid={pid}") return pid diff --git a/plugins/RenameFile/renamefile.yml b/plugins/RenameFile/renamefile.yml index ca3040e0..0dc62c49 100644 --- a/plugins/RenameFile/renamefile.yml +++ b/plugins/RenameFile/renamefile.yml @@ -1,6 +1,6 @@ name: RenameFile description: Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab. -version: 1.0.4 +version: 1.0.5 url: https://discourse.stashapp.cc/t/renamefile/1334 ui: css: diff --git a/plugins/RenameFile/version_history/README.md b/plugins/RenameFile/version_history/README.md index 5f72ff98..d7929765 100644 --- a/plugins/RenameFile/version_history/README.md +++ b/plugins/RenameFile/version_history/README.md @@ -21,3 +21,5 @@ ### 1.0.3 - Fixed OSError "File name too long" (macOS) caused by the long-filename truncation logic appending the file extension twice and not reserving space for the hash suffix. - Rename/move failures now log a single clear error message instead of also dumping a raw Python traceback to the log. +### 1.0.5 +- Hardened detached process spawn (executeProcess) with start_new_session=True, so a detached child survives the launching task process exiting on macOS.