X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fkillpid.cc;h=bc9a55941d7b8e5817395cc19a34cea9a0ef1c83;hb=c87f1a554cce74ac1ba3d4e7e9c2a1d2904e4766;hp=e963f4a7eab1e7fa53d979c97cc24ccc26003cf1;hpb=7abcaebdc4c3dd11b779eaef58a7371fb82ae888;p=m6w6%2Flibmemcached diff --git a/libtest/killpid.cc b/libtest/killpid.cc index e963f4a7..bc9a5594 100644 --- a/libtest/killpid.cc +++ b/libtest/killpid.cc @@ -34,58 +34,68 @@ * */ -#include +#include -#include #include #include #include +#include +#include +#include +#include + #include +#include + +using namespace libtest; bool kill_pid(pid_t pid_arg) { - if ((kill(pid_arg, SIGTERM) == -1)) + assert(pid_arg > 0); + if (pid_arg < 1) + { + Error << "Invalid pid:" << pid_arg; + return false; + } + + if ((::kill(pid_arg, SIGTERM) == -1)) { switch (errno) { case EPERM: - perror(__func__); - std::cerr << __func__ << " -> Does someone else have a process running locally for " << int(pid_arg) << "?" << std::endl; + Error << "Does someone else have a process running locally for " << int(pid_arg) << "?"; return false; case ESRCH: - perror(__func__); - std::cerr << "Process " << int(pid_arg) << " not found." << std::endl; + Error << "Process " << int(pid_arg) << " not found."; return false; default: case EINVAL: - perror(__func__); + Error << "kill() " << strerror(errno); return false; } } int status= 0; - pid_t pid= waitpid(pid_arg, &status, 0); - if (pid == -1) + if (waitpid(pid_arg, &status, 0) == -1) { switch (errno) { + // Just means that the server has already gone away case ECHILD: - return true; + { + return true; + } } - std::cerr << std::endl << "Error occured while waitpid(" << strerror(errno) << ") on pid " << int(pid_arg) << std::endl; - return false; - } - if (WIFEXITED(status)) - return true; + Error << "Error occured while waitpid(" << strerror(errno) << ") on pid " << int(pid_arg); - if (WCOREDUMP(status)) - return true; + return false; + } - return false; + return true; }