Get an absolute path for traces in order to bypass possible change-dir operation
authorEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Mon, 27 Nov 2017 03:14:16 +0000 (04:14 +0100)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Mon, 27 Nov 2017 03:14:16 +0000 (04:14 +0100)
example/diameter/launcher/main.cpp

index 6f2a653..599e4fe 100644 (file)
 // Process
 #include <Launcher.hpp>
 
 // Process
 #include <Launcher.hpp>
 
+// To calculate the current working directory and get an absolute path for traces:
+#include <limits.h>
+#include <unistd.h>
+
 
 int main(int argc, const char** argv) {
   anna::Logger::setLevel(anna::Logger::Warning);
 
 int main(int argc, const char** argv) {
   anna::Logger::setLevel(anna::Logger::Warning);
-  anna::Logger::initialize("launcher", new TraceWriter("launcher.trace", 2048000));
+
+  // Current working directory and absolute trace path file:
+  char c_exe[ PATH_MAX ];
+  ssize_t count = readlink( "/proc/self/exe", c_exe, PATH_MAX );
+  std::string exe(c_exe, (count > 0) ? count : 0 );
+  std::string cwd = exe.substr(0, exe.find_last_of("/"));
+  std::string trace_file = cwd + "/launcher.trace";
+
+  anna::Logger::initialize("launcher", new TraceWriter(trace_file, 2048000));
   anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
   anna::time::functions::setControlPoint(); // start control point (application lifetime)
   Launcher app;
   anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
   anna::time::functions::setControlPoint(); // start control point (application lifetime)
   Launcher app;