2 Aesalon, a tool to visualize a program's behaviour at run-time.
3 Copyright (C) 2010, Aesalon Development Team.
5 Aesalon is distributed under the terms of the GNU GPLv3. For more
6 licensing information, see the file LICENSE included with the distribution.
8 @file monitor/src/program/Launcher.cpp
19 #include "program/Launcher.h"
21 #include "common/AssertionException.h"
22 #include "common/NYIException.h"
23 #include "Coordinator.h"
24 #include "common/StringTo.h"
25 #include "common/PathSanitizer.h"
26 #include "common/StreamAsString.h"
31 Launcher::Launcher(char **argv
) : m_argv(argv
) {
35 Launcher::~Launcher() {
39 pid_t
Launcher::forkTarget() {
43 if(m_targetPid
== -1) {
44 std::cout
<< "Could not fork . . ." << std::endl
;
47 else if(m_targetPid
== 0) {
48 execvp(m_argv
[0], m_argv
);
49 std::cout
<< m_argv
[0] << ": " << strerror(errno
) << std::endl
;
56 void Launcher::waitForChild() {
58 waitid(P_PID
, m_targetPid
, &sinfo
, WEXITED
);
59 if(sinfo
.si_code
== CLD_DUMPED
|| sinfo
.si_code
== CLD_KILLED
)
60 Coordinator::instance()->setReturnValue(128 + sinfo
.si_status
);
61 else Coordinator::instance()->setReturnValue(sinfo
.si_status
);
64 void Launcher::setupEnvironment() {
65 /*setenv("AC___conductorFd", (Common::StreamAsString() << m_controllerFds[1]).operator std::string().c_str(), 1);*/
67 setenv("AesalonSHMName", (Common::StreamAsString() << "/Aesalon-" << getpid()).operator std::string().c_str(), 1);
69 std::vector
<std::string
> modules
;
71 Coordinator::instance()->vault()->get("::modules", modules
);
75 if(getenv("LD_PRELOAD")) {
76 preload
= getenv("LD_PRELOAD");
80 for(std::vector
<std::string
>::iterator i
= modules
.begin(); i
!= modules
.end(); ++i
) {
81 std::string moduleRoot
= Coordinator::instance()->vault()->get(*i
+ ":root");
82 std::string collectorPath
= Coordinator::instance()->vault()->get(*i
+ ":collectorPath");
83 if(collectorPath
.length()) {
84 if(preload
.length()) {
87 preload
+= moduleRoot
+ collectorPath
;
91 setenv("LD_PRELOAD", preload
.c_str(), 1);
94 } // namespace Program
95 } // namespace Monitor