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