projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge working tree with build tree.
[awesomized/libmemcached]
/
libtest
/
killpid.cc
diff --git
a/libtest/killpid.cc
b/libtest/killpid.cc
index 8a1543f4892968a05235bce05690815ba9dc5453..cfc9316f34e2b02976060ffb09035077aa07fb5a 100644
(file)
--- a/
libtest/killpid.cc
+++ b/
libtest/killpid.cc
@@
-20,6
+20,7
@@
*/
*/
+#include <config.h>
#include <libtest/common.h>
#include <cstdlib>
#include <libtest/common.h>
#include <cstdlib>
@@
-85,15
+86,43
@@
bool kill_pid(pid_t pid_arg)
return true;
}
return true;
}
-
-pid_t kill_file(const std::string &filename)
+bool check_pid(const std::string &filename)
{
{
- pid_t ret= -1;
+ if (filename.empty())
+ {
+ return false;
+ }
+
FILE *fp;
FILE *fp;
+ if ((fp= fopen(filename.c_str(), "r")))
+ {
+ char pid_buffer[1024];
+
+ char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
+ fclose(fp);
+ if (ptr)
+ {
+ pid_t pid= (pid_t)atoi(pid_buffer);
+ if (pid > 0)
+ {
+ return (::kill(pid, 0) == 0);
+ }
+ }
+ }
+
+ return false;
+}
+
+
+bool kill_file(const std::string &filename)
+{
if (filename.empty())
if (filename.empty())
- return ret;
+ {
+ return true;
+ }
+ FILE *fp;
if ((fp= fopen(filename.c_str(), "r")))
{
char pid_buffer[1024];
if ((fp= fopen(filename.c_str(), "r")))
{
char pid_buffer[1024];
@@
-106,13
+135,15
@@
pid_t kill_file(const std::string &filename)
pid_t pid= (pid_t)atoi(pid_buffer);
if (pid != 0)
{
pid_t pid= (pid_t)atoi(pid_buffer);
if (pid != 0)
{
- kill_pid(pid);
+
bool ret=
kill_pid(pid);
unlink(filename.c_str()); // If this happens we may be dealing with a dead server that left its pid file.
unlink(filename.c_str()); // If this happens we may be dealing with a dead server that left its pid file.
+
+ return ret;
}
}
}
}
}
}
- return
ret
;
+ return
false
;
}
#define STRINGIFY(x) #x
}
#define STRINGIFY(x) #x