vm/windows: Collect exit code from xchg.

This is the last item that was missing to get a fully working
runInWindowsVM function. Apart from checking exit codes, we also now
have preVM/postVM hooks which we can use to write arbitrary constructs
around this architecture, without the need to worry about specific
details.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
aszlig 2014-02-17 00:34:19 +01:00
parent b01c9624cf
commit e40f41e505
No known key found for this signature in database
GPG Key ID: D0EBD0EC8C2DC961
1 changed files with 23 additions and 5 deletions

View File

@ -128,12 +128,10 @@ let
-i /ssh.key \ -i /ssh.key \
-l Administrator \ -l Administrator \
192.168.0.1 -- ${shellEscape command} 192.168.0.1 -- ${shellEscape command}
'') + lib.optionalString (suspendTo != null) ''
${lib.optionalString (suspendTo != null) ''
${coreutils}/bin/touch /xchg/suspend_now ${coreutils}/bin/touch /xchg/suspend_now
${loopForever} ${loopForever}
''} '');
''));
kernelAppend = lib.concatStringsSep " " [ kernelAppend = lib.concatStringsSep " " [
"panic=1" "panic=1"
@ -175,6 +173,9 @@ let
(set; declare -p) > saved-env (set; declare -p) > saved-env
XCHG_DIR="$(${coreutils}/bin/mktemp -d nix-vm.XXXXXXXXXX --tmpdir)" XCHG_DIR="$(${coreutils}/bin/mktemp -d nix-vm.XXXXXXXXXX --tmpdir)"
${coreutils}/bin/mv saved-env "$XCHG_DIR/" ${coreutils}/bin/mv saved-env "$XCHG_DIR/"
eval "$preVM"
QEMU_VDE_SOCKET="$(pwd)/vde.ctl" QEMU_VDE_SOCKET="$(pwd)/vde.ctl"
MONITOR_SOCKET="$(pwd)/monitor" MONITOR_SOCKET="$(pwd)/monitor"
${vde2}/bin/vde_switch -s "$QEMU_VDE_SOCKET" & ${vde2}/bin/vde_switch -s "$QEMU_VDE_SOCKET" &
@ -190,7 +191,9 @@ let
'' else '' '' else ''
${vmTools.qemuProg} ${cygwinQemuArgs} & ${vmTools.qemuProg} ${cygwinQemuArgs} &
${vmTools.qemuProg} ${controllerQemuArgs}${bgBoth} ${vmTools.qemuProg} ${controllerQemuArgs}${bgBoth}
'' + lib.optionalString (suspendTo != null) '' '';
postVM = if suspendTo != null then ''
while ! test -e "$XCHG_DIR/suspend_now"; do sleep 1; done while ! test -e "$XCHG_DIR/suspend_now"; do sleep 1; done
${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET <<CMD ${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET <<CMD
stop stop
@ -199,10 +202,25 @@ let
quit quit
CMD CMD
wait %- wait %-
eval "$postVM"
exit 0
'' else if installMode then ''
eval "$postVM"
exit 0
'' else ''
if ! test -e "$XCHG_DIR/in-vm-exit"; then
echo "Virtual machine didn't produce an exit code."
exit 1
fi
eval "$postVM"
exit $(< "$XCHG_DIR/in-vm-exit")
''; '';
in writeScript "run-cygwin-vm.sh" '' in writeScript "run-cygwin-vm.sh" ''
#!${stdenv.shell} -e #!${stdenv.shell} -e
${preVM} ${preVM}
${vmExec} ${vmExec}
${postVM}
'' ''