I've noticed that sendfile_test is flaky using this simple shell script:
#!/bin/sh i=1 while true; do echo -n "Run: $i, " if /usr/tests/lib/libc/sys/sendfile_test hdtr_positive_v6 >/dev/null 2>&1; then echo success else echo failed exit fi i=$((i + 1)) done
On my system it fail before 3000 runs with this error:
Generating a random port with seed=2 Port range lower bound: 10000 Port range upper bound: 65535 Random port generated: 21793 Will try to bind socket to host='127.0.0.1', address_family=2, socket_type=1 failed: /FreeBSD/lib/libc/tests/sys/sendfile_test.c:198: error != 0: bind failed: Address already in use
So I've implemented the code with comment 'XXX: use linear probing to find a free port'.