7 #if defined(HAVE_GELF_H)
8 #if LIBELF_H_LFS_CONFLICT
12 # undef _LARGEFILE64_SOURCE
13 # undef _LARGEFILE_SOURCE
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
17 #if defined(__LCLINT__)
19 typedef long long loff_t;
24 #if !defined(DT_GNU_PRELINKED)
25 #define DT_GNU_PRELINKED 0x6ffffdf5
27 #if !defined(DT_GNU_LIBLIST)
28 #define DT_GNU_LIBLIST 0x6ffffef9
39 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
49 static int open_dso(
const char * path, pid_t * pidp,
size_t *fsizep)
55 static const char * cmd = NULL;
56 static int oneshot = 0;
60 cmd =
rpmExpand(
"%{?__prelink_undo_cmd}", NULL);
67 struct stat sb, * st = &sb;
68 if (stat(path, st) < 0)
70 *fsizep = (size_t)st->st_size;
73 fdno = open(path, O_RDONLY);
80 #if defined(HAVE_GELF_H) && defined(HAVE_LIBELF)
83 Elf_Data *data = NULL;
89 (void) elf_version(EV_CURRENT);
92 if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
93 || elf_kind(elf) != ELF_K_ELF
94 || gelf_getehdr(elf, &ehdr) == NULL
95 || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
100 while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) {
101 (void) gelf_getshdr(scn, &shdr);
102 if (shdr.sh_type != SHT_DYNAMIC)
104 while (!bingo && (data = elf_getdata (scn, data)) != NULL) {
105 unsigned maxndx = (unsigned) (data->d_size / shdr.sh_entsize);
108 for (ndx = 0; ndx < maxndx; ++ndx) {
110 (void) gelf_getdyn (data, ndx, &dyn);
112 if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
120 if (pidp != NULL && bingo) {
126 pipes[0] = pipes[1] = -1;
128 if (!(pid = fork())) {
131 xx = close(pipes[0]);
132 xx = dup2(pipes[1], STDOUT_FILENO);
133 xx = close(pipes[1]);
134 if (!poptParseArgvString(cmd, &ac, &av)) {
138 xx = execve(av[0], (
char *
const *)av+1, environ);
144 xx = close(pipes[1]);
148 if (elf) (void) elf_end(elf);
156 int dodigest(
int digestalgo,
const char * fn,
unsigned char * digest,
int asAscii,
size_t *fsizep)
160 unsigned char * dsum = NULL;
162 unsigned char buf[32*BUFSIZ];
169 #if defined(HAVE_MMAP)
174 fdno =
open_dso(path, &pid, &fsize);
182 use_mmap = (pid == 0 && fsize <= 0x07ffffff);
187 #if defined(HAVE_MMAP)
190 void * mapped = NULL;
193 mapped = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fdno, 0);
194 if (mapped == (
void *)-1) {
200 #if defined(HAVE_MADVISE) && defined(MADV_SEQUENTIAL)
201 xx = madvise(mapped, fsize, MADV_SEQUENTIAL);
210 xx = munmap(mapped, fsize);
222 fd = (pid != 0) ?
fdDup(fdno) :
Fopen(fn,
"r.fdio");
224 if (fd == NULL ||
Ferror(fd)) {
233 while ((rc = (
int)
Fread(buf,
sizeof(buf[0]),
sizeof(buf), fd)) > 0)
247 (void) waitpid(pid, &status, 0);
249 if (!WIFEXITED(status) || WEXITSTATUS(status))
257 memcpy(digest, dsum, dlen);