Skip to content

Commit

Permalink
fix: Check for stdout in sysctl
Browse files Browse the repository at this point in the history
This fixes the `sysctl` call on Intel macs, where `sysctl` doesn't
output anything (in which case `stdout` is `null`).
  • Loading branch information
nmattia authored and giggio committed Mar 30, 2022
1 parent 41707f1 commit 8c122d9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,20 @@ function isEmulatedRosettaEnvironment() {
const archName = child_process.spawnSync('uname', ['-m']).stdout.toString().trim();

if (archName === 'x86_64') {
const processTranslated = child_process.spawnSync('sysctl', ['-in', 'sysctl.proc_translated'])
.stdout.toString()
.trim();
const proc = child_process.spawnSync('sysctl', ['-in', 'sysctl.proc_translated']);

// When run with `-in`, the return code is 0 even if there is no `sysctl.proc_translated`
if(proc.status) {
throw new Error('Unexpected return code from sysctl: ' + proc.status);
}

// If there is no `sysctl.proc_translated` (i.e. not rosetta) then nothing is printed to
// stdout
if(!proc.stdout) {
return false
}

const processTranslated = proc.stdout.toString().trim();

return processTranslated === '1';
}
Expand Down

0 comments on commit 8c122d9

Please sign in to comment.