aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2020-01-30 15:53:26 +0100
committerAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2020-02-24 19:29:57 +0100
commit35224092ebd45679e233252b8e36ffcf94fb285d (patch)
tree5b575001919f51ba8909714e62d1a7930fbe2bef
parenta9e39a41ffb58323b4b6c0dd73c83fb7fb4e8179 (diff)
downloadlibssh-35224092ebd45679e233252b8e36ffcf94fb285d.tar.gz
libssh-35224092ebd45679e233252b8e36ffcf94fb285d.tar.xz
libssh-35224092ebd45679e233252b8e36ffcf94fb285d.zip
tests: Use a common function to start sshd
In torture_reload_sshd_server(), instead of trying to use SIGHUP to reload the configuration file, kill the original process and create a new one with the new configuration. With this change, both torture_setup_sshd_server() and torture_reload_sshd_server() need to start sshd, with the only difference in the configuration setup. The shared code to start the sshd server was moved to a new introduced internal function torture_start_sshd_server(). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
-rw-r--r--tests/torture.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/tests/torture.c b/tests/torture.c
index 62cbfaf1..05d9a991 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -825,21 +825,16 @@ static int torture_wait_for_daemon(unsigned int seconds)
return 1;
}
-void torture_setup_sshd_server(void **state, bool pam)
+static int torture_start_sshd_server(void **state)
{
- struct torture_state *s;
+ struct torture_state *s = *state;
char sshd_start_cmd[1024];
int rc;
- torture_setup_socket_dir(state);
- torture_setup_create_sshd_config(state, pam);
-
/* Set the default interface for the server */
setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "10", 1);
setenv("PAM_WRAPPER", "1", 1);
- s = *state;
-
snprintf(sshd_start_cmd, sizeof(sshd_start_cmd),
SSHD_EXECUTABLE " -r -f %s -E %s/sshd/daemon.log 2> %s/sshd/cwrap.log",
s->srv_config, s->socket_dir, s->socket_dir);
@@ -851,7 +846,20 @@ void torture_setup_sshd_server(void **state, bool pam)
unsetenv("PAM_WRAPPER");
/* Wait until the sshd is ready to accept connections */
- rc = torture_wait_for_daemon(5);
+ rc = torture_wait_for_daemon(15);
+ assert_int_equal(rc, 0);
+
+ return SSH_OK;
+}
+
+void torture_setup_sshd_server(void **state, bool pam)
+{
+ int rc;
+
+ torture_setup_socket_dir(state);
+ torture_setup_create_sshd_config(state, pam);
+
+ rc = torture_start_sshd_server(state);
assert_int_equal(rc, 0);
}
@@ -908,29 +916,14 @@ static int
torture_reload_sshd_server(void **state)
{
struct torture_state *s = *state;
- pid_t pid;
int rc;
- /* read the pidfile */
- pid = torture_read_pidfile(s->srv_pidfile);
- assert_int_not_equal(pid, -1);
-
- kill(pid, SIGHUP);
-
- /* 10 ms */
- usleep(10 * 1000);
-
- rc = kill(pid, 0);
+ rc = torture_terminate_process(s->srv_pidfile);
if (rc != 0) {
- fprintf(stderr,
- "ERROR: SSHD process %u died during reload!\n", pid);
- return SSH_ERROR;
+ fprintf(stderr, "XXXXXX Failed to terminate sshd\n");
}
- /* Wait until the sshd is ready to accept connections */
- rc = torture_wait_for_daemon(10);
- assert_int_equal(rc, 0);
- return SSH_OK;
+ return torture_start_sshd_server(state);
}
/* @brief: Updates SSHD server configuration with more options and