public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Harring" <ferringb@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/kvm-tools:ferringb commit in: app-emulation/qemu-init-scripts/files/
Date: Sat, 14 Apr 2012 23:01:32 +0000 (UTC)	[thread overview]
Message-ID: <1334444477.d3291abf0e2d0b3bd07cffe8a2ac2e052e7d4dae.ferringb@gentoo> (raw)

commit:     d3291abf0e2d0b3bd07cffe8a2ac2e052e7d4dae
Author:     Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 22:54:32 2012 +0000
Commit:     Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 23:01:17 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=d3291abf

Make foreground controllable.

This deprecates the VNC option in favour of `FOREGROUND=vnc=:1`; in the
process it makes turning off the display (none mode), and sdl mode
possible.

For sdl mode, it tries to rely on DISPLAY and XAUTHORITY to work.  In
my local usage, this *does* work, but wouldn't surprise me if there are
other configurations where this doesn't (patches welcome).

---
 .../qemu-init-scripts/files/qemu-init-script       |   68 ++++++++++++++++++--
 1 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/app-emulation/qemu-init-scripts/files/qemu-init-script b/app-emulation/qemu-init-scripts/files/qemu-init-script
index e12658c..13dacfe 100644
--- a/app-emulation/qemu-init-scripts/files/qemu-init-script
+++ b/app-emulation/qemu-init-scripts/files/qemu-init-script
@@ -16,6 +16,8 @@ PIDFILE=/var/run/vm/${SVCNAME}.pid
 MONITOR=/var/run/vm/${SVCNAME}.monitor
 QTAP_FILE=/var/run/vm/${SVCNAME}.qtap
 
+ENABLE_SDL=
+
 discern_vm_binary() {
 	case "$VMTYPE" in
 		kvm)
@@ -32,6 +34,35 @@ discern_vm_binary() {
 	return 0
 }
 
+discern_foreground() {
+	if [ -n "$VNC" ]; then
+		ewarn "VNC option is going away; set FOREGROUND=vnc${VNC} instead"
+		FOREGROUND="vnc=${VNC}"
+	fi
+	case "${FOREGROUND:-none}" in
+		vnc*)
+			VNC=${VNC#*=}
+			if [ -z "$VNC" ]; then
+				eerror "FOREGROUND vnc is incorrectly set; must specify an address (:1 for example)"
+				return 1
+			fi
+			;;
+		sdl*)
+			ENABLE_SDL=${FOREGROUND#*=}
+			if [ -z "${ENABLE_SDL}" ]; then
+				eerror "FOREGROUND sdl is incorrectly set; must specify a DISPLAY address"
+				return 1
+			fi
+			;;
+		none)
+			;;
+		*)
+			eerror "Unknown FOREGROUND setting: $FOREGROUND"
+			return 1
+			;;
+	esac
+	return 0
+}
 
 DROP_USER=${DROP_USER:-nobody}
 MEMORY=${MEMORY:-512M}
@@ -73,8 +104,10 @@ sanity_check() {
 		eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
 		return 1;
 	fi
-	discern_vm_binary
+	discern_vm_binary || return 1
 	NIC_TYPE=${NIC_TYPE:-nat}
+
+	discern_foreground || return 1
 }
 
 start_pre() {
@@ -107,17 +140,40 @@ start() {
 		NIC_COMMAND[${#NIC_COMMAND[@]}]=user
 	fi
 
-	ebegin "Starting ${VM_BINARY##*/} for ${VMNAME} at VNC port${VNC}"
-	start-stop-daemon --start "${VM_BINARY}" \
+	local ss_args=( )
+	local vm_args=( -daemonize )
+
+	if [ -n "${ENABLE_SDL}" ]; then
+		ss_args[${#ss_args[@]}]=--env
+		ss_args[${#ss_args[@]}]="DISPLAY=${ENABLE_SDL}"
+		ss_args[${#ss_args[@]}]=--env
+		local user_home=`getent passwd ${DROP_USER:-root} | cut -d: -f6`
+		ss_args[${#ss_args[@]}]="XAUTHORITY=$user_home/.Xauthority"
+		vm_args[${#vm_args[@]}]=-display
+		vm_args[${#vm_args[@]}]=sdl
+	elif [ -n "$VNC" ]; then
+		vm_args[${#vm_args[@]}]=-display
+		vm_args[${#vm_args[@]}]=vnc
+		vm_args[${#vm_args[@]}]="${VNC}"
+	else
+		vm_args[${#vm_args[@]}]=-display
+		vm_args[${#vm_args[@]}]=none
+	fi
+
+	ebegin "Starting ${VM_BINARY##*/} for ${VMNAME} ${FOREGROUND:+at ${FOREGROUND}}"
+	start-stop-daemon \
+		--start "${VM_BINARY}" \
 		--pidfile ${PIDFILE} \
-		-- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
+		"${ss_args[@]}" \
+		-- \
+		"${vm_args[@]}" \
+		-pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
 		-runas ${DROP_USER} -name ${VMNAME} \
 		-drive file="${DISKIMAGE//,/,,}",if=${DRIVE_MODEL:-virtio},cache=${DRIVE_CACHE:-none} \
 		"${NIC_COMMAND[@]}" \
 		${DISABLE_KVM:---enable-kvm}  \
-		${MEMORY:+-m ${MEMORY}} ${SMP:+-smp ${SMP}} ${VNC:+-vnc ${VNC}} ${OTHER_ARGS}
+		${MEMORY:+-m ${MEMORY}} ${SMP:+-smp ${SMP}} ${OTHER_ARGS}
 	ret=$?
-
 	if [ "0" != "${ret}" -a -n "${QTAP}" ]; then
 		qtap-manipulate destroy ${QTAP}
 	fi



             reply	other threads:[~2012-04-14 23:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-14 23:01 Brian Harring [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-04-14 23:01 [gentoo-commits] proj/kvm-tools:ferringb commit in: app-emulation/qemu-init-scripts/files/ Brian Harring
2012-04-14 23:48 Brian Harring
2012-08-24  4:18 [gentoo-commits] proj/kvm-tools:master " Brian Harring
2012-04-14 23:48 ` [gentoo-commits] proj/kvm-tools:ferringb " Brian Harring
2012-08-24  4:18 [gentoo-commits] proj/kvm-tools:master " Brian Harring
2012-04-14 23:48 ` [gentoo-commits] proj/kvm-tools:ferringb " Brian Harring
2012-08-24  4:18 [gentoo-commits] proj/kvm-tools:master " Brian Harring
2012-04-14 23:48 ` [gentoo-commits] proj/kvm-tools:ferringb " Brian Harring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334444477.d3291abf0e2d0b3bd07cffe8a2ac2e052e7d4dae.ferringb@gentoo \
    --to=ferringb@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox