summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-02 11:06:55 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-03 10:12:42 +0000
commit791d6e63be09b361dd3397707a0507399b9a9ce7 (patch)
tree90b98176d8f9863d20498e53c4089dee762c7cc2 /bitbake
parent9abab49f2bcac3ea80f96f837e181904bfae8848 (diff)
downloadpoky-791d6e63be09b361dd3397707a0507399b9a9ce7.tar.gz
bitbake: daemonize: Avoid unclosed file warning
In theory we can leak the so file descriptor so refactor the code to avoid that. (Bitbake rev: dfad69d4d8c894a5e1e2686023e41552de09bf3b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/daemonize.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py
index c187fcfc6c..40fabd0c0a 100644
--- a/bitbake/lib/bb/daemonize.py
+++ b/bitbake/lib/bb/daemonize.py
@@ -74,26 +74,26 @@ def createDaemon(function, logfile):
74 with open('/dev/null', 'r') as si: 74 with open('/dev/null', 'r') as si:
75 os.dup2(si.fileno(), sys.stdin.fileno()) 75 os.dup2(si.fileno(), sys.stdin.fileno())
76 76
77 try: 77 with open(logfile, 'a+') as so:
78 so = open(logfile, 'a+') 78 try:
79 os.dup2(so.fileno(), sys.stdout.fileno()) 79 os.dup2(so.fileno(), sys.stdout.fileno())
80 os.dup2(so.fileno(), sys.stderr.fileno()) 80 os.dup2(so.fileno(), sys.stderr.fileno())
81 except io.UnsupportedOperation: 81 except io.UnsupportedOperation:
82 sys.stdout = open(logfile, 'a+') 82 sys.stdout = so
83 83
84 # Have stdout and stderr be the same so log output matches chronologically 84 # Have stdout and stderr be the same so log output matches chronologically
85 # and there aren't two seperate buffers 85 # and there aren't two seperate buffers
86 sys.stderr = sys.stdout 86 sys.stderr = sys.stdout
87 87
88 try: 88 try:
89 function() 89 function()
90 except Exception as e: 90 except Exception as e:
91 traceback.print_exc() 91 traceback.print_exc()
92 finally: 92 finally:
93 bb.event.print_ui_queue() 93 bb.event.print_ui_queue()
94 # os._exit() doesn't flush open files like os.exit() does. Manually flush 94 # os._exit() doesn't flush open files like os.exit() does. Manually flush
95 # stdout and stderr so that any logging output will be seen, particularly 95 # stdout and stderr so that any logging output will be seen, particularly
96 # exception tracebacks. 96 # exception tracebacks.
97 sys.stdout.flush() 97 sys.stdout.flush()
98 sys.stderr.flush() 98 sys.stderr.flush()
99 os._exit(0) 99 os._exit(0)