mirror of
https://github.com/openembedded/meta-openembedded.git
synced 2025-07-19 15:29:08 +02:00

0002-run_program-support-timeout.patch 0003-support-infinit-timeout.patch 0005-fix-incorrect-timeout-while-system-time-changed.patch 0006-tweak-btrfs-packages.patch 0007-invoking-mount-with-infinite-timeout.patch 0008-use-oe-variable-to-replace-hardcoded-dir.patch 0010-invoking-mkfs-with-infinite-timeout.patch 0011-invoking-dd-with-infinite-timeout.patch refreshed for 3.9.1 Signed-off-by: Wang Mingyu <wangmy@fujitsu.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
101 lines
3.7 KiB
Diff
101 lines
3.7 KiB
Diff
From 8a18a6c1dea7cce6669d0eeb4230e85aa88d8e44 Mon Sep 17 00:00:00 2001
|
|
From: Hongxu Jia <hongxu.jia@windriver.com>
|
|
Date: Fri, 23 Nov 2018 17:03:58 +0800
|
|
Subject: [PATCH 02/11] run_program support timeout
|
|
|
|
Upstream-Status: Pending
|
|
|
|
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
|
|
---
|
|
blivet/util.py | 70 +++++++++++++++++++++++++++++---------------------
|
|
1 file changed, 41 insertions(+), 29 deletions(-)
|
|
|
|
diff --git a/blivet/util.py b/blivet/util.py
|
|
index f8a8f88..a5da7b6 100644
|
|
--- a/blivet/util.py
|
|
+++ b/blivet/util.py
|
|
@@ -171,6 +171,30 @@ class Path(str):
|
|
def __hash__(self):
|
|
return self._path.__hash__()
|
|
|
|
+def timeout_command(argv, timeout, *args, **kwargs):
|
|
+ """call shell-command and either return its output or kill it
|
|
+ if it doesn't normally exit within timeout seconds and return None"""
|
|
+ import subprocess, datetime, os, time, signal
|
|
+ start = datetime.datetime.now()
|
|
+
|
|
+ try:
|
|
+ proc = subprocess.Popen(argv, *args, **kwargs)
|
|
+ while proc.poll() is None:
|
|
+ time.sleep(0.1)
|
|
+ now = datetime.datetime.now()
|
|
+ if (now - start).seconds> timeout:
|
|
+ os.kill(proc.pid, signal.SIGKILL)
|
|
+ os.waitpid(-1, os.WNOHANG)
|
|
+ program_log.debug("%d seconds timeout" % timeout)
|
|
+ return (-1, None)
|
|
+
|
|
+
|
|
+ except OSError as e:
|
|
+ program_log.error("Error running %s: %s", argv[0], e.strerror)
|
|
+ raise
|
|
+
|
|
+ program_log.debug("Return code: %d", proc.returncode)
|
|
+ return (proc.returncode, proc.stdout.read())
|
|
|
|
def _run_program(argv, root='/', stdin=None, env_prune=None, stderr_to_stdout=False, binary_output=False):
|
|
if env_prune is None:
|
|
@@ -193,35 +217,23 @@ def _run_program(argv, root='/', stdin=None, env_prune=None, stderr_to_stdout=Fa
|
|
stderr_dir = subprocess.STDOUT
|
|
else:
|
|
stderr_dir = subprocess.PIPE
|
|
- try:
|
|
- proc = subprocess.Popen(argv, # pylint: disable=subprocess-popen-preexec-fn
|
|
- stdin=stdin,
|
|
- stdout=subprocess.PIPE,
|
|
- stderr=stderr_dir,
|
|
- close_fds=True,
|
|
- preexec_fn=chroot, cwd=root, env=env)
|
|
-
|
|
- out, err = proc.communicate()
|
|
- if not binary_output and six.PY3:
|
|
- out = out.decode("utf-8")
|
|
- if out:
|
|
- if not stderr_to_stdout:
|
|
- program_log.info("stdout:")
|
|
- for line in out.splitlines():
|
|
- program_log.info("%s", line)
|
|
-
|
|
- if not stderr_to_stdout and err:
|
|
- program_log.info("stderr:")
|
|
- for line in err.splitlines():
|
|
- program_log.info("%s", line)
|
|
-
|
|
- except OSError as e:
|
|
- program_log.error("Error running %s: %s", argv[0], e.strerror)
|
|
- raise
|
|
-
|
|
- program_log.debug("Return code: %d", proc.returncode)
|
|
-
|
|
- return (proc.returncode, out)
|
|
+
|
|
+ res, out = timeout_command(argv, 10,
|
|
+ stdin=stdin,
|
|
+ stdout=subprocess.PIPE,
|
|
+ stderr=stderr_dir,
|
|
+ close_fds=True,
|
|
+ preexec_fn=chroot, cwd=root, env=env)
|
|
+ if not binary_output and six.PY3:
|
|
+ out = out.decode("utf-8")
|
|
+ if out:
|
|
+ if not stderr_to_stdout:
|
|
+ program_log.info("stdout:")
|
|
+ for line in out.splitlines():
|
|
+ program_log.info("%s", line)
|
|
+
|
|
+ return (res, out)
|
|
+
|
|
|
|
|
|
def run_program(*args, **kwargs):
|