From c2b2b846578d61b4bd2deae514c6669ba71a6b5d Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 15 Jun 1994 22:41:19 +0000 Subject: Changes from Paul Kranenburg which bring us into sync with his sources: handling of errors through the standard err() and warn() more fixes for Geoff Rehmet's NULL pointer bug. fixes NULL pointer bugs when linking mono and nested X servers. supports a `-nostdlib' option. accept object files without a symbol table don't attempt dynamic linking when `-A' is given a few variable names have chaged (desc -> fd), and the formatting has changed which should make it much easier to track his sources. I tested 'make world' for /usr/src and X twice with these changes. --- usr.bin/ldd/ldd.c | 56 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'usr.bin/ldd') diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c index 7fba989..1072d80 100644 --- a/usr.bin/ldd/ldd.c +++ b/usr.bin/ldd/ldd.c @@ -27,29 +27,30 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ldd.c,v 1.2 1993/11/09 04:19:27 paul Exp $ + * $Id: ldd.c,v 1.3 1994/02/13 20:42:43 jkh Exp $ */ -#include -#include -#include -#include -#include #include #include #include #include #include -#include #include #include - -static char *progname; +#include +#include +#include +#include +#include +#include void usage() { - fprintf(stderr, "Usage: %s ...\n", progname); + extern char *__progname; + + fprintf(stderr, "Usage: %s ...\n", __progname); + exit(1); } int @@ -57,20 +58,14 @@ main(argc, argv) int argc; char *argv[]; { - int rval = 0; + int rval; int c; - extern int optind; - - if ((progname = strrchr(argv[0], '/')) == NULL) - progname = argv[0]; - else - progname++; while ((c = getopt(argc, argv, "")) != EOF) { switch (c) { default: usage(); - exit(1); + /*NOTREACHED*/ } } argc -= optind; @@ -78,27 +73,29 @@ char *argv[]; if (argc <= 0) { usage(); - exit(1); + /*NOTREACHED*/ } /* ld.so magic */ setenv("LD_TRACE_LOADED_OBJECTS", "", 1); + rval = 0; while (argc--) { int fd; struct exec hdr; int status; if ((fd = open(*argv, O_RDONLY, 0)) < 0) { - perror(*argv); + warn("%s", *argv); rval |= 1; argv++; continue; } if (read(fd, &hdr, sizeof hdr) != sizeof hdr || - !(N_GETFLAG(hdr) & EX_DYNAMIC)) { - fprintf(stderr, "%s: not a dynamic executable\n", - *argv); + !(N_GETFLAG(hdr) & EX_DYNAMIC) || + hdr.a_entry < __LDPGSZ) { + + warnx("%s: not a dynamic executable", *argv); (void)close(fd); rval |= 1; argv++; @@ -111,14 +108,13 @@ char *argv[]; switch (fork()) { case -1: - perror("fork"); - exit(1); + err(1, "fork"); break; default: - if (wait(&status) <= 0) - perror("wait"); - - if (WIFSIGNALED(status)) { + if (wait(&status) <= 0) { + warn("wait"); + rval |= 1; + } else if (WIFSIGNALED(status)) { fprintf(stderr, "%s: signal %d\n", *argv, WTERMSIG(status)); rval |= 1; @@ -129,7 +125,7 @@ char *argv[]; } break; case 0: - rval != execl(*argv, *argv, NULL) != 0; + rval |= execl(*argv, *argv, NULL) != 0; perror(*argv); _exit(1); } -- cgit v1.1