diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-10-13 10:00:12 +0200 |
---|---|---|
committer | Fabiano FidĂȘncio <fidencio@redhat.com> | 2015-10-12 13:47:09 +0200 |
commit | 23f0006849c63f3af3c8fd6f9b90349c908dc10d (patch) | |
tree | de9425992ef5f487b49341bdf911da7cce0be3e0 | |
parent | 67171946de26bfa5ce92c50286d4b6fa8204a1c6 (diff) | |
download | libssh-23f0006849c63f3af3c8fd6f9b90349c908dc10d.tar.gz libssh-23f0006849c63f3af3c8fd6f9b90349c908dc10d.tar.xz libssh-23f0006849c63f3af3c8fd6f9b90349c908dc10d.zip |
torture: Add torture_teardown_sshd_server().
-rw-r--r-- | tests/torture.c | 44 | ||||
-rw-r--r-- | tests/torture.h | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c index 032ae950..d99c3cf0 100644 --- a/tests/torture.c +++ b/tests/torture.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <signal.h> #ifndef _WIN32 # include <dirent.h> @@ -919,6 +920,49 @@ void torture_teardown_socket_dir(void **state) free(s); } +void torture_teardown_sshd_server(void **state) +{ + struct torture_state *s = *state; + char buf[8] = {0}; + long int tmp; + ssize_t rc; + pid_t pid; + int fd; + + /* read the pidfile */ + fd = open(s->srv_pidfile, O_RDONLY); + if (fd < 0) { + goto done; + } + + rc = read(fd, buf, sizeof(buf)); + close(fd); + if (rc <= 0) { + goto done; + } + + buf[sizeof(buf) - 1] = '\0'; + + tmp = strtol(buf, NULL, 10); + if (tmp == 0 || tmp > 0xFFFF || errno == ERANGE) { + goto done; + } + + pid = (pid_t)(tmp & 0xFFFF); + + /* Make sure the daemon goes away! */ + kill(pid, SIGTERM); + + kill(pid, 0); + if (rc == 0) { + fprintf(stderr, + "WARNING the sshd server is still running!\n"); + } + +done: + torture_teardown_socket_dir(state); +} + int torture_libssh_verbosity(void){ return verbosity; } diff --git a/tests/torture.h b/tests/torture.h index 071fa76c..efc477aa 100644 --- a/tests/torture.h +++ b/tests/torture.h @@ -112,6 +112,7 @@ void torture_setup_socket_dir(void **state); void torture_setup_sshd_server(void **state); void torture_teardown_socket_dir(void **state); +void torture_teardown_sshd_server(void **state); /* * This function must be defined in every unit test file. |