diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-12-24 00:19:03 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-12-24 00:19:03 +0000 |
commit | b52b7d8bbc333a8eeef8fec1f32c191363743d02 (patch) | |
tree | d6fce1e7589785d0d28839d1e57b0cd8a6ab5bd6 /lib | |
parent | ce103456d969ddc963c1406e42e2a70aedb17b09 (diff) |
Add a version of KillServer that takes a pid_file, and reads the PID from it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/server/ServerControl.cpp | 24 | ||||
-rw-r--r-- | lib/server/ServerControl.h | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index 47b1cc5f..d4d44c70 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -227,6 +227,30 @@ bool KillServer(int pid, bool WaitForProcess) return !ServerIsAlive(pid); } +bool KillServer(std::string pid_file, bool WaitForProcess) +{ + FileStream fs(pid_file); + IOStreamGetLine getline(fs); + std::string line = getline.GetLine(); + int pid = atoi(line.c_str()); + bool status = KillServer(pid, WaitForProcess); + TEST_EQUAL_LINE(true, status, std::string("kill(") + pid_file + ")"); + +#ifdef WIN32 + if(WaitForProcess) + { + int unlink_result = unlink(pid_file.c_str()); + TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file); + if(unlink_result != 0) + { + return false; + } + } +#endif + + return status; +} + int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file) { TEST_THAT_OR(current_pid == 0, return 0); diff --git a/lib/server/ServerControl.h b/lib/server/ServerControl.h index 430f03a3..be2464c1 100644 --- a/lib/server/ServerControl.h +++ b/lib/server/ServerControl.h @@ -5,6 +5,7 @@ bool HUPServer(int pid); bool KillServer(int pid, bool WaitForProcess = false); +bool KillServer(std::string pid_file, bool WaitForProcess = false); int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file); bool StopDaemon(int current_pid, const std::string& pid_file, const std::string& memleaks_file, bool wait_for_process); |