mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 19:50:07 +01:00
core: error out in nm_utils_kill_child_{sync,async}() if first waitpid() gives ECHILD
It is wrong trying to send the signal still. Just error out. Note that ECHILD indicates that the process is either not a child or was already reaped. In both cases, that is a bug of the caller who must keep accurate track of the child's process ID.
This commit is contained in:
parent
a65e80e8b6
commit
f58a69656a
2 changed files with 17 additions and 25 deletions
|
|
@ -507,8 +507,6 @@ nm_utils_kill_child_async(pid_t pid,
|
||||||
return;
|
return;
|
||||||
} else if (ret != 0) {
|
} else if (ret != 0) {
|
||||||
errsv = errno;
|
errsv = errno;
|
||||||
/* ECHILD means, the process is not a child/does not exist or it has SIGCHILD blocked. */
|
|
||||||
if (errsv != ECHILD) {
|
|
||||||
nm_log_err(LOGD_CORE | log_domain,
|
nm_log_err(LOGD_CORE | log_domain,
|
||||||
LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)",
|
LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)",
|
||||||
LOG_NAME_ARGS,
|
LOG_NAME_ARGS,
|
||||||
|
|
@ -517,7 +515,6 @@ nm_utils_kill_child_async(pid_t pid,
|
||||||
_kc_invoke_callback(pid, log_domain, log_name, callback, user_data, FALSE, -1);
|
_kc_invoke_callback(pid, log_domain, log_name, callback, user_data, FALSE, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* send the first signal. */
|
/* send the first signal. */
|
||||||
if (kill(pid, sig) != 0) {
|
if (kill(pid, sig) != 0) {
|
||||||
|
|
@ -647,8 +644,6 @@ nm_utils_kill_child_sync(pid_t pid,
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret != 0) {
|
} else if (ret != 0) {
|
||||||
errsv = errno;
|
errsv = errno;
|
||||||
/* ECHILD means, the process is not a child/does not exist or it has SIGCHILD blocked. */
|
|
||||||
if (errsv != ECHILD) {
|
|
||||||
nm_log_err(LOGD_CORE | log_domain,
|
nm_log_err(LOGD_CORE | log_domain,
|
||||||
LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)",
|
LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)",
|
||||||
LOG_NAME_ARGS,
|
LOG_NAME_ARGS,
|
||||||
|
|
@ -656,7 +651,6 @@ nm_utils_kill_child_sync(pid_t pid,
|
||||||
errsv);
|
errsv);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* send first signal @sig */
|
/* send first signal @sig */
|
||||||
if (kill(pid, sig) != 0) {
|
if (kill(pid, sig) != 0) {
|
||||||
|
|
|
||||||
|
|
@ -333,9 +333,8 @@ do_test_nm_utils_kill_child(void)
|
||||||
|
|
||||||
/* pid3s should not be a valid process, hence the call should fail. Note, that there
|
/* pid3s should not be a valid process, hence the call should fail. Note, that there
|
||||||
* is a race here. */
|
* is a race here. */
|
||||||
NMTST_EXPECT_NM_ERROR(
|
NMTST_EXPECT_NM_ERROR("kill child process 'test-s-3-2' (*): unexpected error while waitpid: No "
|
||||||
"kill child process 'test-s-3-2' (*): failed due to unexpected return value -1 by waitpid "
|
"child process* (10)");
|
||||||
"(No child process*, 10) after sending no signal (0)");
|
|
||||||
test_nm_utils_kill_child_sync_do("test-s-3-2", pid3s, 0, 0, FALSE, NULL);
|
test_nm_utils_kill_child_sync_do("test-s-3-2", pid3s, 0, 0, FALSE, NULL);
|
||||||
|
|
||||||
NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): waiting up to 50 milliseconds for "
|
NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): waiting up to 50 milliseconds for "
|
||||||
|
|
@ -396,9 +395,8 @@ do_test_nm_utils_kill_child(void)
|
||||||
|
|
||||||
/* pid3a should not be a valid process, hence the call should fail. Note, that there
|
/* pid3a should not be a valid process, hence the call should fail. Note, that there
|
||||||
* is a race here. */
|
* is a race here. */
|
||||||
NMTST_EXPECT_NM_ERROR(
|
NMTST_EXPECT_NM_ERROR("kill child process 'test-a-3-2' (*): unexpected error while "
|
||||||
"kill child process 'test-a-3-2' (*): failed due to unexpected return value -1 by waitpid "
|
"waitpid: No child process* (10)");
|
||||||
"(No child process*, 10) after sending no signal (0)");
|
|
||||||
NMTST_EXPECT_NM_DEBUG(
|
NMTST_EXPECT_NM_DEBUG(
|
||||||
"kill child process 'test-a-3-2' (*): invoke callback: killing child failed");
|
"kill child process 'test-a-3-2' (*): invoke callback: killing child failed");
|
||||||
test_nm_utils_kill_child_async_do("test-a-3-2", pid3a, 0, 0, FALSE, NULL);
|
test_nm_utils_kill_child_async_do("test-a-3-2", pid3a, 0, 0, FALSE, NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue