Skip to content

Commit 3d322c3

Browse files
committed
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`.
1 parent 99a39ce commit 3d322c3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

platform/linuxbsd/export/export_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void EditorExportPlatformLinuxBSD::get_export_options(List<ExportOption> *r_opti
192192
"\"{temp_dir}/{exe_name}\" {cmd_args}";
193193

194194
String cleanup_script = "#!/usr/bin/env bash\n"
195-
"kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")\n"
195+
"pkill -x -f \"{temp_dir}/{exe_name} {cmd_args}\"\n"
196196
"rm -rf \"{temp_dir}\"";
197197

198198
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));

platform/macos/export/export_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options
595595
"open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}";
596596

597597
String cleanup_script = "#!/usr/bin/env bash\n"
598-
"kill $(pgrep -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\")\n"
598+
"pkill -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\"\n"
599599
"rm -rf \"{temp_dir}\"";
600600

601601
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));

0 commit comments

Comments
 (0)