mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-17 16:53:13 +00:00
update to getEnvFromPid() for freebsd
This commit is contained in:
@@ -596,23 +596,40 @@ function UserSessions()
|
|||||||
this.getEnvFromPid = function getEnvFromPid(pid)
|
this.getEnvFromPid = function getEnvFromPid(pid)
|
||||||
{
|
{
|
||||||
var ret = {};
|
var ret = {};
|
||||||
var ps, psx, v, vs = 0;
|
if (process.platform == 'linux')
|
||||||
try
|
|
||||||
{
|
{
|
||||||
ps = require('fs').readFileSync('/proc/' + pid + '/environ');
|
var ps, psx, v, vs = 0;
|
||||||
}
|
try
|
||||||
catch(pse)
|
|
||||||
{
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (psx = 0; psx < ps.length; ++psx)
|
|
||||||
{
|
|
||||||
if (ps[psx] == 0)
|
|
||||||
{
|
{
|
||||||
v = ps.slice(vs, psx).toString().split('=');
|
ps = require('fs').readFileSync('/proc/' + pid + '/environ');
|
||||||
ret[v[0]] = v[1];
|
}
|
||||||
vs = psx + 1;
|
catch (pse)
|
||||||
|
{
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (psx = 0; psx < ps.length; ++psx)
|
||||||
|
{
|
||||||
|
if (ps[psx] == 0)
|
||||||
|
{
|
||||||
|
v = ps.slice(vs, psx).toString().split('=');
|
||||||
|
ret[v[0]] = v[1];
|
||||||
|
vs = psx + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (process.platform == 'freebsd')
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("procstat -e " + pid + " | grep " + pid + " | awk '{ $1=\"\"; $2=\"\"; print $0 }' | tr \"\\ \" \"\\n\" | awk -F= '{ if($1==\"\") { print $0 }}'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
var env;
|
||||||
|
var tokens = child.stdout.str.trim().split('\n');
|
||||||
|
for(var i in tokens)
|
||||||
|
{
|
||||||
|
env = tokens[i].split('=');
|
||||||
|
ret[env[0]] = env[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|||||||
Reference in New Issue
Block a user