diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-12-02 11:59:35 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-12-04 03:36:19 +0100 |
commit | a85f4b7349e2ce2aadc2546609578289aa886676 (patch) | |
tree | 450d883d8d05b8aa2c78cf911d3286d4311eff65 /src | |
parent | 73a09df16fa6e7f303777dd5a55f3b0decc59c78 (diff) |
tests: make sure ncat gets killed
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rwxr-xr-x | src/tests/netns.sh | 7 | ||||
-rw-r--r-- | src/tests/qemu/Makefile | 2 | ||||
-rw-r--r-- | src/tests/qemu/init.c | 13 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/tests/netns.sh b/src/tests/netns.sh index 4e8465c..50040fa 100755 --- a/src/tests/netns.sh +++ b/src/tests/netns.sh @@ -48,10 +48,11 @@ cleanup() { ip0 link del dev wg0 ip1 link del dev wg0 ip2 link del dev wg0 + local to_kill="$(ip netns pids $netns0) $(ip netns pids $netns1) $(ip netns pids $netns2)" + [[ -n $to_kill ]] && kill $to_kill pp ip netns del $netns1 pp ip netns del $netns2 pp ip netns del $netns0 - kill -- -$$ exit } @@ -176,14 +177,14 @@ n1 ping -W 1 -c 1 192.168.241.2 # Test that crypto-RP filter works n1 wg set wg0 peer "$pub2" allowed-ips 192.168.241.0/24 -read -r -N 1 -t 1 out < <(n1 ncat -l -u -p 1111) && [[ $out == "X" ]] & listener_pid=$! +read -r -N 1 -t 1 out < <(n1 ncat -l -u -p 1111 2>/dev/null) && [[ $out == "X" ]] & listener_pid=$! waitncatudp $netns1 n2 ncat -u 192.168.241.1 1111 <<<"X" wait $listener_pid more_specific_key="$(pp wg genkey | pp wg pubkey)" n1 wg set wg0 peer "$more_specific_key" allowed-ips 192.168.241.2/32 n2 wg set wg0 listen-port 9997 -read -r -N 1 -t 1 out < <(n1 ncat -l -u -p 1111) && [[ $out == "X" ]] & listener_pid=$! +read -r -N 1 -t 1 out < <(n1 ncat -l -u -p 1111 2>/dev/null) && [[ $out == "X" ]] & listener_pid=$! waitncatudp $netns1 n2 ncat -u 192.168.241.1 1111 <<<"X" ! wait $listener_pid || false diff --git a/src/tests/qemu/Makefile b/src/tests/qemu/Makefile index b60aa5a..a1ece9b 100644 --- a/src/tests/qemu/Makefile +++ b/src/tests/qemu/Makefile @@ -45,7 +45,7 @@ KERNEL_BZIMAGE := $(KERNEL_PATH)/arch/x86/boot/bzImage $(eval $(call tar_download,MUSL,musl,1.1.15,.tar.gz,https://www.musl-libc.org/releases/)) $(eval $(call tar_download,LIBMNL,libmnl,1.0.4,.tar.bz2,http://ftp.netfilter.org/pub/libmnl/)) $(eval $(call tar_download,IPERF,iperf,3.1.3,.tar.gz,http://downloads.es.net/pub/iperf/)) -$(eval $(call tar_download,BASH,bash,30a978b7d808c067219c95be88c4979b6a7aa251,.tar.gz,http://git.savannah.gnu.org/cgit/bash.git/snapshot/)) +$(eval $(call tar_download,BASH,bash,f459cbd8be37b28be1dc90315e0ab51d7f211301,.tar.gz,http://git.savannah.gnu.org/cgit/bash.git/snapshot/)) $(eval $(call tar_download,IPROUTE2,iproute2,4.3.0,.tar.gz,http://www.kernel.org/pub/linux/utils/net/iproute2/)) $(eval $(call tar_download,IPTABLES,iptables,1.6.0,.tar.bz2,http://ftp.netfilter.org/pub/iptables/)) $(eval $(call tar_download,NMAP,nmap,7.25BETA1,.tar.bz2,http://nmap.org/dist/)) diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c index 62157c0..d23ec37 100644 --- a/src/tests/qemu/init.c +++ b/src/tests/qemu/init.c @@ -144,18 +144,17 @@ static void kmod_selftests(void) static void launch_tests(void) { int status, fd; + pid_t pid; pretty_message("[+] Launching tests..."); - switch (fork()) { - case -1: + pid = fork(); + if (pid == -1) panic("fork"); - break; - case 0: + else if (pid == 0) { execl("/init.sh", "init", NULL); panic("exec"); - break; } - if (wait(&status) < 0) - panic("wait"); + if (waitpid(pid, &status, 0) < 0) + panic("waitpid"); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { pretty_message("[+] Tests successful! :-)"); fd = open("/dev/vport1p1", O_WRONLY); |