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.
		
			
				
	
	
		
			12 lines
		
	
	
		
			332 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			12 lines
		
	
	
		
			332 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/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"
 |