From 877bd6b963545d5cc85d41f02b003b465bbed60a Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 1 Feb 2019 18:31:43 +0100 Subject: [PATCH] smaller fixes --- lib/cpu.js | 62 +++++++++++++++++++++++-------------------------- lib/graphics.js | 6 ++--- lib/system.js | 6 ++--- lib/util.js | 8 +++---- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/lib/cpu.js b/lib/cpu.js index eb473d9..3b413f9 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -14,7 +14,6 @@ const os = require('os'); const exec = require('child_process').exec; -const execSync = require('child_process').execSync; const fs = require('fs'); const util = require('./util'); @@ -320,42 +319,39 @@ function getCpu() { result.cache.l3 = util.getValue(lines, 'l3 cache'); if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1); } - // # processurs & # threads/core - method 1 - let threadsPerCoreInt = 0; - try { - lines = []; - lines = execSync('cat /proc/cpuinfo | grep -E "physical id|core id"').toString().split('\n'); - if (lines && lines.length) { - result.processors = util.countUniqueLines(lines, 'physical id') || 1; - result.physicalCores = util.countUniqueLines(lines, 'core id') / result.processors; - if (result.physicalCores) { - threadsPerCoreInt = result.cores / result.physicalCores; - } - } - } catch (e) { - util.noop(); - } - // # threads/core - method 2 - if (threadsPerCoreInt === 0) { - const threadsPerCore = util.getValue(lines, 'thread(s) per core'); - if (threadsPerCore) { - threadsPerCoreInt = parseInt(threadsPerCore, 10); - if (!isNaN(threadsPerCoreInt)) { - result.physicalCores = result.cores / threadsPerCoreInt; - } - } - } // socket type - try { - lines = []; - lines = execSync('dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"').toString().split('\n'); + lines = []; + exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) { + lines = stdout2.toString().split('\n'); if (lines && lines.length) { result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim(); } - } catch (e) { - util.noop(); - } - resolve(result); + + // # processurs & # threads/core - method 1 + let threadsPerCoreInt = 0; + lines = []; + exec('cat /proc/cpuinfo | grep -E "physical id|core id"', function (error2, stdout3) { + lines = stdout3.toString().split('\n'); + if (lines && lines.length) { + result.processors = util.countUniqueLines(lines, 'physical id') || 1; + result.physicalCores = util.countUniqueLines(lines, 'core id') / result.processors; + if (result.physicalCores) { + threadsPerCoreInt = result.cores / result.physicalCores; + } + } + // # threads/core - method 2 + if (threadsPerCoreInt === 0) { + const threadsPerCore = util.getValue(lines, 'thread(s) per core'); + if (threadsPerCore) { + threadsPerCoreInt = parseInt(threadsPerCore, 10); + if (!isNaN(threadsPerCoreInt)) { + result.physicalCores = result.cores / threadsPerCoreInt; + } + } + } + resolve(result); + }); + }); }); } if (_freebsd || _openbsd) { diff --git a/lib/graphics.js b/lib/graphics.js index f28ca7c..ee41959 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -167,7 +167,7 @@ function graphics(callback) { // PCI bus IDs let pciIDs = []; try { - pciIDs = execSync('dmidecode -t 9 2>/dev/null | grep "Bus Address: "').toString().split('\n'); + pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "').toString().split('\n'); for (let i = 0; i < pciIDs.length; i++) { pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim(); } @@ -414,7 +414,7 @@ function graphics(callback) { pixeldepth: -1, resolutionx: parseInt(parts[0], 10), resolutiony: parseInt(parts[1], 10) - }) + }); } } if (lines.length > 1 && lines[1].indexOf('gpu=') >= -1) { @@ -424,7 +424,7 @@ function graphics(callback) { bus: '', vram: lines[1].replace('gpu=', ''), vramDynamic: true - }) + }); } if (callback) { callback(result); diff --git a/lib/system.js b/lib/system.js index 63c8cca..3ece980 100644 --- a/lib/system.js +++ b/lib/system.js @@ -41,7 +41,7 @@ function system(callback) { }; if (_linux || _freebsd || _openbsd) { - exec('dmidecode -t system 2>/dev/null', function (error, stdout) { + exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', function (error, stdout) { // if (!error) { let lines = stdout.toString().split('\n'); result.manufacturer = util.getValue(lines, 'manufacturer'); @@ -255,7 +255,7 @@ function bios(callback) { cmd = 'cat /proc/cpuinfo | grep Serial'; } else { - cmd = 'dmidecode --type 0 2>/dev/null'; + cmd = 'export LC_ALL=C; dmidecode --type 0 2>/dev/null; unset LC_ALL'; } exec(cmd, function (error, stdout) { let lines = stdout.toString().split('\n'); @@ -349,7 +349,7 @@ function baseboard(callback) { cmd = 'cat /proc/cpuinfo | grep Serial'; // 'BCM2709', 'BCM2835', 'BCM2708' --> } else { - cmd = 'dmidecode -t 2 2>/dev/null'; + cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL'; } exec(cmd, function (error, stdout) { let lines = stdout.toString().split('\n'); diff --git a/lib/util.js b/lib/util.js index ac74b1b..8558c75 100644 --- a/lib/util.js +++ b/lib/util.js @@ -292,9 +292,9 @@ function isRaspberry() { cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).split('\n'); } catch (e) { return false; - }; + } const hardware = getValue(cpuinfo, 'hardware'); - return (PI_MODEL_NO.indexOf(hardware) >= -1) + return (hardware && PI_MODEL_NO.indexOf(hardware) > -1); } function isRaspbian() { @@ -303,9 +303,9 @@ function isRaspbian() { osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).split('\n'); } catch (e) { return false; - }; + } const id = getValue(osrelease, 'id'); - return (id.indexOf('raspbian') >= -1) + return (id && id.indexOf('raspbian') > -1); } function execWin(cmd, opts, callback) {