Browse Source

Fixed bug where returning non-zero was not detected as a crash when getting the status of a child process on Posix systems.

David Piuva 2 years ago
parent
commit
9a2fc46009
1 changed files with 8 additions and 1 deletions
  1. 8 1
      Source/DFPSR/api/fileAPI.cpp

+ 8 - 1
Source/DFPSR/api/fileAPI.cpp

@@ -719,9 +719,16 @@ DsrProcessStatus process_getStatus(const DsrProcess &process) {
 				int status = 0;
 				int status = 0;
 				if (waitpid(process->pid, &status, WNOHANG) != 0) {
 				if (waitpid(process->pid, &status, WNOHANG) != 0) {
 					if (WIFEXITED(status)) {
 					if (WIFEXITED(status)) {
-						process->lastStatus = DsrProcessStatus::Completed;
+						if (WEXITSTATUS(status) == 0) {
+							// The program finished and returned 0 for success.
+							process->lastStatus = DsrProcessStatus::Completed;
+						} else {
+							// The program finished, but returned a non-zero result indicating that something still went wrong.
+							process->lastStatus = DsrProcessStatus::Crashed;
+						}
 						process->terminated = true;
 						process->terminated = true;
 					} else if (WIFSIGNALED(status)) {
 					} else if (WIFSIGNALED(status)) {
+						// The program was stopped due to a hard crash.
 						process->lastStatus = DsrProcessStatus::Crashed;
 						process->lastStatus = DsrProcessStatus::Crashed;
 						process->terminated = true;
 						process->terminated = true;
 					}
 					}