diff --git a/gtests/net/packetdrill/in_netns.sh b/gtests/net/packetdrill/in_netns.sh index ef1f72c7..31ae29d1 100755 --- a/gtests/net/packetdrill/in_netns.sh +++ b/gtests/net/packetdrill/in_netns.sh @@ -12,15 +12,27 @@ setup() { ip netns add "${NETNS}" ip -netns "${NETNS}" link set lo up if [ -n "${TCPDUMP_OUTPUT}" ]; then - ip netns exec "${NETNS}" tcpdump -i any -s 150 -w "${TCPDUMP_OUTPUT}" & + mkdir -p "$(dirname "${TCPDUMP_OUTPUT}")" + + ip netns exec "${NETNS}" tcpdump -i any -s 150 --immediate-mode --packet-buffered -w "${TCPDUMP_OUTPUT}" & TCPDUMP_PID=$! - sleep 1 # give some time to TCPDump to start + + # give some time to TCPDump to start + for _ in $(seq 10); do + [ -s "${TCPDUMP_OUTPUT}" ] && break + # BusyBox's sleep doesn't support float numbers, just wait 1 sec + if ! sleep 0.1 2>/dev/null; then + sleep 1 + break + fi + done fi } cleanup() { if [ -n "${TCPDUMP_PID}" ]; then - sleep 1 # give some time to TCPDump to process the packets + # give some time to TCPDump to get the last packets + sleep 0.1 2>/dev/null || sleep 1 kill "${TCPDUMP_PID}" wait "${TCPDUMP_PID}" 2>/dev/null || true fi