From 3d322c3f36d8d4deb7ef13618f867d13e01a1fc0 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 8 Jul 2025 16:13:05 +0100 Subject: [PATCH] linux/bsd/mac: Use pkill to stop remote instance over SSH Previously, the PIDs of any running instances of the game on the remote device were found with `pgrep`, whose output was passed as parameters to `kill`. The problem with doing this is that passing zero arguments to `kill` (which happens when no instances of the game are running remotely) is an error: it shows the command usage, and exits with status 2 indicating a command-line syntax error: $ kill kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec] $ echo $? 2 As far as I can tell, all systems that have a `pgrep` command also have a `pkill` command which accepts (a superset of) the same parameters as `pgrep` and kills the matched processes instead of listing them on STDOUT. In the case where no processes match, `pkill` exits with status 1; but does so silently. Invoke `pkill` rather than `pgrep` + `kill`. --- platform/linuxbsd/export/export_plugin.cpp | 2 +- platform/macos/export/export_plugin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/linuxbsd/export/export_plugin.cpp b/platform/linuxbsd/export/export_plugin.cpp index 77f2c79c33e..c63096cd642 100644 --- a/platform/linuxbsd/export/export_plugin.cpp +++ b/platform/linuxbsd/export/export_plugin.cpp @@ -192,7 +192,7 @@ void EditorExportPlatformLinuxBSD::get_export_options(List *r_opti "\"{temp_dir}/{exe_name}\" {cmd_args}"; String cleanup_script = "#!/usr/bin/env bash\n" - "kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")\n" + "pkill -x -f \"{temp_dir}/{exe_name} {cmd_args}\"\n" "rm -rf \"{temp_dir}\""; r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true)); diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 60e339756a9..edebfe66260 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -595,7 +595,7 @@ void EditorExportPlatformMacOS::get_export_options(List *r_options "open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}"; String cleanup_script = "#!/usr/bin/env bash\n" - "kill $(pgrep -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\")\n" + "pkill -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\"\n" "rm -rf \"{temp_dir}\""; r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));