projects
/
m6w6
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge in util library.
[m6w6/libmemcached]
/
libtest
/
killpid.cc
diff --git
a/libtest/killpid.cc
b/libtest/killpid.cc
index ca8a659b80b798580e0725499f81a51090b8aaf2..bc9a55941d7b8e5817395cc19a34cea9a0ef1c83 100644
(file)
--- a/
libtest/killpid.cc
+++ b/
libtest/killpid.cc
@@
-34,61
+34,68
@@
*
*/
*
*/
-#include <
config
.h>
+#include <
libtest/common
.h>
-#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <iostream>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <libtest/killpid.h>
#include <libtest/killpid.h>
+#include <libtest/stream.h>
+
+using namespace libtest;
bool kill_pid(pid_t pid_arg)
{
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;
return false;
+ }
if ((::kill(pid_arg, SIGTERM) == -1))
{
switch (errno)
{
case EPERM:
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:
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:
return false;
default:
case EINVAL:
-
perror(__func__
);
+
Error << "kill() " << strerror(errno
);
return false;
}
}
int status= 0;
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)
{
{
switch (errno)
{
+ // Just means that the server has already gone away
case ECHILD:
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
fals
e;
+ return
tru
e;
}
}