Commit 8517bc7d authored by Andrei Vagin's avatar Andrei Vagin

service: use waitpid() when a child pid is known

We want to wait a specific child. wait() waits any child.
Signed-off-by: 's avatarAndrei Vagin <avagin@gmail.com>
parent e4d8dc6f
...@@ -753,10 +753,11 @@ cout: ...@@ -753,10 +753,11 @@ cout:
exit(ret); exit(ret);
} }
wait(&status); if (waitpid(pid, &status, 0) != pid) {
if (!WIFEXITED(status)) pr_perror("Unable to wait %d", pid);
goto out; goto out;
if (WEXITSTATUS(status) != 0) }
if (status != 0)
goto out; goto out;
success = true; success = true;
...@@ -842,7 +843,10 @@ out_ch: ...@@ -842,7 +843,10 @@ out_ch:
close(start_pipe[1]); close(start_pipe[1]);
if (daemon_mode) { if (daemon_mode) {
wait(&ret); if (waitpid(pid, &ret, 0) != pid) {
pr_perror("Unable to wait %d", pid);
goto out;
}
if (WIFEXITED(ret)) { if (WIFEXITED(ret)) {
if (WEXITSTATUS(ret)) { if (WEXITSTATUS(ret)) {
pr_err("Child exited with an error\n"); pr_err("Child exited with an error\n");
...@@ -990,20 +994,14 @@ static int handle_feature_check(int sk, CriuReq * msg) ...@@ -990,20 +994,14 @@ static int handle_feature_check(int sk, CriuReq * msg)
* be send from the parent process. * be send from the parent process.
*/ */
ret = send_criu_msg(sk, &resp); ret = send_criu_msg(sk, &resp);
exit(ret); exit(ret);
} }
if (waitpid(pid, &status, 0) != pid) {
ret = waitpid(pid, &status, 0); pr_perror("Unable to wait %d", pid);
if (ret == -1) goto out;
}
if (status != 0)
goto out; goto out;
if (WIFEXITED(status) && !WEXITSTATUS(status))
/*
* The child process exited was able to send the answer.
* Nothing more to do here.
*/
return 0;
/* /*
* The child process was not able to send an answer. Tell * The child process was not able to send an answer. Tell
...@@ -1070,7 +1068,10 @@ cout: ...@@ -1070,7 +1068,10 @@ cout:
exit(ret); exit(ret);
} }
wait(&status); if (waitpid(pid, &status, 0) != pid) {
pr_perror("Unable to wait %d", pid);
goto out;
}
if (!WIFEXITED(status)) if (!WIFEXITED(status))
goto out; goto out;
switch (WEXITSTATUS(status)) { switch (WEXITSTATUS(status)) {
......
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