Skip to content

Commit

Permalink
Add exec parameter to mstool
Browse files Browse the repository at this point in the history
  • Loading branch information
cuveland committed Jun 14, 2018
1 parent 71fee3d commit b24f764
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/mstool/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ void Parameters::parse_options(int argc, char* argv[]) {
general_add("maximum-number,n", po::value<uint64_t>(&maximum_number),
"set the maximum number of microslices to process (default: "
"unlimited)");
general_add("exec,e", po::value<std::string>(&exec)->value_name("<string>"),
"name of an executable to run after startup");

po::options_description source("Source options");
auto source_add = source.add_options();
Expand Down
1 change: 1 addition & 0 deletions app/mstool/Parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct Parameters {

// general options
uint64_t maximum_number = UINT64_MAX;
std::string exec;

// source selection
uint32_t pattern_generator = 0;
Expand Down
19 changes: 19 additions & 0 deletions app/mstool/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// Copyright 2012-2015 Jan de Cuveland <cmail@cuveland.de>

#include "Application.hpp"
#include "ChildProcessManager.hpp"
#include "Parameters.hpp"
#include "log.hpp"
#include <boost/algorithm/string.hpp>

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[]) {
try {
Parameters par(argc, argv);
Application app(par);
if (!par.exec.empty()) {
start_exec(par.exec, par.output_shm);
ChildProcessManager::get().allow_stop_processes(nullptr);
}
app.run();
} catch (std::exception const& e) {
L_(fatal) << e.what();
Expand Down

0 comments on commit b24f764

Please sign in to comment.