summaryrefslogtreecommitdiff
path: root/lib/server/ServerControl.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-12-24 00:19:03 +0000
committerChris Wilson <chris+github@qwirx.com>2015-12-24 00:19:03 +0000
commitb52b7d8bbc333a8eeef8fec1f32c191363743d02 (patch)
treed6fce1e7589785d0d28839d1e57b0cd8a6ab5bd6 /lib/server/ServerControl.cpp
parentce103456d969ddc963c1406e42e2a70aedb17b09 (diff)
Add a version of KillServer that takes a pid_file, and reads the PID from it.
Diffstat (limited to 'lib/server/ServerControl.cpp')
-rw-r--r--lib/server/ServerControl.cpp24
1 files changed, 24 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);