1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-16 16:23:25 +00:00

Updated linux, so ldconfig always works

This commit is contained in:
Bryan Roe
2019-10-10 13:51:09 -07:00
parent 554d022904
commit 169fabf959
2 changed files with 73 additions and 179 deletions

File diff suppressed because one or more lines are too long

View File

@@ -45,24 +45,10 @@ function getLibInfo(libname)
child = require('child_process').execFile('/bin/sh', ['sh']); child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); }); child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write(ldconfig + " -p | grep '" + libname + ".so.'\nexit\n"); child.stdin.write(ldconfig + " -p | grep '" + libname + ".so.' | tr '\\n' '^' | awk -F^ '{ printf \"[\"; for(i=1;i<=NF;++i) {" + ' split($i, plat, ")"); split(plat[1], plat2, "("); split(plat2[2], ifo, ","); x=split($i, tok, " "); if(tok[1]!="") { printf "%s{\\"lib\\": \\"%s\\", \\"path\\": \\"%s\\", \\"info\\": \\"%s\\"}", (i!=1?",":""), tok[1], tok[x], ifo[2]; }} printf "]"; }\'\nexit\n');
child.waitExit(); child.waitExit();
var v = JSON.parse(child.stdout.str.trim());
var v = [];
var lines = child.stdout.str.split('\n');
for (var i in lines) {
if (lines[i]) {
var info = lines[i].split('=>');
var pth = info[1].trim();
var libinfo = info[0].trim().split(' ');
var lib = libinfo[0];
var plat = libinfo[1].substring(1, libinfo[1].length - 1).split(',');
if (lib.startsWith(libname + '.so.')) {
v.push({ lib: lib, path: pth, info: plat });
}
}
}
return (v); return (v);
} }
@@ -109,19 +95,10 @@ function monitorinfo()
})); }));
} }
} }
else if(process.platform == 'linux') else if (process.platform == 'linux')
{ {
// First thing we need to do, is determine where the X11 libraries are // First thing we need to do, is determine where the X11 libraries are
var askOS = false;
try
{
if (require('user-sessions').isRoot()) { askOS = true; }
}
catch (e)
{ }
if (askOS)
{
// Sufficient access rights to use ldconfig // Sufficient access rights to use ldconfig
var x11info = getLibInfo('libX11'); var x11info = getLibInfo('libX11');
var xtstinfo = getLibInfo('libXtst'); var xtstinfo = getLibInfo('libXtst');
@@ -129,7 +106,7 @@ function monitorinfo()
var xfixesinfo = getLibInfo('libXfixes'); var xfixesinfo = getLibInfo('libXfixes');
var ix; var ix;
for(ix in x11info) for (ix in x11info)
{ {
try try
{ {
@@ -137,7 +114,7 @@ function monitorinfo()
Object.defineProperty(this, 'Location_X11LIB', { value: x11info[ix].path }); Object.defineProperty(this, 'Location_X11LIB', { value: x11info[ix].path });
break; break;
} }
catch(ex) catch (ex)
{ {
} }
} }
@@ -177,102 +154,17 @@ function monitorinfo()
{ {
} }
} }
}
else
{
// Not enough access rights to use ldconfig, so manually search
var fs = require('fs');
var files = fs.readdirSync('/usr/lib');
var files2;
for (var i = 0; i < files.length; ++i)
{
try try
{ {
if (files[i].split('libX11.so.').length > 1 && files[i].split('.').length == 3)
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i]);
Object.defineProperty(this, 'Location_X11LIB', { value: '/usr/lib/' + files[i] });
}
if (files[i].split('libXtst.so.').length > 1 && files[i].split('.').length == 3)
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i]);
Object.defineProperty(this, 'Location_X11TST', { value: '/usr/lib/' + files[i] });
}
if (files[i].split('libXext.so.').length > 1 && files[i].split('.').length == 3)
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i]);
Object.defineProperty(this, 'Location_X11EXT', { value: '/usr/lib/' + files[i] });
}
if (files[i].split('libXfixes.so.').length > 1 && files[i].split('.').length == 3)
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i]);
Object.defineProperty(this, 'Location_X11FIXES', { value: '/usr/lib/' + files[i] });
}
if (files[i].split('-linux-').length > 1)
{
files2 = fs.readdirSync('/usr/lib/' + files[i]);
for (j = 0; j < files2.length; ++j)
{
if (files2[j].split('libX11.so.').length > 1 && files2[j].split('.').length == 3)
{
try
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i] + '/' + files2[j]);
}
catch (xx)
{
break;
}
Object.defineProperty(this, 'Location_X11LIB', { value: '/usr/lib/' + files[i] + '/' + files2[j] });
}
if (files2[j].split('libXtst.so.').length > 1 && files2[j].split('.').length == 3)
{
try
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i] + '/' + files2[j]);
}
catch (xx)
{
break;
}
Object.defineProperty(this, 'Location_X11TST', { value: '/usr/lib/' + files[i] + '/' + files2[j] });
}
if (files2[j].split('libXext.so.').length > 1 && files2[j].split('.').length == 3)
{
try
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i] + '/' + files2[j]);
}
catch (xx)
{
break;
}
Object.defineProperty(this, 'Location_X11EXT', { value: '/usr/lib/' + files[i] + '/' + files2[j] });
}
if (files2[j].split('libXfixes.so.').length > 1 && files2[j].split('.').length == 3)
{
try
{
require('_GenericMarshal').CreateNativeProxy('/usr/lib/' + files[i] + '/' + files2[j]);
}
catch (xx)
{
break;
}
Object.defineProperty(this, 'Location_X11FIXES', { value: '/usr/lib/' + files[i] + '/' + files2[j] });
}
}
}
} catch (ex) { }
}
if (process.env['Location_X11LIB']) { Object.defineProperty(this, 'Location_X11LIB', { value: process.env['Location_X11LIB'] }); } if (process.env['Location_X11LIB']) { Object.defineProperty(this, 'Location_X11LIB', { value: process.env['Location_X11LIB'] }); }
if (process.env['Location_X11TST']) { Object.defineProperty(this, 'Location_X11TST', { value: process.env['Location_X11TST'] }); } if (process.env['Location_X11TST']) { Object.defineProperty(this, 'Location_X11TST', { value: process.env['Location_X11TST'] }); }
if (process.env['Location_X11EXT']) { Object.defineProperty(this, 'Location_X11EXT', { value: process.env['Location_X11EXT'] }); } if (process.env['Location_X11EXT']) { Object.defineProperty(this, 'Location_X11EXT', { value: process.env['Location_X11EXT'] }); }
if (process.env['Location_X11FIXES']) { Object.defineProperty(this, 'Location_X11FIXES', { value: process.env['Location_X11FIXES'] }); } if (process.env['Location_X11FIXES']) { Object.defineProperty(this, 'Location_X11FIXES', { value: process.env['Location_X11FIXES'] }); }
} }
catch(ex)
{
}
} }
if(process.platform == 'freebsd') if(process.platform == 'freebsd')
{ {
@@ -593,4 +485,7 @@ if (process.platform != 'darwin')
module.exports = new monitorinfo(); module.exports = new monitorinfo();
} }
if (process.platform == 'linux')
{
module.exports.getLibInfo = getLibInfo;
}