5b4d983
From eb21562bcec67746e756679a60995f68d7d45577 Mon Sep 17 00:00:00 2001
5b4d983
Message-Id: <eb21562bcec67746e756679a60995f68d7d45577.1488964568.git.pmatilai@redhat.com>
5b4d983
In-Reply-To: <189b4f88c8e100155ec23a1e0b214bdc8473532a.1488964568.git.pmatilai@redhat.com>
5b4d983
References: <189b4f88c8e100155ec23a1e0b214bdc8473532a.1488964568.git.pmatilai@redhat.com>
5b4d983
From: Panu Matilainen <pmatilai@redhat.com>
5b4d983
Date: Thu, 5 Jan 2017 12:13:54 +0200
5b4d983
Subject: [PATCH 07/11] Only process regular files when generating build-ids
5b4d983
5b4d983
Versioned shared libraries typically have several symlinks pointing
5b4d983
to them directly and indirectly. When %_build_id_links is set to compat or
5b4d983
separate this causes bogus warnings about duplicate build-ids.
5b4d983
5b4d983
It looks commit bbfe1f86b2e4b5c0bd499d9f3dd9de9c9c20fff2 intends to skip
5b4d983
symlinks since it filters on S_ISREG(), but since uses fstat()
5b4d983
on already open()'ed file it ends up stat()'ing the symlink target.
5b4d983
Flip stat() + open() around and use lstat() instead to fix it.
5b4d983
---
5b4d983
 build/files.c | 11 +++++------
5b4d983
 1 file changed, 5 insertions(+), 6 deletions(-)
5b4d983
5b4d983
diff --git a/build/files.c b/build/files.c
5b4d983
index 2ede463..ca04176 100644
5b4d983
--- a/build/files.c
5b4d983
+++ b/build/files.c
5b4d983
@@ -1678,11 +1678,10 @@ static int generateBuildIDs(FileList fl)
5b4d983
     int needMain = 0;
5b4d983
     int needDbg = 0;
5b4d983
     for (i = 0, flp = fl->files.recs; i < fl->files.used; i++, flp++) {
5b4d983
-	int fd;
5b4d983
-	fd = open (flp->diskPath, O_RDONLY);
5b4d983
-	if (fd >= 0) {
5b4d983
-	    struct stat sbuf;
5b4d983
-	    if (fstat (fd, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
5b4d983
+	struct stat sbuf;
5b4d983
+	if (lstat(flp->diskPath, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
5b4d983
+	    int fd = open (flp->diskPath, O_RDONLY);
5b4d983
+	    if (fd >= 0) {
5b4d983
 		Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
5b4d983
 		if (elf != NULL && elf_kind(elf) == ELF_K_ELF) {
5b4d983
 		    const void *build_id;
5b4d983
@@ -1748,8 +1747,8 @@ static int generateBuildIDs(FileList fl)
5b4d983
 		    }
5b4d983
 		    elf_end (elf);
5b4d983
 		}
5b4d983
+		close (fd);
5b4d983
 	    }
5b4d983
-	    close (fd);
5b4d983
 	}
5b4d983
     }
5b4d983
 
5b4d983
-- 
5b4d983
2.9.3
5b4d983