aboutsummaryrefslogtreecommitdiffstats
path: root/main/xen/xendomains.initd
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2014-11-24 14:53:40 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2014-11-24 14:53:40 +0000
commit164c06ca578241499e1c0badeef98ab41569d98b (patch)
tree7cded29abfde62c4871cbf86b4434d4f16481a81 /main/xen/xendomains.initd
parenta2bfcd03d9990b858fcb2e108fec6e1bad923a8f (diff)
downloadaports-164c06ca578241499e1c0badeef98ab41569d98b.tar.bz2
aports-164c06ca578241499e1c0badeef98ab41569d98b.tar.xz
main/xen: fix race in xendomains init.d script
the gnu screen would show files in SCREENDIR before its ready to accept connections. so starting domains failed
Diffstat (limited to 'main/xen/xendomains.initd')
-rw-r--r--main/xen/xendomains.initd90
1 files changed, 55 insertions, 35 deletions
diff --git a/main/xen/xendomains.initd b/main/xen/xendomains.initd
index e6751eeeaa..dd5a924f66 100644
--- a/main/xen/xendomains.initd
+++ b/main/xen/xendomains.initd
@@ -37,26 +37,16 @@ set_screen_cmd() {
screen_cmd="screen -c ${SCREENRC:-/dev/null} -q -r ${SCREEN_NAME:=xen} -X"
}
-dir_is_empty() {
- local dir=$1
- set -- "$dir"/*
- test "$1" = "$dir/*"
-}
-
wait_screen() {
- while dir_is_empty "$SCREENDIR"; do
+ while ! ${screen_cmd} dettach; do
sleep 0.1
done
}
-start() {
+init_screen() {
set_screen_cmd
- checkpath --directory --mode 755 /var/run/xen
-
- einfo "Starting Xen domains from ${AUTODIR:=/etc/xen/auto}"
- if using_screen ; then
- ebegin "Creating screen session to hold domain consoles"
- ( screen -c ${SCREENRC:-/dev/null} -d -m -S ${SCREEN_NAME} -t dom0 \
+ ebegin "Creating screen session to hold domain consoles"
+ ( screen -c ${SCREENRC:-/dev/null} -d -m -S ${SCREEN_NAME} -t dom0 \
&& wait_screen \
&& ${screen_cmd} zombie dr \
&& logrotate -f /etc/xen/xen-consoles.logrotate \
@@ -64,13 +54,54 @@ start() {
&& ${screen_cmd} logfile flush ${SCREEN_LOG_INTERVAL:-1} \
&& ${screen_cmd} log on \
&& ${screen_cmd} deflog on ) >/dev/null
- if [ $? -ne 0 ] ; then
- eend 1
- return 1
- else
- eend
- fi
+ eend $?
+}
+
+startdom_screen() {
+ ${screen_cmd} screen -t ${1} xl create ${2} -c
+}
+
+close_screen() {
+ set_screen_cmd
+ if ${screen_cmd} sleep 0 >/dev/null 2>&1 ; then
+ ebegin "Closing screen session ${SCREEN_NAME}"
+ ${screen_cmd} quit
+ eend $?
+ else
+ eend 0
fi
+}
+
+startdom_noconsole() {
+ xl create --quiet ${2}
+}
+
+
+set_dom_cmd() {
+ if using_screen; then
+ : ${XENDOMAINS_CONSOLE:=screen}
+ fi
+ case "$XENDOMAINS_CONSOLE" in
+ screen)
+ initconsole=init_screen
+ startdom=startdom_screen
+ closeconsole=close_screen
+ ;;
+ *)
+ initconsole=
+ startdom=startdom_noconsole
+ closeconsole=
+ esac
+}
+
+start() {
+ set_dom_cmd
+ checkpath --directory --mode 755 /var/run/xen
+
+ einfo "Starting Xen domains from ${AUTODIR:=/etc/xen/auto}"
+
+ $initconsole
+
# Create all domains with config files in AUTODIR.
want_usleep=
for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do
@@ -82,11 +113,7 @@ start() {
want_usleep=1
fi
ebegin " Starting domain ${name}"
- if using_screen ; then
- ${screen_cmd} screen -t ${name} xl create ${dom} -c
- else
- xl create --quiet ${dom}
- fi
+ $startdom ${name} ${dom}
eend $?
else
einfo " Not starting domain ${name} - already running"
@@ -95,7 +122,7 @@ start() {
}
stop() {
- set_screen_cmd
+ set_dom_cmd
einfo "Shutting down Xen domains from ${AUTODIR:=/etc/xen/auto}"
# Stop all domains with config files in AUTODIR.
@@ -126,15 +153,8 @@ stop() {
fi
done
fi
- if using_screen ; then
- if ${screen_cmd} sleep 0 >/dev/null 2>&1 ; then
- ebegin "Closing screen session ${SCREEN_NAME}"
- ${screen_cmd} quit
- eend $?
- else
- eend 0
- fi
- fi
+
+ $closeconsole
}
status() {