From 11b8a0409f32537fe4b1cf19aa5c1c31527bfaf9 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Wed, 14 Jul 2010 18:50:48 +0200 Subject: [PATCH] DVM: execute user script before save qubes_prepare_saved_domain.sh now takes optional second argument, the filename. The content of the file will be copied (via xenstore) to DVM and executed just before save. This makes it possible to preload memory with useful apps. --- appvm/qubes_core | 15 ++++++++++++++- dom0/restore/qubes_prepare_saved_domain.sh | 21 ++++++++++++++++++--- rpm_spec/core-appvm.spec | 4 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/appvm/qubes_core b/appvm/qubes_core index 407c9dbe..2b6a1596 100755 --- a/appvm/qubes_core +++ b/appvm/qubes_core @@ -6,6 +6,18 @@ # Source function library. . /etc/rc.d/init.d/functions +possibly_run_save_script() +{ + ENCODED_SCRIPT=$(xenstore-read qubes_save_script) + if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi + echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64()' >/tmp/qubes_save_script + chmod 755 /tmp/qubes_save_script + Xorg -config /etc/X11/xorg-preload-apps.conf :0 & + sleep 2 + DISPLAY=:0 su - user -c /tmp/qubes_save_script + killall Xorg +} + start() { echo -n $"Executing Qubes Core scripts:" @@ -14,7 +26,8 @@ start() echo "ERROR: /usr/bin/xenstore-read not found!" exit 1 fi - if xenstore-read qubes_save_request ; then + if xenstore-read qubes_save_request 2>/dev/null ; then + possibly_run_save_script touch /etc/this_is_dvm dmesg -c >/dev/null # echo 1 >/proc/sys/vm/drop_caches diff --git a/dom0/restore/qubes_prepare_saved_domain.sh b/dom0/restore/qubes_prepare_saved_domain.sh index bbc7df6a..e0dfcf6c 100755 --- a/dom0/restore/qubes_prepare_saved_domain.sh +++ b/dom0/restore/qubes_prepare_saved_domain.sh @@ -1,9 +1,21 @@ #!/bin/sh -if ! [ $# = 2 ] ; then - echo usage: $0 domainname savefile_to_be_created +get_encoded_script() +{ + if ! [ -f "$1" ] ; then + echo $1 is not a file ? + exit 1 + fi + ENCODED_SCRIPT=`cat "$1" | perl -e 'use MIME::Base64 qw(encode_base64); local($/) = undef;print encode_base64()'|tr -d "\n"` +} + +if [ $# != 2 -a $# != 3 ] ; then + echo usage: $0 domainname savefile_to_be_created [preload script] exit 1 fi export PATH=$PATH:/sbin:/usr/sbin +if [ $# = 3 ] ; then + get_encoded_script $3 +fi VMDIR=/var/lib/qubes/appvms/$1 if ! [ -d $VMDIR ] ; then echo $VMDIR does not exist ? @@ -20,12 +32,15 @@ for i in $(xenstore-list /local/domain) ; do ID=$i fi done -set -x if [ $ID = none ] ; then echo cannot get domain id exit 1 fi echo domainid=$ID +if [ -n "$ENCODED_SCRIPT" ] ; then + xenstore-write /local/domain/$ID/qubes_save_script "$ENCODED_SCRIPT" +fi +set -x xenstore-write /local/domain/$ID/qubes_save_request 1 xenstore-watch /local/domain/$ID/device/qubes_used_mem xenstore-read /local/domain/$ID/qubes_gateway | \ diff --git a/rpm_spec/core-appvm.spec b/rpm_spec/core-appvm.spec index 351e1d2d..143aa3dc 100644 --- a/rpm_spec/core-appvm.spec +++ b/rpm_spec/core-appvm.spec @@ -81,6 +81,9 @@ cp ../common/qubes_serial_login $RPM_BUILD_ROOT/sbin mkdir -p $RPM_BUILD_ROOT/etc cp ../common/serial.conf $RPM_BUILD_ROOT/var/lib/qubes/ +mkdir -p $RPM_BUILD_ROOT/etc/X11 +cp xorg-preload-apps.conf $RPM_BUILD_ROOT/etc/X11 + mkdir -p $RPM_BUILD_ROOT/home_volatile/user chown 500:500 $RPM_BUILD_ROOT/home_volatile/user @@ -199,3 +202,4 @@ rm -rf $RPM_BUILD_ROOT /usr/bin/qubes_timestamp %dir /home_volatile %attr(700,user,user) /home_volatile/user +/etc/X11/xorg-preload-apps.conf