Bläddra i källkod

Introduce qubes.SetDateTime service for time synchronization

It would be called by qvm-sync-clock instead of 'date' directly. This
gives a lot of flexibility - VM can control whether it want to sync time
this way. For now slight corrections (+-2sec) are ignored to not cause
problems by frequent time changes. But it can be easily extended to
refuse time sync when some other mechanism is used.
Marek Marczykowski-Górecki 9 år sedan
förälder
incheckning
7339dd1ece
3 ändrade filer med 13 tillägg och 0 borttagningar
  1. 1 0
      Makefile
  2. 11 0
      qubes-rpc/qubes.SetDateTime
  3. 1 0
      rpm_spec/core-vm.spec

+ 1 - 0
Makefile

@@ -167,6 +167,7 @@ install-common:
 	install -m 0644 qubes-rpc/qubes.{Backup,Restore} $(DESTDIR)/etc/qubes-rpc
 	install -m 0644 qubes-rpc/qubes.Select{File,Directory} $(DESTDIR)/etc/qubes-rpc
 	install -m 0644 qubes-rpc/qubes.GetImageRGBA $(DESTDIR)/etc/qubes-rpc
+	install -m 0644 qubes-rpc/qubes.SetDateTime $(DESTDIR)/etc/qubes-rpc
 
 	install -d $(DESTDIR)/usr/share/file-manager/actions
 	install -m 0644 qubes-rpc/*-gnome.desktop $(DESTDIR)/usr/share/file-manager/actions

+ 11 - 0
qubes-rpc/qubes.SetDateTime

@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# it is in format of `date -u -Iseconds`, example: 2014-09-29T22:59:21+0000
+# it comes from dom0, so is trusted
+read timestamp
+timediff=$(( `date -u +'+%Y%m%d%H%M%S'` - `date -u -d "$timestamp" +'+%Y%m%d%H%M%S'` ))
+if [ $timediff -le 2 -a $timediff -ge -2 ]; then
+    # don't bother
+    exit 0
+fi
+date -u -s "$timestamp"

+ 1 - 0
rpm_spec/core-vm.spec

@@ -320,6 +320,7 @@ rm -f %{name}-%{version}
 /etc/qubes-rpc/qubes.SelectFile
 /etc/qubes-rpc/qubes.SelectDirectory
 /etc/qubes-rpc/qubes.GetImageRGBA
+/etc/qubes-rpc/qubes.SetDateTime
 %config(noreplace) /etc/sudoers.d/qubes
 %config(noreplace) /etc/sysconfig/iptables
 %config(noreplace) /etc/sysconfig/ip6tables