From 96b0b4fcfadee31c800e89c4b36e23af50c2fd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 30 Jun 2017 22:02:21 +0200 Subject: [PATCH] Don't show QEmu window when checking for KVM & check it only for QEmu images --- lib/index.js | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index bdd7793b4..3be958503 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,6 +14,31 @@ const spawnSync = require('child_process').spawnSync const processArguments = require('nodeos-barebones/scripts/processArguments') +function checkKvm(qemuBin) +{ + let contents = "" + + try + { + contents = fs.readFileSync('/proc/cpuinfo') + } catch(e){ + if(e.code !== 'ENOENT') throw(e) + + return false + } + + if(! /(vmx|svm|0xc0f)/.test(contents)) return false + + // We have support for KVM, let's see if QEmu has permissions to use it + try + { + spawnSync(qemuBin, ['-nographic'], {timeout: 1000}) + } catch(e){ + return true + } +} + + function prepareCommandLine(argv, output) { const args = processArguments(argv) @@ -44,26 +69,16 @@ function prepareCommandLine(argv, output) } // check if kvm is supported - let contents = "" - - try - { - contents = fs.readFileSync('/proc/cpuinfo') - } catch(e){ - if(e.code !== 'ENOENT') throw(e) - } - let timeout_rate = 1 - // We have support for KVM, let's see if QEmu has permissions to use it - if(/(vmx|svm|0xc0f)/.test(contents) !== false) - try + function qemuKvm() + { + if(checkKvm(command)) { - spawnSync(command, {timeout: 1000}) - } catch(e){ argv.push('-enable-kvm') timeout_rate = 0.1 } + } // CWD const cwd = join('out', cpu_family, machine, platform) @@ -71,6 +86,8 @@ function prepareCommandLine(argv, output) switch(platform) { case 'disk': + qemuKvm() + argv.push('-hda', 'disk.img') break @@ -88,16 +105,22 @@ function prepareCommandLine(argv, output) break case 'img': + qemuKvm() + argv.push('-hda', 'bootfs.img', '-hdb', 'usersfs.img') break case 'iso': + qemuKvm() + argv.push('-cdrom', 'bootfs.iso', '-hda' , 'usersfs.img') break case 'qemu': + qemuKvm() + const append = [ 'root=/dev/sda',