summaryrefslogtreecommitdiff
path: root/rpmio/rpmfileutil.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-05-21 14:52:19 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-05-21 15:15:34 +0300
commit7df78ae46646b7aecb32b2bc541c24fffc9090fa (patch)
treec8e02b1bdb5890f0949bdae9087debee2c181b41 /rpmio/rpmfileutil.c
parent50b03d015e673366cdf0ad4caaf3137736db7f8a (diff)
downloadrpm-7df78ae46646b7aecb32b2bc541c24fffc9090fa.tar.gz
Split prelink checking into a helper function
- No functional changes, just makes the thing a little bit more readable as the ELF details are buried out of sight in the helper
Diffstat (limited to 'rpmio/rpmfileutil.c')
-rw-r--r--rpmio/rpmfileutil.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c
index 7c229e67b..d9c9f5b4c 100644
--- a/rpmio/rpmfileutil.c
+++ b/rpmio/rpmfileutil.c
@@ -36,6 +36,47 @@
static const char *rpm_config_dir = NULL;
+static int is_prelinked(int fdno)
+{
+ int prelinked = 0;
+#if HAVE_GELF_H && HAVE_LIBELF
+ Elf *elf = NULL;
+ Elf_Scn *scn = NULL;
+ Elf_Data *data = NULL;
+ GElf_Ehdr ehdr;
+ GElf_Shdr shdr;
+ GElf_Dyn dyn;
+
+ (void) elf_version(EV_CURRENT);
+
+ if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL ||
+ elf_kind(elf) != ELF_K_ELF || gelf_getehdr(elf, &ehdr) == NULL ||
+ !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
+ goto exit;
+
+ while (!prelinked && (scn = elf_nextscn(elf, scn)) != NULL) {
+ (void) gelf_getshdr(scn, &shdr);
+ if (shdr.sh_type != SHT_DYNAMIC)
+ continue;
+ while (!prelinked && (data = elf_getdata (scn, data)) != NULL) {
+ int maxndx = data->d_size / shdr.sh_entsize;
+
+ for (int ndx = 0; ndx < maxndx; ++ndx) {
+ (void) gelf_getdyn (data, ndx, &dyn);
+ if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
+ continue;
+ prelinked = 1;
+ break;
+ }
+ }
+ }
+
+exit:
+ if (elf) (void) elf_end(elf);
+#endif
+ return prelinked;
+}
+
static int open_dso(const char * path, pid_t * pidp, rpm_loff_t *fsizep)
{
static const char * cmd = NULL;
@@ -63,43 +104,7 @@ static int open_dso(const char * path, pid_t * pidp, rpm_loff_t *fsizep)
if (!(cmd && *cmd))
return fdno;
-#if HAVE_GELF_H && HAVE_LIBELF
- { Elf *elf = NULL;
- Elf_Scn *scn = NULL;
- Elf_Data *data = NULL;
- GElf_Ehdr ehdr;
- GElf_Shdr shdr;
- GElf_Dyn dyn;
- int bingo;
-
- (void) elf_version(EV_CURRENT);
-
- if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
- || elf_kind(elf) != ELF_K_ELF
- || gelf_getehdr(elf, &ehdr) == NULL
- || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
- goto exit;
-
- bingo = 0;
- while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) {
- (void) gelf_getshdr(scn, &shdr);
- if (shdr.sh_type != SHT_DYNAMIC)
- continue;
- while (!bingo && (data = elf_getdata (scn, data)) != NULL) {
- int maxndx = data->d_size / shdr.sh_entsize;
- int ndx;
-
- for (ndx = 0; ndx < maxndx; ++ndx) {
- (void) gelf_getdyn (data, ndx, &dyn);
- if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
- continue;
- bingo = 1;
- break;
- }
- }
- }
-
- if (pidp != NULL && bingo) {
+ if (pidp != NULL && is_prelinked(fdno)) {
int pipes[2];
pid_t pid;
int xx;
@@ -126,11 +131,6 @@ static int open_dso(const char * path, pid_t * pidp, rpm_loff_t *fsizep)
xx = close(pipes[1]);
}
-exit:
- if (elf) (void) elf_end(elf);
- }
-#endif
-
return fdno;
}