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.
This commit is contained in:
Rafal Wojtczuk 2010-07-14 18:50:48 +02:00 committed by Joanna Rutkowska
parent 0c0f34ba9b
commit 11b8a0409f
3 changed files with 36 additions and 4 deletions

View File

@ -6,6 +6,18 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /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(<STDIN>)' >/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() start()
{ {
echo -n $"Executing Qubes Core scripts:" echo -n $"Executing Qubes Core scripts:"
@ -14,7 +26,8 @@ start()
echo "ERROR: /usr/bin/xenstore-read not found!" echo "ERROR: /usr/bin/xenstore-read not found!"
exit 1 exit 1
fi 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 touch /etc/this_is_dvm
dmesg -c >/dev/null dmesg -c >/dev/null
# echo 1 >/proc/sys/vm/drop_caches # echo 1 >/proc/sys/vm/drop_caches

View File

@ -1,9 +1,21 @@
#!/bin/sh #!/bin/sh
if ! [ $# = 2 ] ; then get_encoded_script()
echo usage: $0 domainname savefile_to_be_created {
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(<STDIN>)'|tr -d "\n"`
}
if [ $# != 2 -a $# != 3 ] ; then
echo usage: $0 domainname savefile_to_be_created [preload script]
exit 1 exit 1
fi fi
export PATH=$PATH:/sbin:/usr/sbin export PATH=$PATH:/sbin:/usr/sbin
if [ $# = 3 ] ; then
get_encoded_script $3
fi
VMDIR=/var/lib/qubes/appvms/$1 VMDIR=/var/lib/qubes/appvms/$1
if ! [ -d $VMDIR ] ; then if ! [ -d $VMDIR ] ; then
echo $VMDIR does not exist ? echo $VMDIR does not exist ?
@ -20,12 +32,15 @@ for i in $(xenstore-list /local/domain) ; do
ID=$i ID=$i
fi fi
done done
set -x
if [ $ID = none ] ; then if [ $ID = none ] ; then
echo cannot get domain id echo cannot get domain id
exit 1 exit 1
fi fi
echo domainid=$ID 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-write /local/domain/$ID/qubes_save_request 1
xenstore-watch /local/domain/$ID/device/qubes_used_mem xenstore-watch /local/domain/$ID/device/qubes_used_mem
xenstore-read /local/domain/$ID/qubes_gateway | \ xenstore-read /local/domain/$ID/qubes_gateway | \

View File

@ -81,6 +81,9 @@ cp ../common/qubes_serial_login $RPM_BUILD_ROOT/sbin
mkdir -p $RPM_BUILD_ROOT/etc mkdir -p $RPM_BUILD_ROOT/etc
cp ../common/serial.conf $RPM_BUILD_ROOT/var/lib/qubes/ 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 mkdir -p $RPM_BUILD_ROOT/home_volatile/user
chown 500:500 $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 /usr/bin/qubes_timestamp
%dir /home_volatile %dir /home_volatile
%attr(700,user,user) /home_volatile/user %attr(700,user,user) /home_volatile/user
/etc/X11/xorg-preload-apps.conf