]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Do not fail when /etc/os-release does not exist
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 15:59:49 +0000 (15:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 15:59:49 +0000 (15:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 7fe81c9158da83130e3eb187093a6f0e3c082715..552fd3d563ad64fb79bc0f4c3f512e6379ec9107 100644 (file)
@@ -392,7 +392,9 @@ static int pakfire_safety_checks(Pakfire pakfire) {
 }
 
 static int pakfire_read_os_release(Pakfire pakfire) {
-       int r = 0;
+       char* line = NULL;
+       size_t l = 0;
+       int r = 1;
 
        char* path = pakfire_make_path(pakfire, "/etc/os-release");
        if (!path)
@@ -400,14 +402,15 @@ static int pakfire_read_os_release(Pakfire pakfire) {
 
        FILE* f = fopen(path, "r");
        if (!f) {
+               // Ignore when the file does not exist
+               if (errno == ENOENT)
+                       goto ERROR;
+
                ERROR(pakfire, "Could not open %s: %s\n", path, strerror(errno));
-               r = -1;
+               r = 1;
                goto ERROR;
        }
 
-       char* line = NULL;
-       size_t l = 0;
-
        while (1) {
                ssize_t bytes_read = getline(&line, &l, f);
                if (bytes_read < 0)
@@ -520,7 +523,7 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char
 
        // Read /etc/os-release
        r = pakfire_read_os_release(p);
-       if (r)
+       if (r && errno != ENOENT)
                goto ERROR;
 
        DEBUG(p, "Pakfire initialized at %p\n", p);