Skip to content

Commit

Permalink
Don't show QEmu window when checking for KVM & check it only for QEmu…
Browse files Browse the repository at this point in the history
… images
  • Loading branch information
piranna committed Jun 30, 2017
1 parent 3801639 commit 96b0b4f
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions lib/index.js
Expand Up @@ -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)
Expand Down Expand Up @@ -44,33 +69,25 @@ 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)

switch(platform)
{
case 'disk':
qemuKvm()

argv.push('-hda', 'disk.img')
break

Expand All @@ -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',
Expand Down

0 comments on commit 96b0b4f

Please sign in to comment.