public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Mike Frysinger (vapier)" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c
Date: Mon, 23 Jan 2012 23:48:54 +0000 (UTC)	[thread overview]
Message-ID: <20120123234854.8E22C2004B@flycatcher.gentoo.org> (raw)

vapier      12/01/23 23:48:54

  Modified:             scanelf.c
  Log:
  add --use-ldpath option that considers ld.so.conf when outputting full paths for %n

Revision  Changes    Path
1.240                pax-utils/scanelf.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.240&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.240&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.239&r2=1.240

Index: scanelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
retrieving revision 1.239
retrieving revision 1.240
diff -u -r1.239 -r1.240
--- scanelf.c	23 Jan 2012 22:28:17 -0000	1.239
+++ scanelf.c	23 Jan 2012 23:48:54 -0000	1.240
@@ -1,13 +1,13 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.239 2012/01/23 22:28:17 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.240 2012/01/23 23:48:54 vapier Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-static const char rcsid[] = "$Id: scanelf.c,v 1.239 2012/01/23 22:28:17 vapier Exp $";
+static const char rcsid[] = "$Id: scanelf.c,v 1.240 2012/01/23 23:48:54 vapier Exp $";
 const char argv0[] = "scanelf";
 
 #include "paxinc.h"
@@ -55,6 +55,7 @@
 static char fix_elf = 0;
 static char g_match = 0;
 static char use_ldcache = 0;
+static char use_ldpath = 0;
 
 static char **qa_textrels = NULL;
 static char **qa_execstack = NULL;
@@ -801,7 +802,7 @@
 
 #if defined(__GLIBC__) || defined(__UCLIBC__)
 
-static char *lookup_cache_lib(elfobj *elf, char *fname)
+static char *lookup_cache_lib(elfobj *elf, const char *fname)
 {
 	int fd;
 	char *strs;
@@ -879,7 +880,7 @@
 }
 
 #elif defined(__NetBSD__)
-static char *lookup_cache_lib(elfobj *elf, char *fname)
+static char *lookup_cache_lib(elfobj *elf, const char *fname)
 {
 	static char buf[__PAX_UTILS_PATH_MAX] = "";
 	static struct stat st;
@@ -908,12 +909,27 @@
 #ifdef __ELF__
 #warning Cache support not implemented for your target
 #endif
-static char *lookup_cache_lib(elfobj *elf, char *fname)
+static char *lookup_cache_lib(elfobj *elf, const char *fname)
 {
 	return NULL;
 }
 #endif
 
+static char *lookup_config_lib(elfobj *elf, char *fname)
+{
+	static char buf[__PAX_UTILS_PATH_MAX] = "";
+	const char *ldpath;
+	size_t n;
+
+	array_for_each(ldpaths, n, ldpath) {
+		snprintf(buf, sizeof(buf), "%s/%s", root_rel_path(ldpath), fname);
+		if (faccessat(root_fd, buf, F_OK, AT_SYMLINK_NOFOLLOW) == 0)
+			return buf;
+	}
+
+	return NULL;
+}
+
 static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len)
 {
 	unsigned long i;
@@ -960,9 +976,13 @@
 						/* -n -> print all entries */ \
 						if (!be_wewy_wewy_quiet) { \
 							if (*found_needed) xchrcat(ret, ',', ret_len); \
-							if (use_ldcache) \
+							if (use_ldpath) { \
+								if ((p = lookup_config_lib(elf, needed)) != NULL) \
+									needed = p; \
+							} else if (use_ldcache) { \
 								if ((p = lookup_cache_lib(elf, needed)) != NULL) \
 									needed = p; \
+							} \
 							xstrcat(ret, needed, ret_len); \
 						} \
 						*found_needed = 1; \
@@ -1421,6 +1441,7 @@
 			case 't': prints("TEXTREL "); break;
 			case 'r': prints("RPATH "); break;
 			case 'M': prints("CLASS "); break;
+			case 'l':
 			case 'n': prints("NEEDED "); break;
 			case 'i': prints("INTERP "); break;
 			case 'b': prints("BIND "); break;
@@ -1747,7 +1768,7 @@
 
 #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__)
 
-static int load_ld_cache_config(int i, const char *fname)
+static int _load_ld_cache_config(const char *fname)
 {
 	FILE *fp = NULL;
 	char *p, *path;
@@ -1756,7 +1777,7 @@
 
 	fp = fopenat_r(root_fd, root_rel_path(fname));
 	if (fp == NULL)
-		return i;
+		return -1;
 
 	path = NULL;
 	len = 0;
@@ -1791,7 +1812,7 @@
 					/* try to avoid direct loops */
 					if (strcmp(gl.gl_pathv[x], fname) == 0)
 						continue;
-					i = load_ld_cache_config(i, gl.gl_pathv[x]);
+					_load_ld_cache_config(gl.gl_pathv[x]);
 				}
 				globfree(&gl);
 			}
@@ -1815,12 +1836,12 @@
 		close(curr_fd);
 	}
 
-	return i;
+	return 0;
 }
 
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
 
-static int load_ld_cache_config(int i, const char *fname)
+static int _load_ld_cache_config(const char *fname)
 {
 	FILE *fp = NULL;
 	char *b = NULL, *p;
@@ -1828,21 +1849,21 @@
 
 	fp = fopenat_r(root_fd, root_rel_path(fname));
 	if (fp == NULL)
-		return i;
+		return -1;
 
 	if (fread(&hdr, 1, sizeof(hdr), fp) != sizeof(hdr) ||
 	    hdr.magic != ELFHINTS_MAGIC || hdr.version != 1 ||
 	    fseek(fp, hdr.strtab + hdr.dirlist, SEEK_SET) == -1)
 	{
 		fclose(fp);
-		return i;
+		return -1;
 	}
 
 	b = xmalloc(hdr.dirlistlen + 1);
 	if (fread(b, 1, hdr.dirlistlen+1, fp) != hdr.dirlistlen+1) {
 		fclose(fp);
 		free(b);
-		return i;
+		return -1;
 	}
 
 	while ((p = strsep(&b, ":"))) {
@@ -1853,43 +1874,49 @@
 
 	free(b);
 	fclose(fp);
-	return i;
+	return 0;
 }
 
 #else
 #ifdef __ELF__
 #warning Cache config support not implemented for your target
 #endif
-static int load_ld_cache_config(int i, const char *fname)
+static int _load_ld_cache_config(const char *fname)
 {
 	return 0;
 }
 #endif
 
-/* scan /etc/ld.so.conf for paths */
-static void scanelf_ldpath(void)
+static void load_ld_cache_config(const char *fname)
 {
-	char scan_l, scan_ul, scan_ull;
+	bool scan_l, scan_ul, scan_ull;
 	size_t n;
 	const char *ldpath;
-	int i = 0;
 
-	if (array_cnt(ldpaths) == 0)
-		err("Unable to load any paths from ld.so.conf");
+	_load_ld_cache_config(fname);
 
-	scan_l = scan_ul = scan_ull = 0;
-
-	array_for_each(ldpaths, n, ldpath) {
-		if (!scan_l   && !strcmp(ldpath, "/lib"))           scan_l   = 1;
-		if (!scan_ul  && !strcmp(ldpath, "/usr/lib"))       scan_ul  = 1;
-		if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = 1;
-		scanelf_dir(ldpath);
-		++i;
+	scan_l = scan_ul = scan_ull = false;
+	if (array_cnt(ldpaths)) {
+		array_for_each(ldpaths, n, ldpath) {
+			if (!scan_l   && !strcmp(ldpath, "/lib"))           scan_l   = true;
+			if (!scan_ul  && !strcmp(ldpath, "/usr/lib"))       scan_ul  = true;
+			if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = true;
+		}
 	}
 
-	if (!scan_l)   scanelf_dir("/lib");
-	if (!scan_ul)  scanelf_dir("/usr/lib");
-	if (!scan_ull) scanelf_dir("/usr/local/lib");
+	if (!scan_l)   xarraypush_str(ldpaths, "/lib");
+	if (!scan_ul)  xarraypush_str(ldpaths, "/usr/lib");
+	if (!scan_ull) xarraypush_str(ldpaths, "/usr/local/lib");
+}
+
+/* scan /etc/ld.so.conf for paths */
+static void scanelf_ldpath(void)
+{
+	size_t n;
+	const char *ldpath;
+
+	array_for_each(ldpaths, n, ldpath)
+		scanelf_dir(ldpath);
 }
 
 /* scan env PATH for paths */
@@ -1916,6 +1943,7 @@
 static struct option const long_opts[] = {
 	{"path",      no_argument, NULL, 'p'},
 	{"ldpath",    no_argument, NULL, 'l'},
+	{"use-ldpath",no_argument, NULL, 129},
 	{"root",       a_argument, NULL, 128},
 	{"recursive", no_argument, NULL, 'R'},
 	{"mount",     no_argument, NULL, 'm'},
@@ -1960,6 +1988,7 @@
 static const char * const opts_help[] = {
 	"Scan all directories in PATH environment",
 	"Scan all directories in /etc/ld.so.conf",
+	"Use ld.so.conf to show full path (use with -r/-n)",
 	"Root directory (use with -l or -p)",
 	"Scan directories recursively",
 	"Don't recursively cross mount points",
@@ -2037,6 +2066,7 @@
 	int i;
 	const char *from_file = NULL;
 	int ret = 0;
+	char load_cache_config = 0;
 
 	opterr = 0;
 	while ((i=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) {
@@ -2135,12 +2165,12 @@
 		}
 		case 'Z': show_size = 1; break;
 		case 'g': g_match = 1; break;
-		case 'L': use_ldcache = 1; break;
+		case 'L': load_cache_config = use_ldcache = 1; break;
 		case 'y': scan_symlink = 0; break;
 		case 'A': scan_archives = 1; break;
 		case 'C': color_init(true); break;
 		case 'B': show_banner = 0; break;
-		case 'l': scan_ldpath = 1; break;
+		case 'l': load_cache_config = scan_ldpath = 1; break;
 		case 'p': scan_envpath = 1; break;
 		case 'R': dir_recurse = 1; break;
 		case 'm': dir_crossmount = 0; break;
@@ -2165,6 +2195,7 @@
 			if (root_fd == -1)
 				err("Could not open root: %s", optarg);
 			break;
+		case 129: load_cache_config = use_ldpath = 1; break;
 		case ':':
 			err("Option '%c' is missing parameter", optopt);
 		case '?':
@@ -2217,7 +2248,7 @@
 			case 'S': show_soname = 1; break;
 			case 'T': show_textrels = 1; break;
 			default:
-				err("Invalid format specifier '%c' (byte %i)",
+				err("invalid format specifier '%c' (byte %i)",
 				    out_format[i], i+1);
 			}
 		}
@@ -2250,8 +2281,8 @@
 	if (be_verbose > 2) printf("Format: %s\n", out_format);
 
 	/* now lets actually do the scanning */
-	if (scan_ldpath || use_ldcache)
-		load_ld_cache_config(0, __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG);
+	if (load_cache_config)
+		load_ld_cache_config(__PAX_UTILS_DEFAULT_LD_CACHE_CONFIG);
 	if (scan_ldpath) scanelf_ldpath();
 	if (scan_envpath) scanelf_envpath();
 	if (!from_file && optind == argc && ttyname(0) == NULL && !scan_ldpath && !scan_envpath)






             reply	other threads:[~2012-01-23 23:49 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-23 23:48 Mike Frysinger (vapier) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-02-28 22:59 [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c Mike Frysinger (vapier)
2015-02-24  6:58 Mike Frysinger (vapier)
2015-02-22  2:27 Mike Frysinger (vapier)
2015-02-22  1:38 Mike Frysinger (vapier)
2015-02-22  0:10 Mike Frysinger (vapier)
2015-02-21 19:30 Mike Frysinger (vapier)
2014-11-20  1:25 Mike Frysinger (vapier)
2014-11-05  2:02 Mike Frysinger (vapier)
2014-10-19  7:31 Mike Frysinger (vapier)
2014-03-21  5:33 Mike Frysinger (vapier)
2014-03-21  5:27 Mike Frysinger (vapier)
2014-03-20  8:08 Mike Frysinger (vapier)
2014-03-20  8:06 Mike Frysinger (vapier)
2014-01-11  0:28 Mike Frysinger (vapier)
2013-08-14 21:09 Mike Frysinger (vapier)
2013-04-16 16:22 Mike Frysinger (vapier)
2013-04-10 22:27 Mike Frysinger (vapier)
2013-04-08  6:38 Mike Frysinger (vapier)
2013-04-02 21:15 Mike Frysinger (vapier)
2012-11-30 23:25 Mike Frysinger (vapier)
2012-11-10  9:43 Mike Frysinger (vapier)
2012-11-04  8:25 Mike Frysinger (vapier)
2012-11-04  8:23 Mike Frysinger (vapier)
2012-11-04  7:48 Mike Frysinger (vapier)
2012-11-04  6:55 Mike Frysinger (vapier)
2012-08-04  6:08 Mike Frysinger (vapier)
2012-04-29  6:21 Mike Frysinger (vapier)
2012-04-29  5:41 Mike Frysinger (vapier)
2012-01-25  1:58 Mike Frysinger (vapier)
2012-01-23 22:28 Mike Frysinger (vapier)
2011-12-21 22:17 Mike Frysinger (vapier)
2011-12-21 22:00 Mike Frysinger (vapier)
2011-12-21 17:34 Mike Frysinger (vapier)
2011-12-13  5:12 Mike Frysinger (vapier)
2011-10-13  4:49 Mike Frysinger (vapier)
2011-09-27 22:20 Mike Frysinger (vapier)
2011-09-27 19:56 Mike Frysinger (vapier)
2011-09-27 19:29 Mike Frysinger (vapier)
2011-09-27 19:21 Mike Frysinger (vapier)
2011-09-27 19:20 Mike Frysinger (vapier)
2011-09-27 17:28 Mike Frysinger (vapier)
2011-08-08  1:56 Mike Frysinger (vapier)
2011-07-30 17:08 Ned Ludd (solar)
2010-12-06 20:43 Mike Frysinger (vapier)
2010-01-15 11:56 Mike Frysinger (vapier)
2009-12-20 20:25 Mike Frysinger (vapier)
2009-12-01 10:18 Mike Frysinger (vapier)
2009-03-15  9:13 Mike Frysinger (vapier)
2009-03-15  9:01 Mike Frysinger (vapier)
2009-03-15  8:53 Mike Frysinger (vapier)
2008-12-30 13:38 Mike Frysinger (vapier)
2008-12-30 12:38 Mike Frysinger (vapier)
2008-12-10 20:06 Fabian Groffen (grobian)
2008-12-10 20:05 Fabian Groffen (grobian)
2008-11-17 18:09 Diego Petteno (flameeyes)
2008-11-17 18:03 Diego Petteno (flameeyes)
2008-10-22 17:03 Diego Petteno (flameeyes)
2008-10-22 15:20 Diego Petteno (flameeyes)
2008-09-29  6:05 Mike Frysinger (vapier)
2008-09-29  6:03 Mike Frysinger (vapier)
2008-09-29  6:01 Mike Frysinger (vapier)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120123234854.8E22C2004B@flycatcher.gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox