X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fkillpid.cc;h=bc9a55941d7b8e5817395cc19a34cea9a0ef1c83;hb=23d5278248d8f3deff5903d17b6d55cc503ef3a9;hp=ca8a659b80b798580e0725499f81a51090b8aaf2;hpb=12a07e58df95bb8dbe167e4157b29c910177ade8;p=m6w6%2Flibmemcached diff --git a/libtest/killpid.cc b/libtest/killpid.cc index ca8a659b..bc9a5594 100644 --- a/libtest/killpid.cc +++ b/libtest/killpid.cc @@ -34,61 +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 (pid_arg <= 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; }