1#!/usr/bin/env python3 2# 3# SPDX-License-Identifier: GPL-2.0-only 4# 5# Copyright (C) 2020 Richard Purdie 6# 7 8import os 9import sys 10import warnings 11warnings.simplefilter("default") 12import logging 13sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) 14 15if sys.getfilesystemencoding() != "utf-8": 16 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.") 17 18# Users shouldn't be running this code directly 19if len(sys.argv) != 10 or not sys.argv[1].startswith("decafbad"): 20 print("bitbake-server is meant for internal execution by bitbake itself, please don't use it standalone.") 21 sys.exit(1) 22 23import bb.server.process 24 25lockfd = int(sys.argv[2]) 26readypipeinfd = int(sys.argv[3]) 27logfile = sys.argv[4] 28lockname = sys.argv[5] 29sockname = sys.argv[6] 30timeout = float(sys.argv[7]) 31xmlrpcinterface = (sys.argv[8], int(sys.argv[9])) 32if xmlrpcinterface[0] == "None": 33 xmlrpcinterface = (None, xmlrpcinterface[1]) 34 35# Replace standard fds with our own 36with open('/dev/null', 'r') as si: 37 os.dup2(si.fileno(), sys.stdin.fileno()) 38 39so = open(logfile, 'a+') 40os.dup2(so.fileno(), sys.stdout.fileno()) 41os.dup2(so.fileno(), sys.stderr.fileno()) 42 43# Have stdout and stderr be the same so log output matches chronologically 44# and there aren't two seperate buffers 45sys.stderr = sys.stdout 46 47logger = logging.getLogger("BitBake") 48# Ensure logging messages get sent to the UI as events 49handler = bb.event.LogHandler() 50logger.addHandler(handler) 51 52bb.server.process.execServer(lockfd, readypipeinfd, lockname, sockname, timeout, xmlrpcinterface) 53 54