diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-09-04 15:54:12 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-09-05 18:01:37 +0100 |
commit | 74feaddda3b7cd5b3ab18d2f25bf5ef9581c9c47 (patch) | |
tree | 0e5d4c72d97ba4c0669aaf8394439778ea5ed33e | |
parent | b7e26bedc2952e4ac0edface4bd20be22d7708cd (diff) | |
download | poky-74feaddda3b7cd5b3ab18d2f25bf5ef9581c9c47.tar.gz |
bitbake: server/process: Various server startup logging fixes
There were various problems in the server startup loggin:
a) stdout/stderr were not being flushed before forking which could potentially
duplicate output
b) there were separate buffers for stdout/stderr leading to confusing logs
where the entries could be reordered. This was particularly confusing
due to the separator the logs use to idendify new messages
c) an fd wasn't being closed during server startup meaning if the
server failed to start, the closed fd wasn't detected as it was held
open by the other reference
d) If the pipe was detected as being closed, the code incorrectly retried
server startup
e) The event code would remap stdout/stderr without flushing them, leading
to lose log messages
(Bitbake rev: 0594faa0b52ce5dbd948d836d88617d38d9862d1)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/daemonize.py | 12 | ||||
-rw-r--r-- | bitbake/lib/bb/event.py | 3 | ||||
-rw-r--r-- | bitbake/lib/bb/server/process.py | 20 |
3 files changed, 22 insertions, 13 deletions
diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py index bf16793468..613fb35536 100644 --- a/bitbake/lib/bb/daemonize.py +++ b/bitbake/lib/bb/daemonize.py | |||
@@ -16,6 +16,10 @@ def createDaemon(function, logfile): | |||
16 | background as a daemon, returning control to the caller. | 16 | background as a daemon, returning control to the caller. |
17 | """ | 17 | """ |
18 | 18 | ||
19 | # Ensure stdout/stderror are flushed before forking to avoid duplicate output | ||
20 | sys.stdout.flush() | ||
21 | sys.stderr.flush() | ||
22 | |||
19 | try: | 23 | try: |
20 | # Fork a child process so the parent can exit. This returns control to | 24 | # Fork a child process so the parent can exit. This returns control to |
21 | # the command-line or shell. It also guarantees that the child will not | 25 | # the command-line or shell. It also guarantees that the child will not |
@@ -66,12 +70,14 @@ def createDaemon(function, logfile): | |||
66 | 70 | ||
67 | try: | 71 | try: |
68 | so = open(logfile, 'a+') | 72 | so = open(logfile, 'a+') |
69 | se = so | ||
70 | os.dup2(so.fileno(), sys.stdout.fileno()) | 73 | os.dup2(so.fileno(), sys.stdout.fileno()) |
71 | os.dup2(se.fileno(), sys.stderr.fileno()) | 74 | os.dup2(so.fileno(), sys.stderr.fileno()) |
72 | except io.UnsupportedOperation: | 75 | except io.UnsupportedOperation: |
73 | sys.stdout = open(logfile, 'a+') | 76 | sys.stdout = open(logfile, 'a+') |
74 | sys.stderr = sys.stdout | 77 | |
78 | # Have stdout and stderr be the same so log output matches chronologically | ||
79 | # and there aren't two seperate buffers | ||
80 | sys.stderr = sys.stdout | ||
75 | 81 | ||
76 | try: | 82 | try: |
77 | function() | 83 | function() |
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index c0ec605209..5b1b094a80 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
@@ -141,6 +141,9 @@ def print_ui_queue(): | |||
141 | logger = logging.getLogger("BitBake") | 141 | logger = logging.getLogger("BitBake") |
142 | if not _uiready: | 142 | if not _uiready: |
143 | from bb.msg import BBLogFormatter | 143 | from bb.msg import BBLogFormatter |
144 | # Flush any existing buffered content | ||
145 | sys.stdout.flush() | ||
146 | sys.stderr.flush() | ||
144 | stdout = logging.StreamHandler(sys.stdout) | 147 | stdout = logging.StreamHandler(sys.stdout) |
145 | stderr = logging.StreamHandler(sys.stderr) | 148 | stderr = logging.StreamHandler(sys.stderr) |
146 | formatter = BBLogFormatter("%(levelname)s: %(message)s") | 149 | formatter = BBLogFormatter("%(levelname)s: %(message)s") |
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 9e5e709f04..38b923fe2d 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
@@ -395,11 +395,16 @@ class BitBakeServer(object): | |||
395 | bb.daemonize.createDaemon(self._startServer, logfile) | 395 | bb.daemonize.createDaemon(self._startServer, logfile) |
396 | self.sock.close() | 396 | self.sock.close() |
397 | self.bitbake_lock.close() | 397 | self.bitbake_lock.close() |
398 | os.close(self.readypipein) | ||
398 | 399 | ||
399 | ready = ConnectionReader(self.readypipe) | 400 | ready = ConnectionReader(self.readypipe) |
400 | r = ready.poll(30) | 401 | r = ready.poll(30) |
401 | if r: | 402 | if r: |
402 | r = ready.get() | 403 | try: |
404 | r = ready.get() | ||
405 | except EOFError: | ||
406 | # Trap the child exitting/closing the pipe and error out | ||
407 | r = None | ||
403 | if not r or r != "ready": | 408 | if not r or r != "ready": |
404 | ready.close() | 409 | ready.close() |
405 | bb.error("Unable to start bitbake server") | 410 | bb.error("Unable to start bitbake server") |
@@ -425,21 +430,16 @@ class BitBakeServer(object): | |||
425 | bb.error("Server log for this session (%s):\n%s" % (logfile, "".join(lines))) | 430 | bb.error("Server log for this session (%s):\n%s" % (logfile, "".join(lines))) |
426 | raise SystemExit(1) | 431 | raise SystemExit(1) |
427 | ready.close() | 432 | ready.close() |
428 | os.close(self.readypipein) | ||
429 | 433 | ||
430 | def _startServer(self): | 434 | def _startServer(self): |
431 | print(self.start_log_format % (os.getpid(), datetime.datetime.now().strftime(self.start_log_datetime_format))) | 435 | print(self.start_log_format % (os.getpid(), datetime.datetime.now().strftime(self.start_log_datetime_format))) |
432 | server = ProcessServer(self.bitbake_lock, self.sock, self.sockname) | 436 | server = ProcessServer(self.bitbake_lock, self.sock, self.sockname) |
433 | self.configuration.setServerRegIdleCallback(server.register_idle_function) | 437 | self.configuration.setServerRegIdleCallback(server.register_idle_function) |
438 | os.close(self.readypipe) | ||
434 | writer = ConnectionWriter(self.readypipein) | 439 | writer = ConnectionWriter(self.readypipein) |
435 | try: | 440 | self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset) |
436 | self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset) | 441 | writer.send("ready") |
437 | writer.send("ready") | 442 | writer.close() |
438 | except: | ||
439 | writer.send("fail") | ||
440 | raise | ||
441 | finally: | ||
442 | os.close(self.readypipein) | ||
443 | server.cooker = self.cooker | 443 | server.cooker = self.cooker |
444 | server.server_timeout = self.configuration.server_timeout | 444 | server.server_timeout = self.configuration.server_timeout |
445 | server.xmlrpcinterface = self.configuration.xmlrpcinterface | 445 | server.xmlrpcinterface = self.configuration.xmlrpcinterface |