aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2014-10-13 10:00:12 +0200
committerJakub Jelen <jjelen@redhat.com>2018-10-02 16:33:40 +0200
commit7113074ae4cfbd13c7a1b9511739cb880daf2424 (patch)
tree542e07764228a19db0160296a1956b4f73a0f8e7
parent2db325eb74db424857000d7c32dde9f1b6a58b5f (diff)
downloadlibssh-7113074ae4cfbd13c7a1b9511739cb880daf2424.tar.gz
libssh-7113074ae4cfbd13c7a1b9511739cb880daf2424.tar.xz
libssh-7113074ae4cfbd13c7a1b9511739cb880daf2424.zip
torture: Add torture_teardown_sshd_server().
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> (cherry-picked from commit 14f1ce2e)
-rw-r--r--tests/torture.c44
-rw-r--r--tests/torture.h1
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c
index 75db88a1..42e1d74b 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>
@@ -820,6 +821,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 31691604..1177bc3c 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -109,6 +109,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.