diff options
-rw-r--r-- | bitbake/lib/bb/daemonize.py | 42 |
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) |