rpm/0010-Only-process-regular-f...

50 lines
1.7 KiB
Diff

From 29f756e3fba09f6a66515970978367829862f35c Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 5 Jan 2017 12:13:54 +0200
Subject: [PATCH] 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.
(cherry picked from commit 1ce844ab263bf49ee6d5145ed09e73f2c17924cc)
---
build/files.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/build/files.c b/build/files.c
index 2ede463a1..ca041764f 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);
}
}