]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Check if we have a valid distribution configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Oct 2024 16:01:36 +0000 (16:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Oct 2024 16:01:36 +0000 (16:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 4917f8cccfef8f2e30bf2bbc2e31f45dd5af60de..ef43e394287f620897c994f16fe698080fdfc72d 100644 (file)
@@ -565,24 +565,16 @@ const char* pakfire_get_distro_version_id(struct pakfire* pakfire) {
 const char* pakfire_get_distro_tag(struct pakfire* pakfire) {
        int r;
 
-       if (*pakfire->distro.tag)
-               return pakfire->distro.tag;
-
-       const char* id         = pakfire_get_distro_id(pakfire);
-       const char* version_id = pakfire_get_distro_version_id(pakfire);
-
-       // Break if the configuration is incomplete
-       if (!id || !version_id) {
-               errno = EINVAL;
-               return NULL;
+       // Generate the tag
+       if (!*pakfire->distro.tag) {
+               r = pakfire_string_format(pakfire->distro.tag,
+                               "%s%s", pakfire->distro.id, pakfire->distro.version_id);
+               if (r < 0) {
+                       errno = -r;
+                       return NULL;
+               }
        }
 
-       // Format string
-       r = pakfire_string_format(pakfire->distro.tag, "%s%s", id, version_id);
-       if (r < 0)
-               return NULL;
-
-       // Return the tag
        return pakfire->distro.tag;
 }
 
@@ -995,6 +987,13 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx*
        if (*p->distro.slogan)
                CTX_DEBUG(p->ctx, "    slogan     = %s\n", p->distro.slogan);
 
+       // Check if the distribution has been configured
+       if (!*p->distro.id || !*p->distro.version_id) {
+               CTX_ERROR(p->ctx, "Invalid distribution configuration\n");
+               r = -EINVAL;
+               goto ERROR;
+       }
+
        // Bump RLIMIT_NOFILE to maximum
        r = pakfire_rlimit_set(p, PAKFIRE_RLIMIT_NOFILE_MAX);
        if (r)