From c8222dc1f64621112a6bb309cab3c995fcfe3c6b Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Thu, 30 Jan 2020 18:57:09 +0100 Subject: [PATCH] tests: Verify error returned by kill Verify the error code returned by kill() in torture_terminate_process(). The error code is raised when killing the process failed. Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Jakub Jelen --- tests/client/torture_auth.c | 3 ++- tests/server/torture_server_config.c | 4 +--- tests/torture.c | 18 +++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c index 5a3d2e0d..b89f4334 100644 --- a/tests/client/torture_auth.c +++ b/tests/client/torture_auth.c @@ -194,7 +194,8 @@ static int agent_teardown(void **state) assert_non_null(ssh_agent_pidfile); /* kill agent pid */ - torture_terminate_process(ssh_agent_pidfile); + rc = torture_terminate_process(ssh_agent_pidfile); + assert_return_code(rc, errno); unlink(ssh_agent_pidfile); diff --git a/tests/server/torture_server_config.c b/tests/server/torture_server_config.c index d751dd74..d8ee697e 100644 --- a/tests/server/torture_server_config.c +++ b/tests/server/torture_server_config.c @@ -285,9 +285,7 @@ static int stop_server(void **state) assert_non_null(s); rc = torture_terminate_process(s->srv_pidfile); - if (rc != 0) { - fprintf(stderr, "XXXXXX Failed to terminate sshd\n"); - } + assert_return_code(rc, errno); unlink(s->srv_pidfile); diff --git a/tests/torture.c b/tests/torture.c index 652421e9..c4794382 100644 --- a/tests/torture.c +++ b/tests/torture.c @@ -246,8 +246,12 @@ int torture_terminate_process(const char *pidfile) rc = kill(pid, 0); if (rc != 0) { - is_running = 0; - break; + /* Process not found */ + if (errno == ESRCH) { + is_running = 0; + rc = 0; + break; + } } } @@ -256,7 +260,7 @@ int torture_terminate_process(const char *pidfile) "WARNING: The process with pid %u is still running!\n", pid); } - return 0; + return rc; } ssh_session torture_ssh_session(struct torture_state *s, @@ -923,9 +927,7 @@ torture_reload_sshd_server(void **state) int rc; rc = torture_terminate_process(s->srv_pidfile); - if (rc != 0) { - fprintf(stderr, "XXXXXX Failed to terminate sshd\n"); - } + assert_return_code(rc, errno); return torture_start_sshd_server(state); } @@ -963,9 +965,7 @@ void torture_teardown_sshd_server(void **state) int rc; rc = torture_terminate_process(s->srv_pidfile); - if (rc != 0) { - fprintf(stderr, "XXXXXX Failed to terminate sshd\n"); - } + assert_return_code(rc, errno); torture_teardown_socket_dir(state); }