Module: Elf::Utilities
- Defined in:
- lib/elf/utils/pool.rb,
lib/elf/utils/loader.rb,
lib/elf/utils/offsettable.rb
Defined Under Namespace
Classes: FilePool, OffsetTable
Constant Summary collapse
- @@system_library_path =
nil
Class Method Summary collapse
-
.append_to_library_path(morepaths) ⇒ Object
Convenience function to append an array to the list of system library paths.
-
.environment_library_path ⇒ Object
Return the environment library path.
-
.system_library_path ⇒ Object
Return the system library path to look for libraries, just like the loader would.
Class Method Details
.append_to_library_path(morepaths) ⇒ Object
Convenience function to append an array to the list of system library paths.
This is just used to avoid repeating the same block of code for both the data read from /etc/ld.so.conf and from LD_LIBRARY_PATH environment variable if requested.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elf/utils/loader.rb', line 35 def self.append_to_library_path(morepaths) morepaths.each do |path| begin # Since we can have symlinks and similar issues, try to # canonicalise the paths so that we can expect them to be # truly unique (and thus never pass through the same directory # twice). @@system_library_path << Pathname.new(path).realpath.to_s rescue Errno::ENOENT, Errno::EACCES end end end |
.environment_library_path ⇒ Object
Return the environment library path
We assume the LD_LIBRARY_PATH variable is not going to change between calls.
TODO: systems like Solaris implement further variables like LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64, we should pay attention to those too.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/elf/utils/loader.rb', line 101 def self.environment_library_path return [] if ENV['LD_LIBRARY_PATH'].nil? ENV['LD_LIBRARY_PATH'].split(":").collect do |path| begin Pathname.new(path).realpath.to_s rescue Errno::ENOENT, Errno::EACCES end end.uniq end |
.system_library_path ⇒ Object
Return the system library path to look for libraries, just like the loader would.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/elf/utils/loader.rb', line 50 def self.system_library_path # Try to cache the request since we most likely have multiple # request per process and we don't care if the settings change # between them. if @@system_library_path.nil? @@system_library_path = Array.new # We have to put by default /lib and /usr/lib since they are # implicit in all systems. In particular for Gentoo/Linux # these two are not in the list on x86 systems (but are on # amd64). # # Since LD_LIBRARY_PATH would win over this, but we expect # /etc/ld.so.conf not to, add them here. append_to_library_path(["/lib", "/usr/lib"]) # We might not have the ld.so.conf file, if that's the case # just ignore it. begin # This implements for now the glibc-style loader # configuration; in the future it might be reimplemented to # take into consideration different operating systems. ::File.open("/etc/ld.so.conf") do |ld_so_conf| ld_so_conf.each_line do |line| # Comment lines in the configuration file are prefixed # with the hash character, and the remaining content is # just a single huge list of paths, separated by colon, # comma, space, tabs or newlines. append_to_library_path(line.gsub(/#.*/, '').split(/[:, \t\n]/)) end end rescue Errno::ENOENT end # Make sure the resulting list is uniq to avoid scanning the # same directory multiple times. @@system_library_path.uniq! end return @@system_library_path end |