diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-09-12 10:49:54 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-09-12 23:55:29 +0100 |
commit | e2c25f4bd0e03b2751e39d47636f6eef6456ebab (patch) | |
tree | 003fce02a4213d7f5101707c8e3006591c9e3fce | |
parent | 1bb49ce3228ae429c84830ecc0826092fd3bd072 (diff) | |
download | poky-e2c25f4bd0e03b2751e39d47636f6eef6456ebab.tar.gz |
bitbake: server/process: ensure server failure log is limited to current session
Printing the last 10 lines of bitbake-cookerdaemon.log when the server
fails to start can sometimes result in printing the output from a
previous run, which could lead the user completely down the wrong path
in terms of the cause of the failure. Use a known start text containing
the time which we can then look for when scanning through the log, and
then grab the last 10 lines of that part instead.
Fixes [YOCTO #11903].
(Bitbake rev: 567f2cf1bc455b4f3cfb1cbd7f25145360b05a62)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/server/process.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 6a12f01057..29f87cd2ff 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
@@ -33,6 +33,8 @@ import select | |||
33 | import socket | 33 | import socket |
34 | import subprocess | 34 | import subprocess |
35 | import errno | 35 | import errno |
36 | import re | ||
37 | import datetime | ||
36 | import bb.server.xmlrpcserver | 38 | import bb.server.xmlrpcserver |
37 | from bb import daemonize | 39 | from bb import daemonize |
38 | from multiprocessing import queues | 40 | from multiprocessing import queues |
@@ -358,6 +360,9 @@ class BitBakeProcessServerConnection(object): | |||
358 | return | 360 | return |
359 | 361 | ||
360 | class BitBakeServer(object): | 362 | class BitBakeServer(object): |
363 | start_log_format = '--- Starting bitbake server pid %s at %s ---' | ||
364 | start_log_datetime_format = '%Y-%m-%d %H:%M:%S.%f' | ||
365 | |||
361 | def __init__(self, lock, sockname, configuration, featureset): | 366 | def __init__(self, lock, sockname, configuration, featureset): |
362 | 367 | ||
363 | self.configuration = configuration | 368 | self.configuration = configuration |
@@ -383,6 +388,7 @@ class BitBakeServer(object): | |||
383 | self.sock.listen(1) | 388 | self.sock.listen(1) |
384 | 389 | ||
385 | os.set_inheritable(self.sock.fileno(), True) | 390 | os.set_inheritable(self.sock.fileno(), True) |
391 | startdatetime = datetime.datetime.now() | ||
386 | bb.daemonize.createDaemon(self._startServer, logfile) | 392 | bb.daemonize.createDaemon(self._startServer, logfile) |
387 | self.sock.close() | 393 | self.sock.close() |
388 | self.bitbake_lock.close() | 394 | self.bitbake_lock.close() |
@@ -395,15 +401,31 @@ class BitBakeServer(object): | |||
395 | ready.close() | 401 | ready.close() |
396 | bb.error("Unable to start bitbake server") | 402 | bb.error("Unable to start bitbake server") |
397 | if os.path.exists(logfile): | 403 | if os.path.exists(logfile): |
404 | logstart_re = re.compile(self.start_log_format % ('([0-9]+)', '([0-9-]+ [0-9:.]+)')) | ||
405 | started = False | ||
406 | lines = [] | ||
398 | with open(logfile, "r") as f: | 407 | with open(logfile, "r") as f: |
399 | logs=f.readlines() | 408 | for line in f: |
400 | bb.error("Last 10 lines of server log %s:\n%s" % (logfile, "".join(logs[-10:]))) | 409 | if started: |
410 | lines.append(line) | ||
411 | else: | ||
412 | res = logstart_re.match(line.rstrip()) | ||
413 | if res: | ||
414 | ldatetime = datetime.datetime.strptime(res.group(2), self.start_log_datetime_format) | ||
415 | if ldatetime >= startdatetime: | ||
416 | started = True | ||
417 | lines.append(line) | ||
418 | if lines: | ||
419 | if len(lines) > 10: | ||
420 | bb.error("Last 10 lines of server log for this session (%s):\n%s" % (logfile, "".join(lines[-10:]))) | ||
421 | else: | ||
422 | bb.error("Server log for this session (%s):\n%s" % (logfile, "".join(lines))) | ||
401 | raise SystemExit(1) | 423 | raise SystemExit(1) |
402 | ready.close() | 424 | ready.close() |
403 | os.close(self.readypipein) | 425 | os.close(self.readypipein) |
404 | 426 | ||
405 | def _startServer(self): | 427 | def _startServer(self): |
406 | print("Starting bitbake server pid %d" % os.getpid()) | 428 | print(self.start_log_format % (os.getpid(), datetime.datetime.now().strftime(self.start_log_datetime_format))) |
407 | server = ProcessServer(self.bitbake_lock, self.sock, self.sockname) | 429 | server = ProcessServer(self.bitbake_lock, self.sock, self.sockname) |
408 | self.configuration.setServerRegIdleCallback(server.register_idle_function) | 430 | self.configuration.setServerRegIdleCallback(server.register_idle_function) |
409 | writer = ConnectionWriter(self.readypipein) | 431 | writer = ConnectionWriter(self.readypipein) |