From 08f3e677d6af27a41a918aaa9da9c1c9b20a0b95 Mon Sep 17 00:00:00 2001 From: Yang Xu Date: Fri, 2 Feb 2024 09:36:02 +0000 Subject: bitbake-worker: Fix silent hang issue caused by unexpected stdout content This patch addresses an issue in bitbake-worker where stdout, reserved for status reporting, is improperly accessed by child processes. The problem occurs during the execution of parseRecipe, which calls anonymous functions. If these functions use print-like operations, they can inadvertently output data to stdout. This unexpected data can cause the runqueue to hang silently, if the stdout buffer is flushed before exec_task is executed. To prevent this, the patch redirects stdout to /dev/null and ensures it is flushed prior to the execution of exec_task. Signed-off-by: Yang Xu Signed-off-by: Richard Purdie --- bin/bitbake-worker | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/bitbake-worker b/bin/bitbake-worker index 577651386..e8073f2ac 100755 --- a/bin/bitbake-worker +++ b/bin/bitbake-worker @@ -237,9 +237,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): # Let SIGHUP exit as SIGTERM signal.signal(signal.SIGHUP, sigterm_handler) - # No stdin - newsi = os.open(os.devnull, os.O_RDWR) - os.dup2(newsi, sys.stdin.fileno()) + # No stdin & stdout + # stdout is used as a status report channel and must not be used by child processes. + dumbio = os.open(os.devnull, os.O_RDWR) + os.dup2(dumbio, sys.stdin.fileno()) + os.dup2(dumbio, sys.stdout.fileno()) if umask is not None: os.umask(umask) @@ -305,6 +307,10 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): if not quieterrors: logger.critical(traceback.format_exc()) os._exit(1) + + sys.stdout.flush() + sys.stderr.flush() + try: if dry_run: return 0 -- cgit 1.2.3-korg