diff options
Diffstat (limited to 'bitbake/lib/bb/daemonize.py')
-rw-r--r-- | bitbake/lib/bb/daemonize.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py index c187fcfc6c..7689404436 100644 --- a/bitbake/lib/bb/daemonize.py +++ b/bitbake/lib/bb/daemonize.py | |||
@@ -1,4 +1,6 @@ | |||
1 | # | 1 | # |
2 | # Copyright BitBake Contributors | ||
3 | # | ||
2 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
3 | # | 5 | # |
4 | 6 | ||
@@ -74,26 +76,26 @@ def createDaemon(function, logfile): | |||
74 | with open('/dev/null', 'r') as si: | 76 | with open('/dev/null', 'r') as si: |
75 | os.dup2(si.fileno(), sys.stdin.fileno()) | 77 | os.dup2(si.fileno(), sys.stdin.fileno()) |
76 | 78 | ||
77 | try: | 79 | with open(logfile, 'a+') as so: |
78 | so = open(logfile, 'a+') | 80 | try: |
79 | os.dup2(so.fileno(), sys.stdout.fileno()) | 81 | os.dup2(so.fileno(), sys.stdout.fileno()) |
80 | os.dup2(so.fileno(), sys.stderr.fileno()) | 82 | os.dup2(so.fileno(), sys.stderr.fileno()) |
81 | except io.UnsupportedOperation: | 83 | except io.UnsupportedOperation: |
82 | sys.stdout = open(logfile, 'a+') | 84 | sys.stdout = so |
83 | 85 | ||
84 | # Have stdout and stderr be the same so log output matches chronologically | 86 | # Have stdout and stderr be the same so log output matches chronologically |
85 | # and there aren't two seperate buffers | 87 | # and there aren't two separate buffers |
86 | sys.stderr = sys.stdout | 88 | sys.stderr = sys.stdout |
87 | 89 | ||
88 | try: | 90 | try: |
89 | function() | 91 | function() |
90 | except Exception as e: | 92 | except Exception as e: |
91 | traceback.print_exc() | 93 | traceback.print_exc() |
92 | finally: | 94 | finally: |
93 | bb.event.print_ui_queue() | 95 | bb.event.print_ui_queue() |
94 | # os._exit() doesn't flush open files like os.exit() does. Manually flush | 96 | # 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 | 97 | # stdout and stderr so that any logging output will be seen, particularly |
96 | # exception tracebacks. | 98 | # exception tracebacks. |
97 | sys.stdout.flush() | 99 | sys.stdout.flush() |
98 | sys.stderr.flush() | 100 | sys.stderr.flush() |
99 | os._exit(0) | 101 | os._exit(0) |