You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #106708 from bruvzg/nohang_exitcode
Fix `execute_with_pipe` / `create_process` exit code.
This commit is contained in:
@@ -811,10 +811,14 @@ Dictionary OS_Unix::execute_with_pipe(const String &p_path, const List<String> &
|
||||
#endif
|
||||
}
|
||||
|
||||
int OS_Unix::_wait_for_pid_completion(const pid_t p_pid, int *r_status, int p_options) {
|
||||
int OS_Unix::_wait_for_pid_completion(const pid_t p_pid, int *r_status, int p_options, pid_t *r_pid) {
|
||||
while (true) {
|
||||
if (waitpid(p_pid, r_status, p_options) != -1) {
|
||||
pid_t pid = waitpid(p_pid, r_status, p_options);
|
||||
if (pid != -1) {
|
||||
// Thread exited normally.
|
||||
if (r_pid) {
|
||||
*r_pid = pid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
const int error = errno;
|
||||
@@ -838,10 +842,14 @@ bool OS_Unix::_check_pid_is_running(const pid_t p_pid, int *r_status) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
pid_t pid = -1;
|
||||
int status = 0;
|
||||
const int result = _wait_for_pid_completion(p_pid, &status, WNOHANG);
|
||||
const int result = _wait_for_pid_completion(p_pid, &status, WNOHANG, &pid);
|
||||
if (result == 0) {
|
||||
// Thread is still running.
|
||||
if (pi && pid == p_pid) {
|
||||
pi->exit_code = WIFEXITED(status) ? WEXITSTATUS(status) : status;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -852,8 +860,10 @@ bool OS_Unix::_check_pid_is_running(const pid_t p_pid, int *r_status) const {
|
||||
|
||||
if (pi) {
|
||||
pi->is_running = false;
|
||||
if (pid == p_pid) {
|
||||
pi->exit_code = status;
|
||||
}
|
||||
}
|
||||
|
||||
if (r_status) {
|
||||
*r_status = status;
|
||||
|
||||
@@ -71,7 +71,7 @@ class OS_Unix : public OS {
|
||||
void _load_iconv();
|
||||
#endif
|
||||
|
||||
static int _wait_for_pid_completion(const pid_t p_pid, int *r_status, int p_options);
|
||||
static int _wait_for_pid_completion(const pid_t p_pid, int *r_status, int p_options, pid_t *r_pid = nullptr);
|
||||
bool _check_pid_is_running(const pid_t p_pid, int *r_status) const;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user