11
|
1 |
diff -r 275f1c8a7f1d model/dlm-loader-factory.cc
|
|
2 |
--- a/model/dlm-loader-factory.cc Thu Mar 29 13:54:58 2012 +0900
|
|
3 |
+++ b/model/dlm-loader-factory.cc Thu Mar 29 13:55:03 2012 +0900
|
1
|
4 |
@@ -3,6 +3,7 @@
|
|
5 |
#include "ns3/fatal-error.h"
|
|
6 |
#include <list>
|
|
7 |
#include <dlfcn.h>
|
|
8 |
+#include <sys/stat.h>
|
|
9 |
|
|
10 |
NS_LOG_COMPONENT_DEFINE ("DlmLoaderFactory");
|
|
11 |
|
|
12 |
@@ -34,6 +35,10 @@
|
|
13 |
virtual void Unload (void *module);
|
|
14 |
virtual void *Lookup (void *module, std::string symbol);
|
|
15 |
private:
|
|
16 |
+ bool SearchFile (std::string filename, std::string *fullname) const;
|
|
17 |
+ std::list<std::string> GetSearchDirectories (void) const;
|
|
18 |
+ std::list<std::string> Split (std::string input, std::string sep) const;
|
|
19 |
+ bool Exists (std::string filename) const;
|
|
20 |
Lmid_t m_lmid;
|
|
21 |
std::list<void *> m_loaded;
|
|
22 |
};
|
|
23 |
@@ -83,11 +88,98 @@
|
|
24 |
::dlclose (*i);
|
|
25 |
}
|
|
26 |
}
|
|
27 |
+std::list<std::string>
|
|
28 |
+DlmLoader::Split (std::string input, std::string sep) const
|
|
29 |
+{
|
|
30 |
+ NS_LOG_FUNCTION (this << input << sep);
|
|
31 |
+ std::list<std::string> retval;
|
|
32 |
+ std::string::size_type cur = 0, next;
|
|
33 |
+ while (true)
|
|
34 |
+ {
|
|
35 |
+ next = input.find (sep, cur);
|
|
36 |
+ if (next == cur)
|
|
37 |
+ {
|
|
38 |
+ cur ++;
|
|
39 |
+ continue;
|
|
40 |
+ }
|
|
41 |
+ else if (next == std::string::npos)
|
|
42 |
+ {
|
|
43 |
+ if (input.size () != cur)
|
|
44 |
+ {
|
|
45 |
+ retval.push_back (input.substr (cur, input.size () - cur));
|
|
46 |
+ }
|
|
47 |
+ break;
|
|
48 |
+ }
|
|
49 |
+ retval.push_back (input.substr (cur, next - cur));
|
|
50 |
+ cur = next + 1;
|
|
51 |
+ }
|
|
52 |
+ return retval;
|
|
53 |
+}
|
|
54 |
+std::list<std::string>
|
|
55 |
+DlmLoader::GetSearchDirectories (void) const
|
|
56 |
+{
|
|
57 |
+ NS_LOG_FUNCTION (this);
|
|
58 |
+ std::list<std::string> directories;
|
|
59 |
+ char *ldLibraryPath = getenv ("LD_LIBRARY_PATH");
|
|
60 |
+ if (ldLibraryPath != 0)
|
|
61 |
+ {
|
|
62 |
+ std::list<std::string> tmp = Split (ldLibraryPath, ":");
|
|
63 |
+ directories.insert (directories.end (),
|
|
64 |
+ tmp.begin (),
|
|
65 |
+ tmp.end ());
|
|
66 |
+ }
|
|
67 |
+ char *path = getenv ("PATH");
|
|
68 |
+ if (path != 0)
|
|
69 |
+ {
|
|
70 |
+ std::list<std::string> tmp = Split (path, ":");
|
|
71 |
+ directories.insert (directories.end (),
|
|
72 |
+ tmp.begin (),
|
|
73 |
+ tmp.end ());
|
|
74 |
+ }
|
|
75 |
+ directories.push_back ("/lib");
|
|
76 |
+ directories.push_back ("/usr/lib");
|
|
77 |
+ directories.push_back (".");
|
|
78 |
+ return directories;
|
|
79 |
+}
|
|
80 |
+bool
|
|
81 |
+DlmLoader::Exists (std::string filename) const
|
|
82 |
+{
|
|
83 |
+ //NS_LOG_FUNCTION (this << filename);
|
|
84 |
+ struct stat st;
|
|
85 |
+ int retval = ::stat (filename.c_str (), &st);
|
|
86 |
+ return retval == 0;
|
|
87 |
+}
|
|
88 |
+bool
|
|
89 |
+DlmLoader::SearchFile (std::string filename, std::string *fullname) const
|
|
90 |
+{
|
|
91 |
+ NS_LOG_FUNCTION (this << filename);
|
|
92 |
+ if (Exists (filename))
|
|
93 |
+ {
|
|
94 |
+ *fullname = filename;
|
|
95 |
+ NS_LOG_DEBUG ("Found: " << filename << " as " << *fullname);
|
|
96 |
+ return true;
|
|
97 |
+ }
|
|
98 |
+ std::list<std::string> dirs = GetSearchDirectories ();
|
|
99 |
+ for (std::list<std::string>::const_iterator i = dirs.begin (); i != dirs.end (); i++)
|
|
100 |
+ {
|
|
101 |
+ if (Exists (*i + "/" + filename))
|
|
102 |
+ {
|
|
103 |
+ *fullname = *i + "/" + filename;
|
|
104 |
+ NS_LOG_DEBUG ("Found: " << filename << " as " << *fullname);
|
|
105 |
+ return true;
|
|
106 |
+ }
|
|
107 |
+ }
|
|
108 |
+ return false;
|
|
109 |
+}
|
|
110 |
void *
|
|
111 |
DlmLoader::Load (std::string filename, int flag)
|
|
112 |
{
|
|
113 |
+ std::string fullname;
|
|
114 |
+ bool found;
|
|
115 |
NS_LOG_FUNCTION (this << filename << flag);
|
|
116 |
- void *module = dlmopen (m_lmid, filename.c_str (), flag);
|
|
117 |
+ found = SearchFile (filename, &fullname);
|
|
118 |
+ NS_ASSERT (found);
|
|
119 |
+ void *module = dlmopen (m_lmid, fullname.c_str (), flag);
|
|
120 |
m_loaded.push_back (module);
|
|
121 |
return module;
|
|
122 |
}
|
11
|
123 |
diff -r 275f1c8a7f1d wscript
|
|
124 |
--- a/wscript Thu Mar 29 13:54:58 2012 +0900
|
|
125 |
+++ b/wscript Thu Mar 29 13:55:03 2012 +0900
|
|
126 |
@@ -36,6 +36,8 @@
|
|
127 |
conf.check(header_name='dirent.h', define_name='HAVE_DIRENT_H', mandatory=False)
|
1
|
128 |
|
|
129 |
conf.env.append_value('LINKFLAGS', '-pthread')
|
|
130 |
+ conf.env.append_value('LINKFLAGS', '-Wl,--dynamic-linker=' +
|
|
131 |
+ os.path.abspath ('../build/lib/ldso'))
|
|
132 |
conf.check (lib='dl', mandatory = True)
|
11
|
133 |
|
|
134 |
vg_h = conf.check(header_name='valgrind/valgrind.h', mandatory=False)
|