From: Michael Tremer Date: Fri, 21 May 2021 10:01:51 +0000 (+0000) Subject: execute: Move faking architecture into libpakfire X-Git-Tag: 0.9.28~1285^2~110 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=63064d3b7d820b48940d23e92f457ea04634932f;p=pakfire.git execute: Move faking architecture into libpakfire Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/execute.c b/src/libpakfire/execute.c index a75da8e67..143e78bb6 100644 --- a/src/libpakfire/execute.c +++ b/src/libpakfire/execute.c @@ -399,6 +399,10 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en .cgroup = "pakfire/execute-XXXXXX", }; + // Fetch architectures + const char* native_arch = pakfire_arch_native(); + const char* arch = pakfire_get_arch(pakfire); + // argv is invalid if (!argv || !argv[0]) return -EINVAL; @@ -489,6 +493,17 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en } } + // Fake architecture + if (strcmp(arch, native_arch) != 0) { + r = set_environ(&env, "LD_PRELOAD", "/usr/lib/libpakfire_preload.so"); + if (r) + goto ERROR; + + r = set_environ(&env, "UTS_MACHINE", arch); + if (r) + goto ERROR; + } + // Make cgroup name r = pakfire_cgroup_random_name(env.cgroup); if (r) diff --git a/src/pakfire/builder.py b/src/pakfire/builder.py index 20ae0f655..5317edacb 100644 --- a/src/pakfire/builder.py +++ b/src/pakfire/builder.py @@ -144,21 +144,6 @@ class BuilderContext(object): # Get a reference to the logger self.log = self.builder.log - @property - def environ(self): - # Build a minimal environment for executing, but try to inherit TERM and LANG - env = {} - - # Fake UTS_MACHINE, when we cannot use the personality syscall and - # if the host architecture is not equal to the target architecture. - if not _pakfire.native_arch() == self.pakfire.arch: - env.update({ - "LD_PRELOAD" : "/usr/lib/libpakfire_preload.so", - "UTS_MACHINE" : self.pakfire.arch, - }) - - return env - def _setup(self): """ Sets up the environment by installing some basic packages @@ -230,7 +215,7 @@ class BuilderContext(object): # Run it try: self.pakfire.execute_script(script, logging_callback=self.log.log, - environ=self.environ, enable_network=False, interactive=False) + enable_network=False, interactive=False) # Handle if the build script failed except CommandExecutionError as e: @@ -262,6 +247,5 @@ class BuilderContext(object): ["/usr/bin/bash", "--login"], interactive=True, enable_network=True, - environ=self.environ, )