luci-base: Add option to check linked libraries 678/head
authorDaniel Dickinson <openwrt@daniel.thecshore.com>
Fri, 25 Mar 2016 07:04:18 +0000 (03:04 -0400)
committerDaniel Dickinson <openwrt@daniel.thecshore.com>
Fri, 25 Mar 2016 07:04:25 +0000 (03:04 -0400)
Some packages have different variants that have different
capabilities depending on which libraries against which
they are linked.  Add a function to check which library a
binary links against in order to determine available
functionality.

Signed-off-by: Daniel Dickinson <openwrt@daniel.thecshore.com>
modules/luci-base/luasrc/util.lua

index 2956aad..d614a6c 100644 (file)
@@ -636,6 +636,23 @@ function libpath()
        return require "nixio.fs".dirname(ldebug.__file__)
 end
 
+function checklib(fullpathexe, wantedlib)
+       local fs = require "nixio.fs"
+       local haveldd = fs.access('/usr/bin/ldd')
+       if not haveldd then
+               return -1
+       end
+       local libs = exec("/usr/bin/ldd " .. fullpathexe)
+       if not libs then
+               return 0
+       end
+       for k, v in ipairs(split(libs)) do
+               if v:find(wantedlib) then
+                       return 1
+               end
+       end
+       return 0
+end
 
 --
 -- Coroutine safe xpcall and pcall versions modified for Luci