diff --git a/usr.bin/ldd/ldd.1 b/usr.bin/ldd/ldd.1 index 6e49e9cf5236..25e17b0dbb22 100644 --- a/usr.bin/ldd/ldd.1 +++ b/usr.bin/ldd/ldd.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: ldd.1,v 1.20 2017/12/25 05:08:49 maya Exp $ +.\" $NetBSD: ldd.1,v 1.21 2022/10/15 05:55:45 mrg Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 25, 2017 +.Dd October 15, 2022 .Dt LDD 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd list dynamic object dependencies .Sh SYNOPSIS .Nm -.Op Fl o +.Op Fl ov .Op Fl f Ar format .Ar program ... .Sh DESCRIPTION @@ -105,6 +105,10 @@ which makes .Nm behave analogously to .Ic nm Fl o . +.Pp +The +.Fl v +option turns on verbose mode. .Sh EXIT STATUS .Ex -std .Sh SEE ALSO @@ -118,9 +122,3 @@ A utility first appeared in SunOS 4.0, it appeared in its current form in .Nx 0.9a . -.Sh BUGS -The -a.out -.Nm -actually runs the program it has been requested to analyze which in specially -constructed environments can have security implications. diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c index c74efa18c939..dd02d1a82466 100644 --- a/usr.bin/ldd/ldd.c +++ b/usr.bin/ldd/ldd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $ */ +/* $NetBSD: ldd.c,v 1.26 2022/10/15 05:55:45 mrg Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $"); +__RCSID("$NetBSD: ldd.c,v 1.26 2022/10/15 05:55:45 mrg Exp $"); #endif /* not lint */ #include @@ -124,11 +124,12 @@ main(int argc, char **argv) const char *fmt1 = NULL, *fmt2 = NULL; int c, exit_status = EXIT_SUCCESS; char cwd[MAXPATHLEN], path[MAXPATHLEN]; + bool verbose = false, failed = false; #ifdef DEBUG debug = 1; #endif - while ((c = getopt(argc, argv, "f:o")) != -1) { + while ((c = getopt(argc, argv, "f:ov")) != -1) { switch (c) { case 'f': if (fmt1) { @@ -143,6 +144,9 @@ main(int argc, char **argv) errx(1, "Cannot use -o and -f together"); fmt1 = "%a:-l%o.%m => %p\n"; break; + case 'v': + verbose = true; + break; default: usage(); /*NOTREACHED*/ @@ -174,17 +178,31 @@ main(int argc, char **argv) warn("%s", *argv); continue; } - if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1 - /* Alpha never had 32 bit support. */ + if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1) { + if (verbose) + warnx("%s", error_message); + failed = true; + } + /* Alpha never had 32 bit support. */ #if (defined(_LP64) && !defined(ELF64_ONLY)) || defined(MIPS_N32) - && elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1 + if (elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1) { + if (verbose) + warnx("%s", error_message); + failed = true; + } #if defined(__mips__) && 0 /* XXX this is still hosed for some reason */ - && elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1 + if (elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1) { + if (verbose) + warnx("%s", error_message); + failed = true; + } #endif #endif - ) { + + if (failed) { exit_status = EXIT_FAILURE; - warnx("%s", error_message); + if (!verbose) + warnx("%s", error_message); } close(fd); }