From 7e6d4e45d92fd51f42812ae63ac6e532887bfe0a Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Mon, 13 Dec 2010 16:25:36 -0800 Subject: [PATCH] Close inherited PIPE before doing work Gmake in Darwin has file descriptor leak. In a full build, ota_from_target_files will inherits more than 2000 open PIPEs from gmake and fails in a call to select.select(). This change fixes the build by closing the PIPEs before doing real work. Change-Id: Ie7035d7add0b1da3afb6bf9c2009d40f8c7d29b3 --- tools/releasetools/common.py | 17 +++++++++++++++++ tools/releasetools/img_from_target_files | 1 + tools/releasetools/ota_from_target_files | 1 + 3 files changed, 19 insertions(+) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 3cc86bfb7..a7413a009 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -18,6 +18,7 @@ import getopt import getpass import imp import os +import platform import re import shutil import subprocess @@ -63,6 +64,22 @@ def Run(args, **kwargs): return subprocess.Popen(args, **kwargs) +def CloseInheritedPipes(): + """ Gmake in MAC OS has file descriptor (PIPE) leak. We close those fds + before doing other work.""" + if platform.system() != "Darwin": + return + for d in range(3, 1025): + try: + stat = os.fstat(d) + if stat is not None: + pipebit = stat[0] & 0x1000 + if pipebit != 0: + os.close(d) + except OSError: + pass + + def LoadInfoDict(zip): """Read and parse the META/misc_info.txt key/value pairs from the input target files and return a dict.""" diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files index 08817caa3..c5b98868b 100755 --- a/tools/releasetools/img_from_target_files +++ b/tools/releasetools/img_from_target_files @@ -201,6 +201,7 @@ def main(argv): if __name__ == '__main__': try: + common.CloseInheritedPipes() main(sys.argv[1:]) except common.ExternalError, e: print diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files index 79c546526..8f5c3fe86 100755 --- a/tools/releasetools/ota_from_target_files +++ b/tools/releasetools/ota_from_target_files @@ -807,6 +807,7 @@ def main(argv): if __name__ == '__main__': try: + common.CloseInheritedPipes() main(sys.argv[1:]) except common.ExternalError, e: print -- 2.11.0