Skip to content

Commit

Permalink
Add exec parameter to flib_server
Browse files Browse the repository at this point in the history
  • Loading branch information
cuveland committed Jun 14, 2018
1 parent 4973d9f commit 71fee3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/flib_server/flib_server.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2015 Dirk Hutter

#include "ChildProcessManager.hpp"
#include "log.hpp"
#include "parameters.hpp"
#include "shm_device_server.hpp"
#include <boost/algorithm/string.hpp>
#include <csignal>

namespace {
Expand All @@ -11,6 +13,19 @@ volatile std::sig_atomic_t signal_status = 0;

static void signal_handler(int sig) { signal_status = sig; }

void start_exec(const std::string executable,
const std::string shared_memory_identifier) {
assert(!executable.empty());
ChildProcess cp = ChildProcess();
boost::split(cp.arg, executable, boost::is_any_of(" \t"),
boost::token_compress_on);
cp.path = cp.arg.at(0);
for (auto& arg : cp.arg) {
boost::replace_all(arg, "%s", shared_memory_identifier);
}
ChildProcessManager::get().start_process(cp);
}

int main(int argc, char* argv[]) {

std::signal(SIGINT, signal_handler);
Expand All @@ -35,6 +50,10 @@ int main(int argc, char* argv[]) {
flib_shm_device_server server(
flib.get(), par.shm(), par.data_buffer_size_exp(),
par.desc_buffer_size_exp(), par.etcd(), &signal_status);
if (!par.exec().empty()) {
start_exec(par.exec(), par.shm());
ChildProcessManager::get().allow_stop_processes(nullptr);
}
server.run();

} catch (std::exception const& e) {
Expand Down
4 changes: 4 additions & 0 deletions app/flib_server/parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class parameters {
size_t data_buffer_size_exp() { return _data_buffer_size_exp; }
size_t desc_buffer_size_exp() { return _desc_buffer_size_exp; }
etcd_config_t etcd() const { return _etcd; }
std::string exec() const { return _exec; }

std::string print_buffer_info() {
std::stringstream ss;
Expand Down Expand Up @@ -128,6 +129,8 @@ class parameters {
"where to find the etcd server");
config_add("etcd-path", po::value<std::string>(&_etcd.path),
"base path for this instance, leave empty to not use etcd");
config_add("exec,e", po::value<std::string>(&_exec)->value_name("<string>"),
"name of an executable to run after startup");

po::options_description cmdline_options("Allowed options");
cmdline_options.add(generic).add(config);
Expand Down Expand Up @@ -188,4 +191,5 @@ class parameters {
size_t _data_buffer_size_exp;
size_t _desc_buffer_size_exp;
etcd_config_t _etcd;
std::string _exec;
};

0 comments on commit 71fee3d

Please sign in to comment.