1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-11 13:53:37 +00:00

1. Added 'getProcess' to process-manager for posix platforms with pgrep

2. Fixed parsing bug in user-sessions.getEnvFromPid
3. Updated linux-gnome-helpers to set environment and uid before calling gsettings
This commit is contained in:
Bryan Roe
2019-11-14 15:19:27 -08:00
parent 0333f124ae
commit 895ff6be15
4 changed files with 52 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@@ -51,8 +51,11 @@ function gnome_getDesktopWallpaper(uid)
function gnome_setDesktopWallpaper(uid, filePath)
{
if (!filePath) { filePath = '/dev/null'; }
var child = require('child_process').execFile('/bin/sh', ['sh'], { env: { HOME: require('user-sessions').getHomeFolder(uid) } });
child.stderr.str = ''; child.stderr.on('data', function (c) { });
var v = { HOME: require('user-sessions').getHomeFolder(uid), DBUS_SESSION_BUS_ADDRESS: require('user-sessions').getEnvFromPid(require('process-manager').getProcess('gnome-session')).DBUS_SESSION_BUS_ADDRESS };
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: v });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('gsettings set org.gnome.desktop.background picture-uri file://' + filePath + '\nexit\n');
child.waitExit();

View File

@@ -189,6 +189,33 @@ function processManager() {
break;
}
};
Object.defineProperty(this, '_pgrep', {
value: (function ()
{
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("whereis pgrep | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
})()
});
if(this._pgrep != '')
{
this.getProcess = function getProcess(cmd)
{
var child = require('child_process').execFile(this._pgrep, ['pgrep', cmd]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
return (parseInt(child.stdout.str.trim()));
};
}
}
module.exports = new processManager();

View File

@@ -719,24 +719,21 @@ function UserSessions()
var ret = {};
if (process.platform == 'linux')
{
var ps, psx, v, vs = 0;
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("cat /proc/" + pid + "/environ | tr '\\0' '\\t' |" + ' awk -F"\t" \'{ printf "{"; for(i=1;i<NF;++i) { if(i>1) {printf ",";} x=split($i, tok, "="); printf "\\"%s\\": \\"%s\\"", tok[1], substr($i, 2+length(tok[1])); } printf "}"; }\'');
child.stdin.write('\nexit\n');
child.waitExit();
try
{
ps = require('fs').readFileSync('/proc/' + pid + '/environ');
return (JSON.parse(child.stdout.str.trim()));
}
catch (pse)
catch(ee)
{
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;
}
return ({});
}
}
else if (process.platform == 'freebsd')