Skip to content

Commit

Permalink
execSync() fixed EFAUL issue (linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Aug 1, 2024
1 parent f81b635 commit b33df17
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.

| Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| 5.23.2 | 2024-08-01 | `execSync()` fixed EFAULT (linux) |
| 5.23.1 | 2024-07-31 | `disklayout()` updated docs (macOS) |
| 5.23.0 | 2024-07-31 | `usb()` added serialNumber (linux) |
| 5.22.11 | 2024-06-10 | `osInfo()` added macOS Sequoia |
Expand Down
5 changes: 5 additions & 0 deletions docs/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ <h3>Full version history</h3>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.23.2</th>
<td>2024-08-01</td>
<td><span class="code">execSync()</span> fixed EFAULT (linux)</td>
</tr>
<tr>
<th scope="row">5.23.1</th>
<td>2024-07-31</td>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.23.1</span></div>
<div class="version">New Version: <span id="version">5.23.2</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">
Expand Down
2 changes: 1 addition & 1 deletion lib/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getLinuxAudioPci() {
let cmd = 'lspci -v 2>/dev/null';
let result = [];
try {
const parts = execSync(cmd).toString().split('\n\n');
const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n');
parts.forEach(element => {
const lines = element.split('\n');
if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function bluetoothDevices(callback) {
});
// determine "connected" with hcitool con
try {
const hdicon = execSync('hcitool con').toString().toLowerCase();
const hdicon = execSync('hcitool con', util.execOptsLinux).toString().toLowerCase();
for (let i = 0; i < result.length; i++) {
if (result[i].macDevice && result[i].macDevice.length > 10 && hdicon.indexOf(result[i].macDevice.toLowerCase()) >= 0) {
result[i].connected = true;
Expand Down
4 changes: 2 additions & 2 deletions lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ function cpuTemperature(callback) {
// CPU Chipset, Socket
try {
const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;';
const parts = execSync(cmd).toString().split('-----\n');
const parts = execSync(cmd, util.execOptsLinux).toString().split('-----\n');
if (parts.length === 2) {
const lines = parts[0].split('\n');
const lines2 = parts[1].split('\n');
Expand Down Expand Up @@ -1605,7 +1605,7 @@ function getLoad() {
// linux: try to get other cpu stats
if (_linux) {
try {
const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu', { encoding: 'utf8' }).toString().split('\n');
const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu', util.execOptsLinux).toString().split('\n');
if (lines.length > 1) {
lines.shift();
if (lines.length === cpus.length) {
Expand Down
8 changes: 4 additions & 4 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function fsSize(drive, callback) {
if (_linux) {
try {
cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL';
execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => {
execSync('cat /proc/mounts 2>/dev/null', util.execOptsLinux).toString().split('\n').filter(line => {
return line.startsWith('/');
}).forEach((line) => {
osMounts[line.split(' ')[0]] = osMounts[line.split(' ')[0]] || false;
Expand Down Expand Up @@ -426,7 +426,7 @@ function raidMatchLinux(data) {
try {
data.forEach(element => {
if (element.type.startsWith('raid')) {
const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n');
const lines = execSync(`mdadm --export --detail /dev/${element.name}`, util.execOptsLinux).toString().split('\n');
const mdData = decodeMdabmData(lines);

element.label = mdData.label; // <- assign label info
Expand Down Expand Up @@ -1087,7 +1087,7 @@ function diskLayout(callback) {
} catch (e) {
// fallback to older version of lsblk
try {
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString();
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL', util.execOptsLinux).toString();
let lines = blkStdoutToObject(out2).split('\n');
const data = parseBlk(lines);
devices = data.filter(item => { return (item.type === 'disk') && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mount === '' && item.label === '' && item.fsType === '')); });
Expand All @@ -1100,7 +1100,7 @@ function diskLayout(callback) {
const BSDName = '/dev/' + device.name;
const logical = device.name;
try {
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null').toString().split('\n')[0];
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null', util.execOptsLinux).toString().split('\n')[0];
} catch (e) {
util.noop();
}
Expand Down
5 changes: 4 additions & 1 deletion lib/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function graphics(callback) {
// PCI bus IDs
let pciIDs = [];
try {
pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "').toString().split('\n');
pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "', util.execOptsLinux).toString().split('\n');
for (let i = 0; i < pciIDs.length; i++) {
pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim();
}
Expand Down Expand Up @@ -421,6 +421,9 @@ function graphics(callback) {
if (nvidiaSmiExe) {
const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts + (_linux ? ' 2>/dev/null' : '');
if (_linux) {
options.stdio = ['pipe', 'pipe', 'ignore'];
}
try {
const res = execSync(cmd, options).toString();
return res;
Expand Down
6 changes: 3 additions & 3 deletions lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function memLayout(callback) {

// Try Raspberry PI
try {
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null');
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
let lines = stdout.toString().split('\n');
let model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
let version = util.getValue(lines, 'revision', ':', true).toLowerCase();
Expand All @@ -419,14 +419,14 @@ function memLayout(callback) {
result[0].clockSpeed = version && version[4] && version[4] === 'd' ? 500 : result[0].clockSpeed;
result[0].formFactor = 'SoC';

stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null');
stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null', util.execOptsLinux);
lines = stdout.toString().split('\n');
let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0;
if (freq) {
result[0].clockSpeed = freq;
}

stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null');
stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null', util.execOptsLinux);
lines = stdout.toString().split('\n');
let voltage = parseFloat(util.getValue(lines, 'volt', '=', true)) || 0;
if (voltage) {
Expand Down
20 changes: 10 additions & 10 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function getDefaultNetworkInterface() {
}
if (_linux) {
let cmd = 'ip route 2> /dev/null | grep default';
let result = execSync(cmd);
let result = execSync(cmd, util.execOptsLinux);
let parts = result.toString().split('\n')[0].split(/\s+/);
if (parts[0] === 'none' && parts[5]) {
ifacename = parts[5];
Expand Down Expand Up @@ -130,7 +130,7 @@ function getMacAddresses() {
if (_linux || _freebsd || _openbsd || _netbsd) {
if (typeof pathToIp === 'undefined') {
try {
const lines = execSync('which ip').toString().split('\n');
const lines = execSync('which ip', util.execOptsLinux).toString().split('\n');
if (lines.length && lines[0].indexOf(':') === -1 && lines[0].indexOf('/') === 0) {
pathToIp = lines[0];
} else {
Expand All @@ -142,7 +142,7 @@ function getMacAddresses() {
}
try {
const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
let res = execSync(cmd);
let res = execSync(cmd, util.execOptsLinux);
const lines = res.toString().split('\n');
for (let i = 0; i < lines.length; i++) {
if (lines[i] && lines[i][0] !== ' ') {
Expand Down Expand Up @@ -511,7 +511,7 @@ function getLinuxIfaceConnectionName(interfaceName) {
const cmd = `nmcli device status 2>/dev/null | grep ${interfaceName}`;

try {
const result = execSync(cmd).toString();
const result = execSync(cmd, util.execOptsLinux).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim();
const connectionNameLines = resultFormat.split(' ').slice(3);
const connectionName = connectionNameLines.join(' ');
Expand All @@ -525,7 +525,7 @@ function checkLinuxDCHPInterfaces(file) {
let result = [];
try {
let cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`;
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');

lines.forEach(line => {
const parts = line.replace(/\s+/g, ' ').trim().split(' ');
Expand All @@ -550,7 +550,7 @@ function getLinuxDHCPNics() {
let cmd = 'ip a 2> /dev/null';
let result = [];
try {
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
const nsections = splitSectionsNics(lines);
result = (parseLinuxDHCPNics(nsections));
} catch (e) {
Expand Down Expand Up @@ -591,7 +591,7 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.method;`;
try {
const lines = execSync(cmd).toString();
const lines = execSync(cmd, util.execOptsLinux).toString();
const resultFormat = lines.replace(/\s+/g, ' ').trim();

let dhcStatus = resultFormat.split(' ').slice(1).toString();
Expand Down Expand Up @@ -631,7 +631,7 @@ function getLinuxIfaceDNSsuffix(connectionName) {
if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.dns-search;`;
try {
const result = execSync(cmd).toString();
const result = execSync(cmd, util.execOptsLinux).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim();
const dnsSuffix = resultFormat.split(' ').slice(1).toString();
return dnsSuffix == '--' ? 'Not defined' : dnsSuffix;
Expand All @@ -647,7 +647,7 @@ function getLinuxIfaceIEEE8021xAuth(connectionName) {
if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep 802-1x.eap;`;
try {
const result = execSync(cmd).toString();
const result = execSync(cmd, util.execOptsLinux).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim();
const authenticationProtocol = resultFormat.split(' ').slice(1).toString();

Expand Down Expand Up @@ -875,7 +875,7 @@ function networkInterfaces(callback, rescan, defaultString) {

let lines = [];
try {
lines = execSync(cmd).toString().split('\n');
lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
const connectionName = getLinuxIfaceConnectionName(ifaceSanitized);
dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics);
dnsSuffix = getLinuxIfaceDNSsuffix(connectionName);
Expand Down
4 changes: 2 additions & 2 deletions lib/osinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ function getFQDN() {
let fqdn = os.hostname;
if (_linux || _darwin) {
try {
const stdout = execSync('hostnamectl --json short 2>/dev/null');
const stdout = execSync('hostnamectl --json short 2>/dev/null', util.execOptsLinux);
const json = JSON.parse(stdout.toString());

fqdn = json['StaticHostname'];
} catch (e) {
try {
const stdout = execSync('hostname -f 2>/dev/null');
const stdout = execSync('hostname -f 2>/dev/null', util.execOptsLinux);
fqdn = stdout.toString().split(os.EOL)[0];
} catch (e) {
util.noop();
Expand Down
6 changes: 3 additions & 3 deletions lib/processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function services(srv, callback) {
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') {
try {
const tmpsrv = execSync('systemctl --all --type=service --no-legend 2> /dev/null').toString().split('\n');
const tmpsrv = execSync('systemctl --all --type=service --no-legend 2> /dev/null', util.execOptsLinux).toString().split('\n');
srvs = [];
for (const s of tmpsrv) {
const name = s.split('.service')[0];
Expand All @@ -164,7 +164,7 @@ function services(srv, callback) {
} catch (d) {
try {
srvString = '';
const tmpsrv = execSync('service --status-all 2> /dev/null').toString().split('\n');
const tmpsrv = execSync('service --status-all 2> /dev/null', util.execOptsLinux).toString().split('\n');
for (const s of tmpsrv) {
const parts = s.split(']');
if (parts.length === 2) {
Expand All @@ -174,7 +174,7 @@ function services(srv, callback) {
srvs = srvString.split('|');
} catch (e) {
try {
const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null').toString().split('\n').join('');
const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null', util.execOptsLinux).toString().split('\n').join('');
srvString = '';
if (srvStr) {
const tmpsrv = srvStr.split(',');
Expand Down
10 changes: 5 additions & 5 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function system(callback) {
echo -n "product_version: "; cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null; echo;
echo -n "sys_vendor: "; cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; echo;`;
try {
lines = execSync(cmd).toString().split('\n');
lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
result.manufacturer = result.manufacturer === '' ? util.getValue(lines, 'sys_vendor') : result.manufacturer;
result.model = result.model === '' ? util.getValue(lines, 'product_name') : result.model;
result.version = result.version === '' ? util.getValue(lines, 'product_version') : result.version;
Expand Down Expand Up @@ -107,7 +107,7 @@ function system(callback) {
}
if (!result.virtual) {
try {
const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null').toString();
const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null', util.execOptsLinux).toString();
if (disksById.indexOf('_QEMU_') >= 0) {
result.virtual = true;
result.virtualHost = 'QEMU';
Expand All @@ -129,7 +129,7 @@ function system(callback) {
}
if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) {
try {
const procInfo = execSync('dmidecode -t 4');
const procInfo = execSync('dmidecode -t 4', util.execOptsLinux);
const procLines = procInfo.toString().split('\n');
const procManufacturer = util.getValue(procLines, 'manufacturer', ':', true);
switch (procManufacturer.toLowerCase()) {
Expand Down Expand Up @@ -371,7 +371,7 @@ function bios(callback) {
echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo;
echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`;
try {
lines = execSync(cmd).toString().split('\n');
lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
result.vendor = !result.vendor ? util.getValue(lines, 'bios_vendor') : result.vendor;
result.version = !result.version ? util.getValue(lines, 'bios_version') : result.version;
datetime = util.getValue(lines, 'bios_date');
Expand Down Expand Up @@ -485,7 +485,7 @@ function baseboard(callback) {
echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo;
echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`;
try {
lines = execSync(cmd).toString().split('\n');
lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
result.manufacturer = !result.manufacturer ? util.getValue(lines, 'board_vendor') : result.manufacturer;
result.model = !result.model ? util.getValue(lines, 'board_name') : result.model;
result.version = !result.version ? util.getValue(lines, 'board_version') : result.version;
Expand Down
Loading

0 comments on commit b33df17

Please sign in to comment.