Expose a single process_wait()

There were two versions: process_wait() and process_wait_noclose().

Expose a single version with a flag (it was already implemented that way
internally).
This commit is contained in:
Romain Vimont 2021-01-22 18:48:17 +01:00
parent b8edcf52b0
commit 6a50231698
6 changed files with 13 additions and 35 deletions

View file

@ -178,7 +178,7 @@ file_handler_stop(struct file_handler *file_handler) {
if (!process_terminate(file_handler->current_process)) {
LOGW("Could not terminate install process");
}
process_wait(file_handler->current_process); // ignore exit code
process_wait(file_handler->current_process, true); // ignore exit code
file_handler->current_process = PROCESS_NONE;
}
mutex_unlock(file_handler->mutex);

View file

@ -391,7 +391,7 @@ server_init(struct server *server) {
static int
run_wait_server(void *data) {
struct server *server = data;
process_wait_noclose(server->process); // ignore exit code
process_wait(server->process, false); // ignore exit code
mutex_lock(server->mutex);
server->process_terminated = true;
@ -447,7 +447,7 @@ server_start(struct server *server, const char *serial,
SDL_CreateThread(run_wait_server, "wait-server", server);
if (!server->wait_server_thread) {
process_terminate(server->process);
process_wait(server->process); // ignore exit code
process_wait(server->process, true); // ignore exit code
goto error2;
}

View file

@ -121,8 +121,8 @@ process_terminate(pid_t pid) {
return kill(pid, SIGTERM) != -1;
}
static exit_code_t
process_wait_internal(pid_t pid, bool close) {
exit_code_t
process_wait(pid_t pid, bool close) {
int code;
int options = WEXITED;
if (!close) {
@ -140,19 +140,9 @@ process_wait_internal(pid_t pid, bool close) {
return code;
}
exit_code_t
process_wait(pid_t pid) {
return process_wait_internal(pid, true);
}
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, true); // ignore exit code
process_wait(pid, true); // ignore exit code
}
char *

View file

@ -59,8 +59,8 @@ process_terminate(HANDLE handle) {
return TerminateProcess(handle, 1);
}
static exit_code_t
process_wait_internal(HANDLE handle, bool close) {
exit_code_t
process_wait(HANDLE handle, bool close) {
DWORD code;
if (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0
|| !GetExitCodeProcess(handle, &code)) {
@ -73,16 +73,6 @@ process_wait_internal(HANDLE handle, bool close) {
return code;
}
exit_code_t
process_wait(HANDLE handle) {
return process_wait_internal(handle, true);
}
exit_code_t
process_wait_noclose(HANDLE handle) {
return process_wait_internal(handle, false);
}
void
process_close(HANDLE handle) {
bool closed = CloseHandle(handle);

View file

@ -8,7 +8,7 @@ process_check_success(process_t proc, const char *name) {
LOGE("Could not execute \"%s\"", name);
return false;
}
exit_code_t exit_code = process_wait(proc);
exit_code_t exit_code = process_wait(proc, true);
if (exit_code) {
if (exit_code != NO_EXIT_CODE) {
LOGE("\"%s\" returned with value %" PRIexitcode, name, exit_code);

View file

@ -47,16 +47,14 @@ bool
process_terminate(process_t pid);
// wait and close the process (like waitpid())
// the "close" flag indicates if the process must be "closed" (reaped)
// (passing false is equivalent to enable WNOWAIT in waitid())
exit_code_t
process_wait(process_t pid);
// wait (but does not close) the process (waitid() with WNOWAIT)
exit_code_t
process_wait_noclose(process_t pid);
process_wait(process_t pid, bool close);
// close the process
//
// Semantically, process_wait = process_wait_noclose + process_close.
// Semantically, process_wait(close) = process_wait(noclose) + process_close
void
process_close(process_t pid);