Commit 74594554 authored by Chris Wilson's avatar Chris Wilson

igt_core: Refactor igt_stop_helper() to use igt_wait_helper()

Reduce code duplication as the igt_stop_helper can reuse
igt_wait_helper() to replace its own waiting routine.
Signed-off-by: Chris Wilson's avatarChris Wilson <chris@chris-wilson.co.uk>
parent bd3cf81e
...@@ -843,56 +843,45 @@ bool __igt_fork_helper(struct igt_helper_process *proc) ...@@ -843,56 +843,45 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
} }
/** /**
* igt_stop_helper: * igt_wait_helper:
* @proc: #igt_helper_process structure * @proc: #igt_helper_process structure
* *
* Terminates a helper process. It is an error to call this on a helper process * Joins a helper process. It is an error to call this on a helper process which
* which hasn't been spawned yet. * hasn't been spawned yet.
*/ */
void igt_stop_helper(struct igt_helper_process *proc) int igt_wait_helper(struct igt_helper_process *proc)
{ {
int status, ret; int status = -1;
assert(proc->running); assert(proc->running);
ret = kill(proc->pid, waitpid(proc->pid, &status, WNOHANG);
proc->use_SIGKILL ? SIGKILL : SIGTERM);
assert(ret == 0);
while (waitpid(proc->pid, &status, 0) == -1 &&
errno == EINTR)
;
igt_assert(WIFSIGNALED(status) &&
WTERMSIG(status) == (proc->use_SIGKILL ? SIGKILL : SIGTERM));
proc->running = false; proc->running = false;
helper_process_pids[proc->id] = -1; helper_process_pids[proc->id] = -1;
helper_process_count--; helper_process_count--;
return status;
} }
/** /**
* igt_wait_helper: * igt_stop_helper:
* @proc: #igt_helper_process structure * @proc: #igt_helper_process structure
* *
* Joins a helper process. It is an error to call this on a helper process which * Terminates a helper process. It is an error to call this on a helper process
* hasn't been spawned yet. * which hasn't been spawned yet.
*/ */
void igt_wait_helper(struct igt_helper_process *proc) void igt_stop_helper(struct igt_helper_process *proc)
{ {
int status; int status;
assert(proc->running); /* failure here means the pid is already dead and so waiting is safe */
kill(proc->pid, proc->use_SIGKILL ? SIGKILL : SIGTERM);
while (waitpid(proc->pid, &status, 0) == -1 &&
errno == EINTR)
;
igt_assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
proc->running = false;
helper_process_pids[proc->id] = -1; status = igt_wait_helper(proc);
helper_process_count--; assert(WIFSIGNALED(status) &&
WTERMSIG(status) == (proc->use_SIGKILL ? SIGKILL : SIGTERM));
} }
static void children_exit_handler(int sig) static void children_exit_handler(int sig)
......
...@@ -420,7 +420,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc); ...@@ -420,7 +420,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc);
*/ */
#define igt_fork_helper(proc) \ #define igt_fork_helper(proc) \
for (; __igt_fork_helper(proc); exit(0)) for (; __igt_fork_helper(proc); exit(0))
void igt_wait_helper(struct igt_helper_process *proc); int igt_wait_helper(struct igt_helper_process *proc);
void igt_stop_helper(struct igt_helper_process *proc); void igt_stop_helper(struct igt_helper_process *proc);
/* exit handler code */ /* exit handler code */
......
...@@ -253,8 +253,12 @@ static void load_helper_run(enum load load) ...@@ -253,8 +253,12 @@ static void load_helper_run(enum load load)
static void load_helper_stop(void) static void load_helper_stop(void)
{ {
int status;
kill(lh.igt_proc.pid, SIGUSR1); kill(lh.igt_proc.pid, SIGUSR1);
igt_wait_helper(&lh.igt_proc); status = igt_wait_helper(&lh.igt_proc);
igt_assert(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1);
} }
static void load_helper_init(void) static void load_helper_init(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment