debuggers.hg

view stubdom/stubdom-dm @ 19976:98e606e9d173

stubdom: fix stubdom-dm error path

Exit the shell and not a subshell.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 14 14:46:04 2009 +0100 (2009-07-14)
parents 82c6d0b8852e
children 00dfe0ea59e8
line source
1 #!/bin/bash
2 #
3 # Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.net>
4 #
5 # dm script around stubdomains.
6 #
8 DIR=`dirname $0`
9 . "${DIR}/stubdompath.sh"
10 stubdom_configdir="${XEN_CONFIG_DIR}/stubdoms"
12 # To fit xterms nicely
13 height=339
15 # Parse arguments
17 domid=
18 domname=
19 vncviewer=0
20 vncpid=
21 extra=
22 sdl=0
23 opengl=1
24 vnc=0
25 vncunused=0
26 while [ "$#" -gt 0 ];
27 do
28 if [ "$#" -ge 2 ];
29 then
30 case "$1" in
31 -d)
32 domid=$2;
33 extra="$extra -d $domid";
34 shift
35 ;;
36 -domain-name)
37 domname=$2;
38 shift
39 ;;
40 -vnc)
41 vnc=1
42 op=${2%,*}
43 ip=${op%:*};
44 vnc_port=${op#*:};
45 shift
46 ;;
47 -vncunused)
48 vncunused=1
49 shift
50 ;;
51 -loadvm)
52 extra="$extra -loadvm $2";
53 shift
54 ;;
55 -k)
56 keymap=$2
57 shift
58 ;;
59 -serial)
60 serial="$2"
61 shift
62 ;;
63 -monitor)
64 monitor="$2"
65 shift
66 ;;
67 esac
68 fi
69 case "$1" in
70 -vncviewer) vncviewer=1 ;;
71 -sdl) sdl=1 ;;
72 -disable-opengl) opengl=0 ;;
73 esac
74 shift
75 done
77 [ -z "$domid" ] && { echo "couldn't find domain ID" ; exit 1; }
78 [ -z "$domname" ] && { echo "couldn't find domain name" ; exit 1; }
80 # Termination handler
82 term() {
83 kill %1
84 (
85 [ -n "$vncpid" ] && kill -9 $vncpid
86 rm ${stubdom_configdir}/$domname-dm
87 xm destroy $domname-dm
88 ) &
89 # We need to exit immediately so as to let xend do the commands above
90 exit 0
91 }
93 trap term SIGHUP
95 ############
96 # stubdomain
97 # Wait for any previous stubdom to terminate
98 while xm list | grep $domname-dm
99 do
100 sleep 1
101 done
103 # Generate stubdom config file
104 mkdir -p ${stubdom_configdir} &>/dev/null
105 echo "#This file is autogenerated, edit $domname instead!" > ${stubdom_configdir}/$domname-dm
106 echo "kernel = '${XENFIRMWAREDIR}/ioemu-stubdom.gz'" >> ${stubdom_configdir}/$domname-dm
108 vfb="sdl=$sdl, opengl=$opengl"
109 test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
110 test "$XAUTHORITY" && vfb="$vfb, xauthority=$XAUTHORITY"
111 test $vnc != 0 && vfb="$vfb, vnc=$vnc, vncdisplay=$vnc_port, vnclisten=$ip, vncunused=$vncunused"
112 vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
113 test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
114 test "$keymap" && vfb="$vfb, keymap=$keymap"
115 test "$monitor" && vfb="$vfb, monitor=$monitor"
116 test "$serial" && vfb="$vfb, serial=$serial"
117 echo "vfb = ['$vfb']" >> ${stubdom_configdir}/$domname-dm
119 echo -n "disk = [ " >> ${stubdom_configdir}/$domname-dm
120 j=0
121 for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
122 do
123 i=${i%\"}
124 i=${i#\"}
125 vbd_mode=`xenstore-read $i/mode`
126 vbd_disk=`xenstore-read $i/params`
127 vbd_type=`xenstore-read $i/type`
128 vbd_dev=`xenstore-read $i/dev`
129 vbd_front=`xenstore-read $i/frontend`
130 vbd_devtype=`xenstore-read $vbd_front/device-type`
131 if [ $j -ne 0 ]
132 then
133 echo -n "," >> ${stubdom_configdir}/$domname-dm
134 fi
135 echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> ${stubdom_configdir}/$domname-dm
136 j=$(( $j + 1 ))
137 done
138 echo " ] " >> ${stubdom_configdir}/$domname-dm
139 echo -n "vif = [ " >> ${stubdom_configdir}/$domname-dm
140 j=0
141 for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
142 do
143 i=${i%\"}
144 i=${i#\"}
145 vif_mac=`xenstore-read $i/mac`
146 if [ $j -ne 0 ]
147 then
148 echo -n "," >> ${stubdom_configdir}/$domname-dm
149 fi
150 echo -n "'mac=$vif_mac'" >> ${stubdom_configdir}/$domname-dm
151 j=$(( $j + 1 ))
152 done
153 echo " ] " >> ${stubdom_configdir}/$domname-dm
154 creation="xm create -c ${stubdom_configdir}/$domname-dm target=$domid memory=32 extra=\"$extra\""
156 (while true ; do sleep 60 ; done) | /bin/sh -c "$creation" &
157 #xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
158 consolepid=$!
161 ###########
162 # vncviewer
163 if [ "$vncviewer" = 1 ]
164 then
165 # Wait for vnc server to appear
166 while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
167 do
168 # Check that the stubdom job is still alive
169 kill -0 $consolepid || term
170 sleep 1
171 done
173 vncviewer $ip:$vnc_port &
174 vncpid=$!
175 fi
177 # wait for SIGHUP or stubdom termination
178 wait $consolepid
180 term