qvm-sync-clock: sync dom0 clock only when NTP sync succeeded, even with --force
Otherwise dom0 clock (initially almost ok) may be adjusted to totally invalid timestamp of ClockVM (for example just after resume from S3 sleep).
This commit is contained in:
parent
3f19157d2f
commit
3ece17a8cf
@ -94,24 +94,24 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print >> sys.stderr, 'Time sync failed! - Exiting'
|
print >> sys.stderr, 'Time sync failed! - Exiting'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
# Use the date format based on RFC2822 to avoid localisation issues
|
||||||
|
p = clock_vm.run('date -u -Iseconds', verbose=options.verbose,
|
||||||
|
gui=False, passio_popen=True, ignore_stderr=True)
|
||||||
|
date_out = p.stdout.read(100)
|
||||||
|
date_out = date_out.strip()
|
||||||
|
if not re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+0000$', date_out):
|
||||||
|
print >> sys.stderr, 'Invalid date output, aborting!'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Use the date format based on RFC2822 to avoid localisation issues
|
# Sync dom0 time
|
||||||
p = clock_vm.run('date -u -Iseconds', verbose=options.verbose,
|
if options.verbose:
|
||||||
gui=False, passio_popen=True, ignore_stderr=True)
|
print >> sys.stderr, '--> Syncing dom0 clock.'
|
||||||
date_out = p.stdout.read(100)
|
|
||||||
date_out = date_out.strip()
|
|
||||||
if not re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+0000$', date_out):
|
|
||||||
print >> sys.stderr, 'Invalid date output, aborting!'
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Sync dom0 time
|
subprocess.check_call(['sudo', 'date', '-u', '-Iseconds', '-s', date_out],
|
||||||
if options.verbose:
|
stdout=None if options.verbose else open(os.devnull, 'w'))
|
||||||
print >> sys.stderr, '--> Syncing dom0 clock.'
|
subprocess.check_call(['sudo', 'hwclock', '--systohc'],
|
||||||
|
stdout=None if options.verbose else open(os.devnull, 'w'))
|
||||||
subprocess.check_call(['sudo', 'date', '-u', '-Iseconds', '-s', date_out],
|
|
||||||
stdout=None if options.verbose else open(os.devnull, 'w'))
|
|
||||||
subprocess.check_call(['sudo', 'hwclock', '--systohc'],
|
|
||||||
stdout=None if options.verbose else open(os.devnull, 'w'))
|
|
||||||
|
|
||||||
# Sync other VMs clock
|
# Sync other VMs clock
|
||||||
for vm in qvm_collection.values():
|
for vm in qvm_collection.values():
|
||||||
|
Loading…
Reference in New Issue
Block a user