2011-08-02 14:12:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2011-10-01 02:52:56 +02:00
|
|
|
CLOCK_VM=`qvm-get-clockvm`
|
2011-08-02 14:12:03 +02:00
|
|
|
|
|
|
|
QREXEC_CLIENT=/usr/lib/qubes/qrexec_client
|
|
|
|
|
2011-10-01 02:52:56 +02:00
|
|
|
if [ -z "$CLOCK_VM" ]; then
|
|
|
|
echo "ClockVM not set, exiting!" >&2
|
2011-08-02 14:12:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-10-01 02:52:56 +02:00
|
|
|
if ! xl domid "$CLOCK_VM" > /dev/null 2>&1; then
|
|
|
|
echo "ClockVM not started, exiting!"
|
2011-08-02 14:12:03 +02:00
|
|
|
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
|
|
|
|
|
2011-10-01 02:52:56 +02:00
|
|
|
CURRENT_TIME="$($QREXEC_CLIENT -d $CLOCK_VM 'user:date -u' |
|
2011-08-02 14:12:03 +02:00
|
|
|
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
|
2011-10-01 02:52:56 +02:00
|
|
|
echo "Error while parsing the time obtained from the ClockVM ($CLOCK_VM).."
|
2011-08-02 14:12:03 +02:00
|
|
|
fi
|
|
|
|
|