/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.32 Revision 1.33
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2005 Gentoo Foundation 3 * Copyright 1999-2005 Gentoo Foundation
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.32 2005/04/07 00:01:40 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.33 2005/04/10 15:15:40 solar Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 10 * published by the Free Software Foundation; either version 2 of the
33#include <getopt.h> 33#include <getopt.h>
34#include <assert.h> 34#include <assert.h>
35 35
36#include "paxelf.h" 36#include "paxelf.h"
37 37
38static const char *rcsid = "$Id: scanelf.c,v 1.32 2005/04/07 00:01:40 vapier Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.33 2005/04/10 15:15:40 solar Exp $";
39 39
40 40
41/* helper functions for showing errors */ 41/* helper functions for showing errors */
42#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ 42#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
43#define warn(fmt, args...) \ 43#define warn(fmt, args...) \
81{ 81{
82 int i; 82 int i;
83 char found_pax, found_stack, found_relro, found_textrel, 83 char found_pax, found_stack, found_relro, found_textrel,
84 found_rpath, found_needed, found_sym; 84 found_rpath, found_needed, found_sym;
85 elfobj *elf; 85 elfobj *elf;
86 struct stat st;
86 87
88 /* make sure path exists */
89 if (lstat(filename, &st) == -1)
90 return;
91 if (!S_ISREG(st.st_mode))
92 return;
87 found_pax = found_stack = found_relro = found_textrel = \ 93 found_pax = found_stack = found_relro = found_textrel = \
88 found_rpath = found_needed = found_sym = 0; 94 found_rpath = found_needed = found_sym = 0;
89 95
90 /* verify this is real ELF */ 96 /* verify this is real ELF */
91 if ((elf = readelf(filename)) == NULL) { 97 if ((elf = readelf(filename)) == NULL) {
160 dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \ 166 dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \
161 while (EGET(dyn->d_tag) != DT_NULL) { \ 167 while (EGET(dyn->d_tag) != DT_NULL) { \
162 if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \ 168 if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \
163 found_textrel = 1; \ 169 found_textrel = 1; \
164 /*if (dyn->d_un.d_val & DF_TEXTREL)*/ \ 170 /*if (dyn->d_un.d_val & DF_TEXTREL)*/ \
165 printf("TEXTREL "); \ 171 fputs("TEXTREL ", stdout); \
166 } \ 172 } \
167 ++dyn; \ 173 ++dyn; \
168 } \ 174 } \
169 } } 175 } }
170 SHOW_TEXTREL(32) 176 SHOW_TEXTREL(32)
171 SHOW_TEXTREL(64) 177 SHOW_TEXTREL(64)
172 if (!be_quiet && !found_textrel) printf("------- "); 178 if (!be_quiet && !found_textrel) fputs("------- ", stdout);
173 } 179 }
174 180
175 /* rpath fun */ 181 /* rpath fun */
176 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */ 182 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */
177 if (show_rpath) { 183 if (show_rpath) {
303 free(versioned_symname); 309 free(versioned_symname);
304 if (*find_sym != '*') { 310 if (*find_sym != '*') {
305 if (found_sym) 311 if (found_sym)
306 printf(" %s ", find_sym); 312 printf(" %s ", find_sym);
307 else if (!be_quiet) 313 else if (!be_quiet)
308 printf(" - "); 314 fputs(" - ", stdout);
309 } 315 }
310 } 316 }
311 317
312 if (!be_quiet || found_pax || found_stack || found_textrel || \ 318 if (!be_quiet || found_pax || found_stack || found_textrel || \
313 found_rpath || found_needed || found_sym) 319 found_rpath || found_needed || found_sym)
314 printf("%s\n", filename); 320 puts(filename);
315 321
316 unreadelf(elf); 322 unreadelf(elf);
317} 323}
318 324
319/* scan a directory for ET_EXEC files and print when we find one */ 325/* scan a directory for ET_EXEC files and print when we find one */
400} 406}
401 407
402/* scan env PATH for paths */ 408/* scan env PATH for paths */
403static void scanelf_envpath() 409static void scanelf_envpath()
404{ 410{
405 char *path, *p; 411 char *orig_path, *path, *p;
406 412
407 path = getenv("PATH"); 413 path = getenv("PATH");
408 if (!path) 414 if (!path)
409 err("PATH is not set in your env !"); 415 err("PATH is not set in your env !");
410 416
411 if ((path = strdup(path)) == NULL) 417 if ((orig_path = path = strdup(path)) == NULL)
412 err("strdup failed: %s", strerror(errno)); 418 err("strdup failed: %s", strerror(errno));
413 419
414 while ((p = strrchr(path, ':')) != NULL) { 420 while ((p = strrchr(path, ':')) != NULL) {
415 scanelf_dir(p + 1); 421 scanelf_dir(p + 1);
416 *p = 0; 422 *p = 0;
417 } 423 }
418 424
419 free(path); 425 free(orig_path);
420} 426}
421 427
422 428
423 429
424/* usage / invocation handling functions */ 430/* usage / invocation handling functions */

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

  ViewVC Help
Powered by ViewVC 1.1.20