processLoad() linux fix * (linux)

This commit is contained in:
Sebastian Hildebrandt 2024-08-21 19:30:33 +02:00
parent 6ffb79aca3
commit 642312e166

View File

@ -1005,7 +1005,7 @@ function processLoad(proc, callback) {
let processes = processesString.split('|'); let processes = processesString.split('|');
let result = []; let result = [];
const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc); const procSanitized = util.isPrototypePolluted() ? '' : (util.sanitizeShellString(proc) || '*');
// from here new // from here new
// let result = { // let result = {
@ -1149,12 +1149,14 @@ function processLoad(proc, callback) {
}); });
return found; return found;
}); });
lines.shift();
lines.forEach(function (line) { lines.forEach(function (line) {
let data = line.trim().replace(/ +/g, ' ').split(' '); let data = line.trim().replace(/ +/g, ' ').split(' ');
if (data.length > 4) { if (data.length > 4) {
const linuxName = data[4].indexOf('/') >= 0 ? data[4].substring(0, data[4].indexOf('/') - 1) : data[4];
const name = _linux ? (linuxName) : data[4].substring(data[4].lastIndexOf('/') + 1);
procStats.push({ procStats.push({
name: data[4].substring(data[4].lastIndexOf('/') + 1), name,
pid: parseInt(data[0]) || 0, pid: parseInt(data[0]) || 0,
ppid: parseInt(data[1]) || 0, ppid: parseInt(data[1]) || 0,
cpu: parseFloat(data[2].replace(',', '.')), cpu: parseFloat(data[2].replace(',', '.')),
@ -1166,7 +1168,7 @@ function processLoad(proc, callback) {
procStats.forEach(function (item) { procStats.forEach(function (item) {
let listPos = -1; let listPos = -1;
let inList = false; let inList = false;
let name = ''; let name = item.name;
for (let j = 0; j < result.length; j++) { for (let j = 0; j < result.length; j++) {
if (item.name.toLowerCase().indexOf(result[j].proc.toLowerCase()) >= 0) { if (item.name.toLowerCase().indexOf(result[j].proc.toLowerCase()) >= 0) {
listPos = j; listPos = j;
@ -1181,13 +1183,15 @@ function processLoad(proc, callback) {
}); });
if ((processesString === '*') || inList) { if ((processesString === '*') || inList) {
if (listPos < 0) { if (listPos < 0) {
result.push({ if (name) {
proc: name, result.push({
pid: item.pid, proc: name,
pids: [item.pid], pid: item.pid,
cpu: item.cpu, pids: [item.pid],
mem: item.mem cpu: item.cpu,
}); mem: item.mem
});
}
} else { } else {
if (item.ppid < 10) { if (item.ppid < 10) {
result[listPos].pid = item.pid; result[listPos].pid = item.pid;