]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
arch: Change how the native architecture is being returned
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 08:02:20 +0000 (08:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 08:02:20 +0000 (08:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/arch.c
src/pakfire/arch.h
src/pakfire/root.c

index 02923876b3accc5ef3b93b221bfb0c31fe4ec25c..3ba60c2f36483f4798de84fbe5135634ca464d59 100644 (file)
@@ -176,15 +176,21 @@ int __pakfire_arch_buildtarget(char* buffer, size_t length, const char* arch, co
        return 0;
 }
 
-const char* pakfire_arch_native(void) {
+int pakfire_arch_native(const char** arch) {
        static struct utsname utsname = {};
+       int r;
 
+       // Fetch uname() data only once
        if (!*utsname.machine) {
-               if (uname(&utsname) < 0)
-                       return NULL;
+               r = uname(&utsname);
+               if (r < 0)
+                       return -errno;
        }
 
-       return utsname.machine;
+       // Return the architecture
+       *arch = utsname.machine;
+
+       return 0;
 }
 
 int pakfire_arch_is_compatible(const char* name, const char* compatible_arch) {
@@ -212,12 +218,18 @@ int pakfire_arch_is_compatible(const char* name, const char* compatible_arch) {
        which might not be the same as the requested architecture.
 */
 static const char* pakfire_arch_is_natively_supported_by_host(const char* name) {
+       const char* native_arch = NULL;
+       int r;
+
        if (!name) {
                errno = EINVAL;
                return NULL;
        }
 
-       const char* native_arch = pakfire_arch_native();
+       // Fetch the native architecture
+       r = pakfire_arch_native(&native_arch);
+       if (r < 0)
+               return NULL;
 
        // All hosts support noarch natively
        if (pakfire_string_equals(name, "noarch"))
index e02a0475fbcdd393f4bcda3e4d1621d1b49c897c..eaf3f4d14bb86a5291ea4f8c7d60cf4996c48659 100644 (file)
@@ -23,7 +23,7 @@
 
 int pakfire_arch_supported(const char* name);
 const char** pakfire_supported_arches(void);
-const char* pakfire_arch_native(void);
+int pakfire_arch_native(const char** arch);
 
 const char* pakfire_arch_is_supported_by_host(const char* name);
 
index 3f46034549f561bd7a53e127853e06d36cfe973d..5ffac3cb37361fb69f80375cfc21f5efdd794459 100644 (file)
@@ -981,8 +981,11 @@ int pakfire_root_create(pakfire_root** root, pakfire_ctx* ctx,
                return -EINVAL;
 
        // Default to the native architecture
-       if (!arch)
-               arch = pakfire_arch_native();
+       if (!arch) {
+               r = pakfire_arch_native(&arch);
+               if (r < 0)
+                       return r;
+       }
 
        // Check path
        if (path) {