From be0a5c66af9a516b98070a55a8e671e990aa9228 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 11 Feb 2021 21:29:52 +0100 Subject: [PATCH] processes() fixed issue truncated params --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/processes.js | 50 ++++++++++++++++++++++++----------------------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e42ba20..cf7bee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 5.2.5 | 2020-02-11 | `processes()` fixed truncated params (linux) | | 5.2.4 | 2020-02-11 | `currentLoad()` fixed issue | | 5.2.3 | 2020-02-11 | `diskLayout()` added USB drives (mac OS) | | 5.2.2 | 2020-02-11 | code cleanup, updated docs | diff --git a/docs/history.html b/docs/history.html index cd5a271..75bf404 100644 --- a/docs/history.html +++ b/docs/history.html @@ -56,6 +56,11 @@ + + 5.2.5 + 2020-02-11 + processes() fix truncated params (linux) + 5.2.4 2020-02-11 diff --git a/docs/index.html b/docs/index.html index e3b52ab..01027be 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.2.4
+
New Version: 5.2.5
diff --git a/lib/processes.js b/lib/processes.js index 126d7d8..8221b47 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -525,38 +525,40 @@ function processes(callback) { checkColumn(11); const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim(); checkColumn(12); - let fullcommand = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim(); - if (fullcommand.substr(0, 1) === '[') { fullcommand = fullcommand.substring(1); } - if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); } let cmdPath = ''; let command = ''; let params = ''; - // try to figure out where parameter starts - let firstParamPos = fullcommand.indexOf(' -'); - let firstParamPathPos = fullcommand.indexOf(' /'); - firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000); - firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000); - const firstPos = Math.min(firstParamPos, firstParamPathPos); - let tmpCommand = fullcommand.substr(0, firstPos); - const tmpParams = fullcommand.substr(firstPos); - const lastSlashPos = tmpCommand.lastIndexOf('/'); - if (lastSlashPos >= 0) { - cmdPath = tmpCommand.substr(0, lastSlashPos); - tmpCommand = tmpCommand.substr(lastSlashPos + 1); - } + let fullcommand = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim(); + if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); } + if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); } + else { + // try to figure out where parameter starts + let firstParamPos = fullcommand.indexOf(' -'); + let firstParamPathPos = fullcommand.indexOf(' /'); + firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000); + firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000); + const firstPos = Math.min(firstParamPos, firstParamPathPos); + let tmpCommand = fullcommand.substr(0, firstPos); + const tmpParams = fullcommand.substr(firstPos); + const lastSlashPos = tmpCommand.lastIndexOf('/'); + if (lastSlashPos >= 0) { + cmdPath = tmpCommand.substr(0, lastSlashPos); + tmpCommand = tmpCommand.substr(lastSlashPos + 1); + } - if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) { - const parts = tmpCommand.split(' '); - if (fs.existsSync(path.join(cmdPath, parts[0]))) { - command = parts.shift(); - params = (parts.join(' ') + ' ' + tmpParams).trim(); + if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) { + const parts = tmpCommand.split(' '); + if (fs.existsSync(path.join(cmdPath, parts[0]))) { + command = parts.shift(); + params = (parts.join(' ') + ' ' + tmpParams).trim(); + } else { + command = tmpCommand.trim(); + params = tmpParams.trim(); + } } else { command = tmpCommand.trim(); params = tmpParams.trim(); } - } else { - command = tmpCommand.trim(); - params = tmpParams.trim(); } return ({