4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Process.h"
14 : undef_wrapper_ ("nothing"),
15 undefs_(undef_wrapper_
.imports()),
20 libs_
= new Library
*[max_libs_
];
23 SO_Group::~SO_Group ()
25 for (int i
= 0; i
< num_libs_
; delete libs_
[i
++])
34 SO_Group::add_executable (const char * path
)
37 ACE_Process_Options opts
;
42 opts
.set_handles (ACE_STDIN
,pipe
[1]);
44 int result
= opts
.command_line ("ldd %s",path
);
45 // Prevent compiler warning about "unused variable" if ACE_ASSERT is
47 ACE_UNUSED_ARG (result
);
48 ACE_ASSERT (result
== 0);
51 if (ACE_OS::close(pipe
[1]) == -1)
52 ACE_DEBUG ((LM_DEBUG
, "%p\n", "close"));
53 opts
.release_handles();
55 const int max_line_length
= 1000;
56 char line
[max_line_length
];
60 ACE_OS::memset (line
,0,max_line_length
);
65 // Skip initial whitespace.
66 while ((nread
= ACE_OS::read (pipe
[0], line
,1)) == 1
67 && (*line
== ' ' || *line
== '\t'))
77 // read the library name
80 while ((nread
= ACE_OS::read (pipe
[0], line
+ len
, 1)) == 1
81 && (line
[len
] != ' '))
83 if (! bogus
&& ++len
== max_line_length
)
90 if (nread
!= 1 || bogus
)
96 char * dot
= ACE_OS::strchr (line
,'.');
103 char * libname
= line
+ 3; // skip over "lib"
105 // check to see if this is a new library
108 for (int i
= 0; !found
&& i
< num_libs_
; ++i
)
110 found
= (libs_
[i
]->name() == libname
);
115 Library
*nlib
= new Library(libname
);
116 ACE_OS::memset (line
,0,max_line_length
);
119 if (ACE_OS::read (pipe
[0], line
, 3) != 3)
127 while ((nread
= ACE_OS::read(pipe
[0],line
+ len
,1)) == 1 &&
130 if (! bogus
&& ++len
== max_line_length
)
137 if (nread
!= 1 || bogus
)
143 nlib
->set_path (line
);
144 libs_
[num_libs_
++] = nlib
;
145 ACE_ASSERT (num_libs_
< max_libs_
); // grow max libs?
148 // Skip the rest of the line.
149 while ((nread
= ACE_OS::read (pipe
[0], line
, 1)) == 1
161 ACE_OS::close (pipe
[0]);
163 undef_wrapper_
.add_source(path
,1);
164 // now do the ldd, iterate over the results to add new libs, etc.
170 for (int passcount
= 0; undefs_
.modified (); ++passcount
)
172 ACE_DEBUG ((LM_DEBUG
,
173 "pass %d, undef count = %d\n",
177 for (int i
= 0; i
< num_libs_
; libs_
[i
++]->resolve (undefs_
))
185 SO_Group::write_results ()
187 for (int i
= 0; i
< num_libs_
; libs_
[i
++]->write_export_list (1))
194 SO_Group::load_modules ()
196 for (int i
= 0; i
< num_libs_
; libs_
[i
++]->load_modules ())
203 SO_Group::list_libs ()
205 ACE_DEBUG ((LM_DEBUG
, "Libs subject to analysis:\n"));
207 for (int i
= 0; i
< num_libs_
; ++i
)
209 if (libs_
[i
]->has_modules ())
211 ACE_DEBUG ((LM_DEBUG
, " %s\n", libs_
[i
]->name ().c_str ()));