Began implementing Marshaller system again.
[aesalon.git] / src / monitor / Launcher.cpp
blob111eee0aa0e6673276ad1e51afb9e946de256ada
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/monitor/Launcher.cpp
8 */
10 #include <iostream>
11 #include <cstdlib>
12 #include <errno.h>
13 #include <cstring>
15 #include "monitor/Launcher.h"
16 #include "monitor/Coordinator.h"
17 #include "monitor/ZoneReader.h"
18 #include "util/MessageSystem.h"
20 namespace Monitor {
22 Launcher::Launcher(char **argv) : m_argv(argv) {
26 Launcher::~Launcher() {
30 void Launcher::launch() {
31 forkTarget();
33 ZoneReader *reader = new ZoneReader(m_shmReader);
34 reader->run();
37 void Launcher::forkTarget() {
38 setupEnvironment();
40 m_shmReader = new SHMReader();
42 m_targetPid = fork();
43 if(m_targetPid == -1) {
44 Message(Fatal, "Could not fork target " << m_argv[0] << ": " << std::strerror(errno));
45 std::cout << "Could not fork . . ." << std::endl;
46 exit(1);
48 else if(m_targetPid == 0) {
49 execvp(m_argv[0], m_argv);
50 Message(Fatal, "Could not launch " << m_argv[0] << ": " << std::strerror(errno));
54 void Launcher::setupEnvironment() {
55 setenv("AesalonSHMName", (Util::StreamAsString() << "/Aesalon-" << getpid()).operator std::string().c_str(), 1);
57 std::vector<std::string> modules;
59 Coordinator::instance()->vault()->get("::modules", modules);
61 std::string preload;
63 if(getenv("LD_PRELOAD")) {
64 Message(Warning, "Replacing current LD_PRELOAD.");
67 for(std::vector<std::string>::iterator i = modules.begin(); i != modules.end(); ++i) {
68 std::string moduleRoot = Coordinator::instance()->vault()->get(*i + ":root");
69 std::string collectorPath = Coordinator::instance()->vault()->get(*i + ":collectorPath");
70 if(collectorPath.length()) {
71 if(preload.length()) {
72 preload += ":";
74 preload += moduleRoot + collectorPath;
78 setenv("LD_PRELOAD", preload.c_str(), 1);
81 } // namespace Monitor