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
15 #include "monitor/Launcher.h"
16 #include "monitor/Coordinator.h"
17 #include "monitor/ZoneReader.h"
18 #include "util/MessageSystem.h"
22 Launcher::Launcher(char **argv
) : m_argv(argv
) {
26 Launcher::~Launcher() {
30 void Launcher::launch() {
33 ZoneReader
*reader
= new ZoneReader(m_shmReader
);
37 void Launcher::forkTarget() {
40 m_shmReader
= new SHMReader();
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
;
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
);
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()) {
74 preload
+= moduleRoot
+ collectorPath
;
78 setenv("LD_PRELOAD", preload
.c_str(), 1);
81 } // namespace Monitor