diff options
author | rich <rich@FreeBSD.org> | 1994-06-15 22:41:19 +0000 |
---|---|---|
committer | rich <rich@FreeBSD.org> | 1994-06-15 22:41:19 +0000 |
commit | c2b2b846578d61b4bd2deae514c6669ba71a6b5d (patch) | |
tree | fc74fe81900a764f41153f6c45e592474d9cb257 /usr.bin/ldd/ldd.c | |
parent | 24f89c1469242434ab6ab918657aa2085fad5ddc (diff) | |
download | FreeBSD-src-c2b2b846578d61b4bd2deae514c6669ba71a6b5d.zip FreeBSD-src-c2b2b846578d61b4bd2deae514c6669ba71a6b5d.tar.gz |
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.
Diffstat (limited to 'usr.bin/ldd/ldd.c')
-rw-r--r-- | usr.bin/ldd/ldd.c | 56 |
1 files changed, 26 insertions, 30 deletions
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 <sys/param.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> #include <sys/time.h> #include <sys/resource.h> -#include <fcntl.h> #include <sys/wait.h> #include <a.out.h> - -static char *progname; +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> void usage() { - fprintf(stderr, "Usage: %s <filename> ...\n", progname); + extern char *__progname; + + fprintf(stderr, "Usage: %s <filename> ...\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); } |