4 #include "ns3/assert.h" 
   15 #include <sys/types.h> 
   29   if (getenv (
"OLDDEP"))
 
   35       dependency.
found = fullname;
 
   36       m_deps.push_back (dependency);
 
   43       dependency.
found = fullname;
 
   44       m_deps.push_back (dependency);
 
   48 std::vector<struct ElfDependencies::Dependency>
 
   51   std::vector<struct Dependency> res;
 
   52   ElfLdd tool (sName, fullname);
 
   53   std::vector<struct Dependency> tm = tool.
GetDeps ();
 
   56        i != tool.
End (); ++i)
 
   58       std::string depname = (*i).required;
 
   60       if (depname == 
"linux-gate.so.1" 
   61           || depname == 
"ld-linux.so.2" 
   62           || depname == 
"ld-linux-x86-64.so.2" 
   63           || depname == 
"/lib/ld-linux.so.2" 
   64           || depname == 
"/lib64/ld-linux-x86-64.so.2" 
   65           || depname == 
"/usr/lib/debug/ld-linux-x86-64.so.2" 
   66           || depname == 
"linux-vdso.so.1")
 
   78 std::vector<struct ElfDependencies::Dependency>
 
   81   NS_LOG_FUNCTION (
this << fullname);
 
   86   std::vector<struct Dependency> dependencies;
 
   88   std::ostringstream tmpFile;
 
   89   tmpFile << 
"/tmp/deps_" << getpid ();
 
   90   std::ostringstream lddCmd;
 
   91   lddCmd << 
"/usr/bin/ldd " 
   93          << 
" > " << tmpFile.str ();
 
   94   int ret = system (lddCmd.str ().c_str ());
 
   97       NS_LOG_ERROR (lddCmd << 
" failed");
 
  101   int depsFd = open (tmpFile.str ().c_str (), O_RDONLY);
 
  104       NS_LOG_ERROR (tmpFile.str () << 
" doesn't exist");
 
  108   std::string lddOutput;
 
  110   ssize_t bytesRead = ::read (depsFd, &c, 1);
 
  111   while (bytesRead == 1)
 
  113       lddOutput.push_back (c);
 
  114       bytesRead = ::read (depsFd, &c, 1);
 
  117   NS_LOG_DEBUG (
"line=" << lddOutput << 
", " << (
int)lddOutput[0]);
 
  119   std::string::size_type cur = 0;
 
  122       std::string::size_type dep_start = lddOutput.find_first_not_of (
" \t", cur);
 
  123       std::string::size_type next_line = lddOutput.find (
"\n", cur);
 
  124       std::string::size_type dep_end = lddOutput.find (
" ", dep_start);
 
  125       std::string::size_type full_start = lddOutput.find_first_of (
">", dep_end);
 
  127       full_start = lddOutput.find_first_not_of (
" \t", full_start + 1);
 
  128       std::string::size_type full_end = lddOutput.find_first_of (
" \n", full_start);
 
  129       NS_LOG_DEBUG (
"dep_start=" << (
int)dep_start << 
" dep_end=" << (
int)dep_end
 
  130                                  << 
" full_start=" << (
int)full_start << 
" full_end=" << (
int)full_end
 
  131                                  << 
" next_line=" << (
int)next_line << 
" cur=" << (
int)cur);
 
  132       if (dep_start != std::string::npos
 
  133           && full_start != std::string::npos
 
  134           && next_line != std::string::npos
 
  135           && dep_start < next_line
 
  136           && dep_end < next_line
 
  137           && full_start <= next_line
 
  138           && full_start > dep_start)
 
  140           std::string depname = lddOutput.substr (dep_start, dep_end - dep_start);
 
  141           std::string fulldepname = lddOutput.substr (full_start, full_end - (full_start));
 
  142           NS_LOG_DEBUG (depname << 
"->" << fulldepname);
 
  143           if (depname == 
"linux-gate.so.1" 
  144               || depname == 
"ld-linux.so.2" 
  145               || depname == 
"ld-linux-x86-64.so.2" 
  146               || depname == 
"/lib/ld-linux.so.2" 
  147               || depname == 
"/lib64/ld-linux-x86-64.so.2" 
  148               || depname == 
"/usr/lib/debug/ld-linux-x86-64.so.2" 
  149               || depname == 
"linux-vdso.so.1")
 
  157               dependency.
found = fulldepname;
 
  158               dependencies.push_back (dependency);
 
  163           if (next_line == std::string::npos)
 
  169               full_start = next_line - 1;
 
  173       cur = lddOutput.find_first_of (
"\n", full_start);
 
  174       if (cur != std::string::npos)
 
  188 std::list<std::string>
 
  191   NS_LOG_FUNCTION (
this << input << sep);
 
  192   std::list<std::string> retval;
 
  193   std::string::size_type cur = 0, next;
 
  196       next = input.find (sep, cur);
 
  202       else if (next == std::string::npos)
 
  204           if (input.size () != cur)
 
  206               retval.push_back (input.substr (cur, input.size () - cur));
 
  210       retval.push_back (input.substr (cur, next - cur));
 
  216 std::list<std::string>
 
  219   NS_LOG_FUNCTION (
this);
 
  220   std::list<std::string> directories;
 
  221   char *ldLibraryPath = getenv (
"LD_LIBRARY_PATH");
 
  222   if (ldLibraryPath != 0)
 
  224       std::list<std::string> tmp = 
Split (ldLibraryPath, 
":");
 
  225       directories.insert (directories.end (),
 
  229   char *path = getenv (
"PATH");
 
  232       std::list<std::string> tmp = 
Split (path, 
":");
 
  233       directories.insert (directories.end (),
 
  237   directories.push_back (
"/lib");
 
  238   directories.push_back (
"/usr/lib");
 
  239   directories.push_back (
".");
 
  248   int retval = ::stat (filename.c_str (), &st);
 
  255   NS_LOG_FUNCTION (
this << filename);
 
  258       *fullname = filename;
 
  259       NS_LOG_DEBUG (
"Found: " << filename << 
" as " << *fullname);
 
  263   for (std::list<std::string>::const_iterator i = dirs.begin (); i != dirs.end (); i++)
 
  265       if (
Exists (*i + 
"/" + filename))
 
  267           *fullname = *i + 
"/" + filename;
 
  268           NS_LOG_DEBUG (
"Found: " << filename << 
" as " << *fullname);