diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-29 13:58:17 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-04-03 10:27:43 +0200 |
commit | f58a69656a362a39e8826dd1027b3b5874f8f30a (patch) | |
tree | 14640742b515c1431d2421f54d0c0d504e3ba548 | |
parent | a65e80e8b6907c5666ff7f41316b0b00b78760f0 (diff) |
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.
-rw-r--r-- | src/core/nm-core-utils.c | 32 | ||||
-rw-r--r-- | src/core/tests/test-core-with-expect.c | 10 |
2 files changed, 17 insertions, 25 deletions
diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 880483b817..7482292034 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -507,16 +507,13 @@ nm_utils_kill_child_async(pid_t pid, return; } else if (ret != 0) { 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, - LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)", - LOG_NAME_ARGS, - nm_strerror_native(errsv), - errsv); - _kc_invoke_callback(pid, log_domain, log_name, callback, user_data, FALSE, -1); - return; - } + nm_log_err(LOGD_CORE | log_domain, + LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)", + LOG_NAME_ARGS, + nm_strerror_native(errsv), + errsv); + _kc_invoke_callback(pid, log_domain, log_name, callback, user_data, FALSE, -1); + return; } /* send the first signal. */ @@ -647,15 +644,12 @@ nm_utils_kill_child_sync(pid_t pid, goto out; } else if (ret != 0) { 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, - LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)", - LOG_NAME_ARGS, - nm_strerror_native(errsv), - errsv); - goto out; - } + nm_log_err(LOGD_CORE | log_domain, + LOG_NAME_FMT ": unexpected error while waitpid: %s (%d)", + LOG_NAME_ARGS, + nm_strerror_native(errsv), + errsv); + goto out; } /* send first signal @sig */ diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index b05144ac21..015101262c 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -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 * is a race here. */ - NMTST_EXPECT_NM_ERROR( - "kill child process 'test-s-3-2' (*): failed due to unexpected return value -1 by waitpid " - "(No child process*, 10) after sending no signal (0)"); + NMTST_EXPECT_NM_ERROR("kill child process 'test-s-3-2' (*): unexpected error while waitpid: No " + "child process* (10)"); 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 " @@ -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 * is a race here. */ - NMTST_EXPECT_NM_ERROR( - "kill child process 'test-a-3-2' (*): failed due to unexpected return value -1 by waitpid " - "(No child process*, 10) after sending no signal (0)"); + NMTST_EXPECT_NM_ERROR("kill child process 'test-a-3-2' (*): unexpected error while " + "waitpid: No child process* (10)"); NMTST_EXPECT_NM_DEBUG( "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); |