1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-09 03:53:26 +00:00

Updated consoleUid() and getXInfo() for Amazon EC2 (Amazon Linux)

This commit is contained in:
Bryan Roe
2021-12-11 23:45:59 -08:00
parent 235fcbd3ba
commit 4f43c68b56
3 changed files with 60 additions and 5 deletions

View File

@@ -516,13 +516,27 @@ function monitorinfo()
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("ps " + (process.platform == 'freebsd'?"-ax ":"") + "-e -o user" + (process.platform=='linux'?":999":"") + " -o tty -o command | grep X | awk '{ split($0, a, \"-auth\"); split(a[2], b, \" \"); if($1==\"" + uname + "\" && b[1]!=\"\") { printf \"%s,%s,%s\",$1,$2,b[1] } }'\nexit\n");
child.stdin.write("ps " + "-e -o user" + (":999") + " -o tty -o command | grep X | ");
child.stdin.write("awk '{ ");
child.stdin.write(' display="";');
child.stdin.write(' if($4~/^:/)');
child.stdin.write(' {');
child.stdin.write(' display=$4;');
child.stdin.write(' }');
child.stdin.write(' split($0, a, "-auth");');
child.stdin.write(' split(a[2], b, " ");');
child.stdin.write(' if($1=="' + uname + '" && b[1]!="")');
child.stdin.write(" {");
child.stdin.write(" printf \"%s,%s,%s,%s\",$1,$2,b[1],display;");
child.stdin.write(" }");
child.stdin.write(" }'\nexit\n");
child.waitExit();
var tokens = child.stdout.str.trim().split(',');
console.info1(JSON.stringify(tokens));
if (tokens.length == 3)
if (tokens.length == 4)
{
ret = { tty: tokens[1], xauthority: tokens[2], exportEnv: exportEnv };
ret = { tty: tokens[1], xauthority: tokens[2], display: tokens[3], exportEnv: exportEnv };
console.info1('ret => ' + JSON.stringify(ret));
}
@@ -754,6 +768,7 @@ function monitorinfo()
{
if (ps[psx] == 0)
{
if (psx == 0) { continue; }
v = ps.slice(vs, psx).toString().split('=');
if (v[0] == 'DISPLAY')
{