Simplify process_wait()
The function process_wait() returned a bool (true if the process terminated successfully) and provided the exit code via an output parameter exit_code. But the returned value was always equivalent to exit_code == 0, so just return the exit code instead.
This commit is contained in:
@@ -121,8 +121,8 @@ process_terminate(pid_t pid) {
|
||||
return kill(pid, SIGTERM) != -1;
|
||||
}
|
||||
|
||||
static bool
|
||||
process_wait_internal(pid_t pid, int *exit_code, bool close) {
|
||||
static exit_code_t
|
||||
process_wait_internal(pid_t pid, bool close) {
|
||||
int code;
|
||||
int options = WEXITED;
|
||||
if (!close) {
|
||||
@@ -133,29 +133,26 @@ process_wait_internal(pid_t pid, int *exit_code, bool close) {
|
||||
int r = waitid(P_PID, pid, &info, options);
|
||||
if (r == -1 || info.si_code != CLD_EXITED) {
|
||||
// could not wait, or exited unexpectedly, probably by a signal
|
||||
code = -1;
|
||||
code = NO_EXIT_CODE;
|
||||
} else {
|
||||
code = info.si_status;
|
||||
}
|
||||
if (exit_code) {
|
||||
*exit_code = code;
|
||||
}
|
||||
return !code;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool
|
||||
process_wait(pid_t pid, int *exit_code) {
|
||||
return process_wait_internal(pid, exit_code, true);
|
||||
exit_code_t
|
||||
process_wait(pid_t pid) {
|
||||
return process_wait_internal(pid, true);
|
||||
}
|
||||
|
||||
bool
|
||||
process_wait_noclose(pid_t pid, int *exit_code) {
|
||||
return process_wait_internal(pid, exit_code, false);
|
||||
exit_code_t
|
||||
process_wait_noclose(pid_t pid) {
|
||||
return process_wait_internal(pid, false);
|
||||
}
|
||||
|
||||
void
|
||||
process_close(pid_t pid) {
|
||||
process_wait_internal(pid, NULL, true);
|
||||
process_wait_internal(pid, true); // ignore exit code
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
@@ -59,31 +59,28 @@ process_terminate(HANDLE handle) {
|
||||
return TerminateProcess(handle, 1);
|
||||
}
|
||||
|
||||
static bool
|
||||
process_wait_internal(HANDLE handle, DWORD *exit_code, bool close) {
|
||||
static exit_code_t
|
||||
process_wait_internal(HANDLE handle, bool close) {
|
||||
DWORD code;
|
||||
if (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0
|
||||
|| !GetExitCodeProcess(handle, &code)) {
|
||||
// could not wait or retrieve the exit code
|
||||
code = -1; // max value, it's unsigned
|
||||
}
|
||||
if (exit_code) {
|
||||
*exit_code = code;
|
||||
code = NO_EXIT_CODE; // max value, it's unsigned
|
||||
}
|
||||
if (close) {
|
||||
CloseHandle(handle);
|
||||
}
|
||||
return !code;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool
|
||||
process_wait(HANDLE handle, DWORD *exit_code) {
|
||||
return process_wait_internal(handle, exit_code, true);
|
||||
exit_code_t
|
||||
process_wait(HANDLE handle) {
|
||||
return process_wait_internal(handle, true);
|
||||
}
|
||||
|
||||
bool
|
||||
process_wait_noclose(HANDLE handle, DWORD *exit_code) {
|
||||
return process_wait_internal(handle, exit_code, false);
|
||||
exit_code_t
|
||||
process_wait_noclose(HANDLE handle) {
|
||||
return process_wait_internal(handle, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user