]> git.ipfire.org Git - pakfire.git/commitdiff
execute: Move faking architecture into libpakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 May 2021 10:01:51 +0000 (10:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 May 2021 10:01:51 +0000 (10:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/execute.c
src/pakfire/builder.py

index a75da8e67ad6e31aa7f9fda2c5e9bf9228465bc2..143e78bb657d0c4fbad2f9d3a43858ecccc56093 100644 (file)
@@ -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)
index 20ae0f655eb7bd6a853b7eda0dc0640b14f0c100..5317edacbde9a14a3cd5569b43332664e32fb272 100644 (file)
@@ -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,
                )