Files
MapLibreParticleLab/test/fixtures/util.cpp
Thiago Marcos P. Santos 124b49562d Get rid of printf and cout by using Log::*
Use our logging system that will route the message accordingly on
the target platform.

Fixes #613
2015-03-12 14:19:32 +02:00

38 lines
944 B
C++

#include "util.hpp"
#include <mbgl/platform/log.hpp>
#include <csignal>
namespace mbgl {
namespace test {
pid_t startServer(const char *executable) {
const std::string parent_pid = std::to_string(getpid());
pid_t pid = fork();
if (pid < 0) {
throw std::runtime_error("Cannot create server process");
} else if (pid == 0) {
char *args[] = { const_cast<char *>(executable),
const_cast<char *>(parent_pid.c_str()),
nullptr };
int ret = execv(executable, args);
// This call should not return. In case execve failed, we exit anyway.
if (ret < 0) {
Log::Error(Event::Setup, "failed to start server: %s", strerror(errno));
}
exit(0);
} else {
// Wait until the server process sends SIGCONT.
raise(SIGSTOP);
}
return pid;
}
void stopServer(pid_t pid) {
kill(pid, SIGTERM);
}
}
}