Subject: bin/453: ldd output should be grepable
To: None <gnats-admin>
From: Arne H Juul <arnej@dsl.unit.no>
List: netbsd-bugs
Date: 09/02/1994 13:50:08
>Number:         453
>Category:       bin
>Synopsis:       ldd output is highly irregular and not good to grep
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Sep  2 13:50:06 1994
>Originator:     Arne H Juul
>Organization:
University of Trondheim, Norway
>Release:        
>Environment:
	Netbsd-current as of yesterday or so
System: NetBSD skarven.dsl.unit.no 1.0_BETA NetBSD 1.0_BETA (SKARVEN) #2: Sun Jul 31 16:32:24 MET DST 1994 arnej@skarven.dsl.unit.no:/usr/src/sys/arch/i386/compile/SKARVEN i386


>Description:
	I sometimes feel the need to find out what binaries on my
	system uses a particular version of a shared library (to
	delete it) or which binaries have problems with finding
	their shared libraries (that would be after I deleted it).
	Currently this is cumbersome.
>How-To-Repeat:
	ldd /usr/bin/* | grep libc.so.12
	# gives essentially no information
>Fix:
	Since there is already an environment variable used to
	transmit information from ldd to ld.so, why not stuff
	the program name in it, so here's a patch I hope you can use:

diff -rcP /usr/src/gnu/usr.bin/ld/ldd/ldd.1 ./gnu/usr.bin/ld/ldd/ldd.1
*** /usr/src/gnu/usr.bin/ld/ldd/ldd.1	Fri Dec 17 07:16:51 1993
--- ./gnu/usr.bin/ld/ldd/ldd.1	Thu Sep  1 08:39:40 1994
***************
*** 14,19 ****
--- 14,25 ----
  .Dq indirect
  depedencies that are the result of needed shared objects which themselves
  depend on yet other shared objects.
+ .Pp
+ The only option available is
+ .Bl -tag -width flag
+ .It Fl p
+ include program name on each line to make it easier to grep output.
+ .El
  .Sh SEE ALSO
  .Xr ld 1 ,
  .Xr ld.so 1 ,
diff -rcP /usr/src/gnu/usr.bin/ld/ldd/ldd.c ./gnu/usr.bin/ld/ldd/ldd.c
*** /usr/src/gnu/usr.bin/ld/ldd/ldd.c	Sun Aug 14 12:47:11 1994
--- ./gnu/usr.bin/ld/ldd/ldd.c	Thu Sep  1 08:36:32 1994
***************
*** 53,58 ****
--- 53,60 ----
  	exit(1);
  }
  
+ int pflag;
+ 
  int
  main(argc, argv)
  int	argc;
***************
*** 61,68 ****
  	int		rval;
  	int		c;
  
! 	while ((c = getopt(argc, argv, "")) != EOF) {
  		switch (c) {
  		default:
  			usage();
  			/*NOTREACHED*/
--- 63,73 ----
  	int		rval;
  	int		c;
  
! 	while ((c = getopt(argc, argv, "p")) != EOF) {
  		switch (c) {
+ 		case 'p':
+ 			pflag = 1;
+ 			break;
  		default:
  			usage();
  			/*NOTREACHED*/
***************
*** 106,113 ****
  		}
  		(void)close(fd);
  
! 		printf("%s:\n", *argv);
! 		fflush(stdout);
  
  		switch (fork()) {
  		case -1:
--- 111,122 ----
  		}
  		(void)close(fd);
  
! 		if (pflag)
! 			setenv("LD_TRACE_LOADED_OBJECTS", *argv, 1);
! 		else {
! 			printf("%s:\n", *argv);
! 			fflush(stdout);
! 		}
  
  		switch (fork()) {
  		case -1:
diff -rcP /usr/src/gnu/usr.bin/ld/rtld/rtld.c ./gnu/usr.bin/ld/rtld/rtld.c
*** /usr/src/gnu/usr.bin/ld/rtld/rtld.c	Fri Aug 12 11:58:27 1994
--- ./gnu/usr.bin/ld/rtld/rtld.c	Thu Sep  1 08:31:50 1994
***************
*** 305,311 ****
  struct _dynamic	*dp;
  {
  	struct so_map	*smp;
! 	int		tracing = (int)getenv("LD_TRACE_LOADED_OBJECTS");
  
  	/* Handle LD_PRELOAD's here */
  
--- 305,311 ----
  struct _dynamic	*dp;
  {
  	struct so_map	*smp;
! 	char		*tracing = getenv("LD_TRACE_LOADED_OBJECTS");
  
  	/* Handle LD_PRELOAD's here */
  
***************
*** 367,377 ****
  		if ((path = smp->som_path) == NULL)
  			path = "not found";
  
! 		if (sodp->sod_library)
! 			printf("\t-l%s.%d => %s (%p)\n", name,
! 					sodp->sod_major, path, smp->som_addr);
! 		else
! 			printf("\t%s => %s (%p)\n", name, path, smp->som_addr);
  	}
  
  	exit(0);
--- 367,389 ----
  		if ((path = smp->som_path) == NULL)
  			path = "not found";
  
! 		if (*tracing) {
! 			if (sodp->sod_library)
! 				printf("%s\t-l%s.%d => %s (%p)\n", tracing,
! 						name, sodp->sod_major, path,
! 						smp->som_addr);
! 			else
! 				printf("%s\t%s => %s (%p)\n", tracing,
! 						name, path, smp->som_addr);
! 		} else {
! 			if (sodp->sod_library)
! 				printf("\t-l%s.%d => %s (%p)\n", name,
! 						sodp->sod_major, path,
! 						smp->som_addr);
! 			else
! 				printf("\t%s => %s (%p)\n", name, path,
! 						smp->som_addr);
! 		}
  	}
  
  	exit(0);
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------