From 49bfe8921ca27d5b6e36576bc476306cac86757a Mon Sep 17 00:00:00 2001 From: Joanna Rutkowska Date: Tue, 2 Aug 2011 14:12:03 +0200 Subject: [PATCH] dom0: qvm-sync-dom0-clock --- dom0/qvm-tools/qvm-sync-dom0-clock | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dom0/qvm-tools/qvm-sync-dom0-clock diff --git a/dom0/qvm-tools/qvm-sync-dom0-clock b/dom0/qvm-tools/qvm-sync-dom0-clock new file mode 100644 index 00000000..ab588c05 --- /dev/null +++ b/dom0/qvm-tools/qvm-sync-dom0-clock @@ -0,0 +1,34 @@ +#!/bin/sh + +UPDATES_VM=`qvm-get-updatevm` + +QREXEC_CLIENT=/usr/lib/qubes/qrexec_client + +if [ -z "$UPDATES_VM" ]; then + echo "UpdateVM not set, exiting!" >&2 + exit 1 +fi + +if ! xl domid "$UPDATES_VM" > /dev/null 2>&1; then + echo "UpdateVM not started, exiting!" + exit 1 +fi + +# dd is supposed to not allow memory exhaustion +# grep does basic sanity checking +# there seems to be no way to pass output of date +%s.%N to date, +# so we use human-readable format + +CURRENT_TIME="$($QREXEC_CLIENT -d $UPDATES_VM 'user:date -u' | + dd count=1 2>/dev/null | + grep '^[A-Za-z]* [A-Za-z]* [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [A-Z]* [0-9][0-9][0-9][0-9]$'| + head -1)" + +if [ -n "$CURRENT_TIME" ] ; then + echo Syncing Dom0 clock: setting time "$CURRENT_TIME"... + sudo date -u -s "$CURRENT_TIME" ; + echo Done. +else + echo "Error while parsing the time obtained from the UpdateVM ($UPDATES_VM).." +fi +