diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-08-24 17:12:30 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-08-25 18:14:53 +0100 |
| commit | 7002d67de02206fca0782c3373e915de20a71e9e (patch) | |
| tree | ea6b56cbd121d617801220dc42ed12bb1399fcff /bitbake/bin | |
| parent | 6bab132879c0abf6f2b1670174445766198d3cac (diff) | |
| download | poky-7002d67de02206fca0782c3373e915de20a71e9e.tar.gz | |
bitbake: server/process: Add bitbake-server and exec() a new server process
Trying to have a new python process forked off an original doesn't work
out well and ends up having race issues. To avoid this, exec() a new
bitbake server process. This starts with a fresh python interpreter
and resolves various atexit and other multiprocessing issues once
and for all.
(Bitbake rev: 9501dd6fdd7a7c25cbfa4464cf881fcf8c049ce2)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
| -rwxr-xr-x | bitbake/bin/bitbake-server | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake-server b/bitbake/bin/bitbake-server new file mode 100755 index 0000000000..ffbc7894ef --- /dev/null +++ b/bitbake/bin/bitbake-server | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 4 | # | ||
| 5 | # Copyright (C) 2020 Richard Purdie | ||
| 6 | # | ||
| 7 | |||
| 8 | import os | ||
| 9 | import sys | ||
| 10 | import warnings | ||
| 11 | import logging | ||
| 12 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) | ||
| 13 | |||
| 14 | if sys.getfilesystemencoding() != "utf-8": | ||
| 15 | sys.exit("Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).\nPython can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.") | ||
| 16 | |||
| 17 | # Users shouldn't be running this code directly | ||
| 18 | if len(sys.argv) != 10 or not sys.argv[1].startswith("decafbad"): | ||
| 19 | print("bitbake-server is meant for internal execution by bitbake itself, please don't use it standalone.") | ||
| 20 | sys.exit(1) | ||
| 21 | |||
| 22 | import bb.server.process | ||
| 23 | |||
| 24 | lockfd = int(sys.argv[2]) | ||
| 25 | readypipeinfd = int(sys.argv[3]) | ||
| 26 | logfile = sys.argv[4] | ||
| 27 | lockname = sys.argv[5] | ||
| 28 | sockname = sys.argv[6] | ||
| 29 | timeout = sys.argv[7] | ||
| 30 | xmlrpcinterface = (sys.argv[8], int(sys.argv[9])) | ||
| 31 | if xmlrpcinterface[0] == "None": | ||
| 32 | xmlrpcinterface = (None, xmlrpcinterface[1]) | ||
| 33 | if timeout == "None": | ||
| 34 | timeout = None | ||
| 35 | |||
| 36 | # Replace standard fds with our own | ||
| 37 | with open('/dev/null', 'r') as si: | ||
| 38 | os.dup2(si.fileno(), sys.stdin.fileno()) | ||
| 39 | |||
| 40 | so = open(logfile, 'a+') | ||
| 41 | os.dup2(so.fileno(), sys.stdout.fileno()) | ||
| 42 | os.dup2(so.fileno(), sys.stderr.fileno()) | ||
| 43 | |||
| 44 | # Have stdout and stderr be the same so log output matches chronologically | ||
| 45 | # and there aren't two seperate buffers | ||
| 46 | sys.stderr = sys.stdout | ||
| 47 | |||
| 48 | logger = logging.getLogger("BitBake") | ||
| 49 | # Ensure logging messages get sent to the UI as events | ||
| 50 | handler = bb.event.LogHandler() | ||
| 51 | logger.addHandler(handler) | ||
| 52 | |||
| 53 | bb.server.process.execServer(lockfd, readypipeinfd, lockname, sockname, timeout, xmlrpcinterface) | ||
| 54 | |||
