| 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.19 2005/04/02 04:13:36 solar Exp $ |
5 | * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.20 2005/04/02 19:06:36 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 |
| … | |
… | |
| 28 | #include <errno.h> |
28 | #include <errno.h> |
| 29 | #include <unistd.h> |
29 | #include <unistd.h> |
| 30 | #include <sys/stat.h> |
30 | #include <sys/stat.h> |
| 31 | #include <dirent.h> |
31 | #include <dirent.h> |
| 32 | #include <getopt.h> |
32 | #include <getopt.h> |
| 33 | |
33 | #include <assert.h> |
| 34 | #include "paxelf.h" |
34 | #include "paxelf.h" |
| 35 | |
35 | |
| 36 | static const char *rcsid = "$Id: scanelf.c,v 1.19 2005/04/02 04:13:36 solar Exp $"; |
36 | static const char *rcsid = "$Id: scanelf.c,v 1.20 2005/04/02 19:06:36 solar Exp $"; |
| 37 | |
37 | |
| 38 | |
38 | |
| 39 | /* helper functions for showing errors */ |
39 | /* helper functions for showing errors */ |
| 40 | #define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ |
40 | #define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ |
| 41 | #define warn(fmt, args...) \ |
41 | #define warn(fmt, args...) \ |
| … | |
… | |
| 188 | static void scanelf_dir(const char *path) |
188 | static void scanelf_dir(const char *path) |
| 189 | { |
189 | { |
| 190 | register DIR *dir; |
190 | register DIR *dir; |
| 191 | register struct dirent *dentry; |
191 | register struct dirent *dentry; |
| 192 | struct stat st_top, st; |
192 | struct stat st_top, st; |
| 193 | char *p; |
193 | char buf[PATH_MAX]; |
| 194 | int len = 0; |
194 | size_t len = 0; |
| 195 | |
195 | |
| 196 | /* make sure path exists */ |
196 | /* make sure path exists */ |
| 197 | if (lstat(path, &st_top) == -1) |
197 | if (lstat(path, &st_top) == -1) |
| 198 | return; |
198 | return; |
| 199 | |
199 | |
| … | |
… | |
| 212 | |
212 | |
| 213 | while ((dentry = readdir(dir))) { |
213 | while ((dentry = readdir(dir))) { |
| 214 | if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) |
214 | if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) |
| 215 | continue; |
215 | continue; |
| 216 | len = (strlen(path) + 2 + strlen(dentry->d_name)); |
216 | len = (strlen(path) + 2 + strlen(dentry->d_name)); |
| 217 | p = malloc(len); |
217 | assert(len < sizeof(buf)); |
| 218 | if (!p) |
|
|
| 219 | err("scanelf_dir(): Could not malloc: %s", strerror(errno)); |
|
|
| 220 | strncpy(p, path, len); |
218 | strncpy(buf, path, len); |
| 221 | strncat(p, "/", len); |
219 | strncat(buf, "/", len); |
| 222 | strncat(p, dentry->d_name, len); |
220 | strncat(buf, dentry->d_name, len); |
|
|
221 | buf[sizeof(buf)] = 0; |
| 223 | if (lstat(p, &st) != -1) { |
222 | if (lstat(buf, &st) != -1) { |
| 224 | if (S_ISREG(st.st_mode)) |
223 | if (S_ISREG(st.st_mode)) |
| 225 | scanelf_file(p); |
224 | scanelf_file(buf); |
| 226 | else if (dir_recurse && S_ISDIR(st.st_mode)) { |
225 | else if (dir_recurse && S_ISDIR(st.st_mode)) { |
| 227 | if (dir_crossmount || (st_top.st_dev == st.st_dev)) |
226 | if (dir_crossmount || (st_top.st_dev == st.st_dev)) |
| 228 | scanelf_dir(p); |
227 | scanelf_dir(buf); |
| 229 | } |
228 | } |
| 230 | } |
229 | } |
| 231 | free(p); |
|
|
| 232 | } |
230 | } |
| 233 | closedir(dir); |
231 | closedir(dir); |
| 234 | } |
232 | } |
| 235 | |
233 | |
| 236 | /* scan /etc/ld.so.conf for paths */ |
234 | /* scan /etc/ld.so.conf for paths */ |