Skip to content

Commit

Permalink
Fix posix_kill crashing / killing other programs on null (#68)
Browse files Browse the repository at this point in the history
When `$pid` in `posix_kill($pid, $signo)` is `null` it kills other programs like Firefox, Terminal, even Gnome Shell.

This patch adds a null check to avoid this.

Discovered via phpactor in Sublime Text: Removing several folders in quick succession causes `posix_kill` to be called with `null`, for whatever reason, which causes a bunch of programs to crash.

See phpactor/phpactor#2516.

Co-authored-by: Niklas Keller <me@kelunik.com>
  • Loading branch information
gerardroche and kelunik committed Feb 24, 2024
1 parent 76e9495 commit 04b4517
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Internal/Posix/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function kill(ProcessHandle $handle)
return;
}
// ignore errors because process not always detached
@\posix_kill($pid, 9);
self::tryPosixKill($pid, 9);
});

if ($handle->status < ProcessStatus::ENDED) {
Expand All @@ -213,10 +213,17 @@ public function signal(ProcessHandle $handle, int $signo)
return;
}

@\posix_kill($pid, $signo);
self::tryPosixKill($pid, $signo);
});
}

private static function tryPosixKill($pid, int $signo)
{
if ($pid !== null) {
@\posix_kill($pid, $signo);
}
}

/** @inheritdoc */
public function destroy(ProcessHandle $handle)
{
Expand Down

0 comments on commit 04b4517

Please sign in to comment.