[v2,1/1] bitbake: bitbake-worker: Preserve network non-local uid

Message ID 43c4b99b0f28af12d82fa5ce659b2a84798c22d3.1642747927.git.liezhi.yang@windriver.com
State Accepted, archived
Commit 4eafae7904bae6e5c6bc50356e8a9077f2e207fa
Headers show
Series [v2,1/1] bitbake: bitbake-worker: Preserve network non-local uid | expand

Commit Message

Robert Yang Jan. 21, 2022, 6:52 a.m. UTC
The NIS can't work when network is dissable, so preserve network for it, the
error is like:

do_ypcall: clnt_call: RPC: Unable to send; errno = Network is unreachable

Note, enable nscd on the build machine might be a solution, but that isn't
reliable since it depends on whether the network function has been cached or
not.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 bitbake/bin/bitbake-worker |  7 +++++--
 bitbake/lib/bb/utils.py    | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

Patch

diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker
index 3aaf3c2444b..063cf379262 100755
--- a/bitbake/bin/bitbake-worker
+++ b/bitbake/bin/bitbake-worker
@@ -262,8 +262,11 @@  def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha
                 bb.utils.set_process_name("%s:%s" % (the_data.getVar("PN"), taskname.replace("do_", "")))
 
                 if not the_data.getVarFlag(taskname, 'network', False):
-                    logger.debug("Attempting to disable network")
-                    bb.utils.disable_network(uid, gid)
+                    if bb.utils.is_local_uid(uid):
+                        logger.debug("Attempting to disable network for %s" % taskname)
+                        bb.utils.disable_network(uid, gid)
+                    else:
+                        logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid))
 
                 # exported_vars() returns a generator which *cannot* be passed to os.environ.update() 
                 # successfully. We also need to unset anything from the environment which shouldn't be there 
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 0312231933b..128b3ab5708 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1735,3 +1735,19 @@  def environment(**envvars):
                 os.environ[var] = backup[var]
             else:
                 del os.environ[var]
+
+def is_local_uid(uid=''):
+    """
+    Check whether uid is a local one or not.
+    Can't use pwd module since it gets all UIDs, not local ones only.
+    """
+    if not uid:
+        uid = os.getuid()
+    with open('/etc/passwd', 'r') as f:
+        for line in f:
+            line_split = line.split(':')
+            if len(line_split) < 3:
+                continue
+            if str(uid) == line_split[2]:
+                return True
+    return False