X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fkillpid.cc;h=4f8f3370cb1c04a42133f959af3516b7c6c74a89;hb=23dca174eef8d846e3d4402729b57f6ded035e64;hp=aae43bb391bc12729bf82648653ecf4892708627;hpb=47f45992107361ad58c170bdf78fdc92523fab06;p=m6w6%2Flibmemcached diff --git a/libtest/killpid.cc b/libtest/killpid.cc index aae43bb3..4f8f3370 100644 --- a/libtest/killpid.cc +++ b/libtest/killpid.cc @@ -34,7 +34,7 @@ * */ -#include +#include "mem_config.h" #include #include @@ -80,21 +80,34 @@ bool kill_pid(pid_t pid_arg) } } - int status= 0; - if (waitpid(pid_arg, &status, 0) == -1) { - switch (errno) + uint32_t this_wait= 0; + uint32_t timeout= 20; // This number should be high enough for valgrind startup (which is slow) + uint32_t waited; + uint32_t retry; + + for (waited= 0, retry= 4; ; retry++, waited+= this_wait) { - // Just means that the server has already gone away - case ECHILD: + int status= 0; + if (waitpid(pid_arg, &status, WNOHANG) == 0) { - return true; + break; + } + else if (errno == ECHILD) + { + // Server has already gone away + break; + } + else if (waited >= timeout) + { + // Timeout failed + kill(pid_arg, SIGKILL); + break; } - } - - Error << "Error occured while waitpid(" << strerror(errno) << ") on pid " << int(pid_arg); - return false; + this_wait= retry * retry / 3 + 1; + libtest::dream(this_wait, 0); + } } return true;