blob: ecb95039d04cda1f386bce45252ed82765dd8483 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From b30a74671ca603e6bfd514f72d4fd7fd6fceef54 Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Fri, 26 Aug 2016 02:02:49 -0400
4Subject: [PATCH 05/11] fix incorrect timeout while system time changed
5
6While system time changed by NTP, invoking timeout_command
7breaks with incorrect timeout.
8--------
9|05:40:55,872 INFO program: Running... mount -t ext2 -o
10 defaults,ro /dev/sda2 /mnt/sysimage
11|01:40:55,086 DEBUG program: 10 seconds timeout
12--------
13
14Use numbert count to replace current time count could workaround
15the issue.
16
17Upstream-Status: Pending
18
19Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
20---
21 blivet/util.py | 6 +++---
22 1 file changed, 3 insertions(+), 3 deletions(-)
23
24diff --git a/blivet/util.py b/blivet/util.py
25index d6804be..bc08af5 100644
26--- a/blivet/util.py
27+++ b/blivet/util.py
28@@ -162,14 +162,14 @@ def timeout_command(argv, timeout, *args, **kwargs):
29 """call shell-command and either return its output or kill it
30 if it doesn't normally exit within timeout seconds and return None"""
31 import subprocess, datetime, os, time, signal
32- start = datetime.datetime.now()
33+ count = 0
34
35 try:
36 proc = subprocess.Popen(argv, *args, **kwargs)
37 while proc.poll() is None:
38 time.sleep(0.1)
39- now = datetime.datetime.now()
40- if timeout != -1 and (now - start).seconds> timeout:
41+ count += 1
42+ if timeout != -1 and count > timeout*10:
43 os.kill(proc.pid, signal.SIGKILL)
44 os.waitpid(-1, os.WNOHANG)
45 program_log.debug("%d seconds timeout" % timeout)
46--
472.7.4
48