Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zevweiss/virtme
Browse files Browse the repository at this point in the history
This improves script mode.
  • Loading branch information
amluto committed Nov 27, 2016
2 parents 4adb4fb + e0c06ae commit 3be28dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions virtme/commands/run.py
Expand Up @@ -198,7 +198,9 @@ def main():
export_virtfs(qemu, arch, qemuargs, guest_tools_path,
'virtme.guesttools')

initargs = ['-c', 'mount -t tmpfs run /run;mkdir -p /run/virtme/guesttools;/bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any virtme.guesttools /run/virtme/guesttools;exec /run/virtme/guesttools/virtme-init']
initcmds = ['mkdir -p /run/virtme/guesttools',
'/bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any virtme.guesttools /run/virtme/guesttools',
'exec /run/virtme/guesttools/virtme-init']

# Map modules
if moddir is not None:
Expand Down Expand Up @@ -295,7 +297,7 @@ def main():

has_script = False

def do_script(shellcmd):
def do_script(shellcmd, use_exec=False):
if args.graphics:
arg_fail('scripts and --graphics are mutually exclusive')

Expand Down Expand Up @@ -328,8 +330,8 @@ def do_script(shellcmd):
# Ask virtme-init to run the script
config.virtme_data[b'script'] = """#!/bin/sh
exec {shellcmd}
""".format(shellcmd=shellcmd).encode('ascii')
{prefix}{shellcmd}
""".format(shellcmd=shellcmd, prefix="exec " if use_exec else "").encode('ascii')

# Nasty issue: QEMU will set O_NONBLOCK on fds 0, 1, and 2.
# This isn't inherently bad, but it can cause a problem if
Expand All @@ -352,7 +354,7 @@ def do_script(shellcmd):
do_script(args.script_sh)

if args.script_exec is not None:
do_script(shlex.quote(args.script_exec))
do_script(shlex.quote(args.script_exec), use_exec=True)

if args.net:
qemuargs.extend(['-net', 'nic,model=virtio'])
Expand Down Expand Up @@ -395,6 +397,7 @@ def do_script(shellcmd):
'rw' if args.rw else 'ro',
])
initrdpath = None
initcmds.insert(0, 'mount -t tmpfs run /run')

# Now that we're done setting up kernelargs, append user-specified args
# and then initargs
Expand All @@ -406,7 +409,7 @@ def do_script(shellcmd):
# sure that 'init=' appears directly before '--'.
kernelargs.append('init=/bin/sh')
kernelargs.append('--')
kernelargs.extend(initargs)
kernelargs.extend(['-c', ';'.join(initcmds)])

if args.xen is None:
# Load a normal kernel
Expand Down
2 changes: 1 addition & 1 deletion virtme/guest/virtme-init
Expand Up @@ -141,7 +141,7 @@ if [[ -x /run/virtme/data/script ]]; then
fi

log 'starting script'
setsid /run/virtme/data/script <>/dev/virtio-ports/virtme.scriptio 2>&1
setsid /run/virtme/data/script <>/dev/virtio-ports/virtme.scriptio 1>&0 2>&0
log "script returned $?"

# Hmm. We should expose the return value somehow.
Expand Down
2 changes: 1 addition & 1 deletion virtme/mkinitramfs.py
Expand Up @@ -157,7 +157,7 @@ def mkinitramfs(out, config):
if config.modfiles is not None:
install_modules(cw, config.modfiles)
for name,contents in config.virtme_data.items():
cw.write_file(b'/run_virtme/data/' + name, body=contents, mode=0o755)
cw.write_file(b'run_virtme/data/' + name, body=contents, mode=0o755)
cw.write_file(b'init', body=generate_init(),
mode=0o755)
cw.write_trailer()
Expand Down

0 comments on commit 3be28dc

Please sign in to comment.