Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mail.openembedded.org (Postfix) with ESMTP id 34E3078313 for ; Tue, 13 Jun 2017 16:21:56 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2017 09:21:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,338,1493708400"; d="scan'208";a="980326555" Received: from juro-precision-t5610.jf.intel.com ([10.7.198.53]) by orsmga003.jf.intel.com with ESMTP; 13 Jun 2017 09:21:55 -0700 From: Juro Bystricky To: bitbake-devel@lists.openembedded.org Date: Tue, 13 Jun 2017 09:21:54 -0700 Message-Id: <1497370914-1618-1-git-send-email-juro.bystricky@intel.com> X-Mailer: git-send-email 2.7.4 Cc: richard.purdie@intel.com, jurobystricky@hotmail.com, paul.eggleton@linux.intel.com Subject: [PATCH v2] bitbake:process: flush stderr/stdout to log X-BeenThere: bitbake-devel@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussion that advance bitbake development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jun 2017 16:22:00 -0000 When a process terminates, some messages may still remain in stdout or stderr and do not make it into the log file. In addition, the messages that do make it to the log file may end up in the log file in incorrect order. This patch flushes all messages into the log file after the process terminates. Some additional log flushing is also needed to keep the various messages showing up in the log file in proper order. [YOCTO#10785] Signed-off-by: Juro Bystricky --- bitbake/lib/bb/process.py | 79 ++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/bitbake/lib/bb/process.py b/bitbake/lib/bb/process.py index a4a5599..e69697c 100644 --- a/bitbake/lib/bb/process.py +++ b/bitbake/lib/bb/process.py @@ -94,45 +94,52 @@ def _logged_communicate(pipe, log, input, extrafiles): if data is not None: func(data) + def read_all_pipes(log, rin, outdata, errdata): + rlist = rin + stdoutbuf = b"" + stderrbuf = b"" + + try: + r,w,e = select.select (rlist, [], [], 1) + except OSError as e: + if e.errno != errno.EINTR: + raise + + readextras(r) + + if pipe.stdout in r: + data = stdoutbuf + pipe.stdout.read() + if data is not None and len(data) > 0: + try: + data = data.decode("utf-8") + outdata.append(data) + log.write(data) + log.flush() + stdoutbuf = b"" + except UnicodeDecodeError: + stdoutbuf = data + + if pipe.stderr in r: + data = stderrbuf + pipe.stderr.read() + if data is not None and len(data) > 0: + try: + data = data.decode("utf-8") + errdata.append(data) + log.write(data) + log.flush() + stderrbuf = b"" + except UnicodeDecodeError: + stderrbuf = data + try: + # Read all pipes while the process is open while pipe.poll() is None: - rlist = rin - stdoutbuf = b"" - stderrbuf = b"" - try: - r,w,e = select.select (rlist, [], [], 1) - except OSError as e: - if e.errno != errno.EINTR: - raise - - if pipe.stdout in r: - data = stdoutbuf + pipe.stdout.read() - if data is not None and len(data) > 0: - try: - data = data.decode("utf-8") - outdata.append(data) - log.write(data) - stdoutbuf = b"" - except UnicodeDecodeError: - stdoutbuf = data - - if pipe.stderr in r: - data = stderrbuf + pipe.stderr.read() - if data is not None and len(data) > 0: - try: - data = data.decode("utf-8") - errdata.append(data) - log.write(data) - stderrbuf = b"" - except UnicodeDecodeError: - stderrbuf = data - - readextras(r) - - finally: - log.flush() + read_all_pipes(log, rin, outdata, errdata) - readextras([fobj for fobj, _ in extrafiles]) + # Pocess closed, drain all pipes... + read_all_pipes(log, rin, outdata, errdata) + finally: + log.flush() if pipe.stdout is not None: pipe.stdout.close() -- 2.7.4