Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 140019 - app-portage/portage-utils: qfile new option to find orphan files
Summary: app-portage/portage-utils: qfile new option to find orphan files
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Tools (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Portage Utils Team
URL:
Whiteboard:
Keywords: InVCS
: 27652 (view as bug list)
Depends on: 139825
Blocks:
  Show dependency tree
 
Reported: 2006-07-11 12:21 UTC by TGL
Modified: 2010-01-24 21:29 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
qfile-0.1.19-orphans.patch (qfile-0.1.19-orphans.patch,4.13 KB, patch)
2006-07-11 12:22 UTC, TGL
Details | Diff
qfile-orphans-fix.patch (qfile-orphans-fix.patch,1.01 KB, patch)
2006-07-18 11:57 UTC, TGL
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description TGL 2006-07-11 12:21:13 UTC
Here is a patch which adds a --orphans (-o) option to qfile.  It inverses the purpose of the command: instead of listing packages owning the files, it lists files which don't have any owner.  Exit code is zero if no orphan found.

An example of use is to look for orphan libtool files (left behind because of fix_libtool_files.sh):
 % find /lib /usr/lib -type f -name "*.la" -print0 | xargs -0 -n 500 qfile -o

This patch is based on the optimized qfile from bug #139825, it should be applied after attachment #91385 [details, diff] (on portage-utils-0.1.19).  This way, the above command takes ~8s (for ~1500 .la files).
Comment 1 TGL 2006-07-11 12:22:12 UTC
Created attachment 91495 [details, diff]
qfile-0.1.19-orphans.patch
Comment 2 solar (RETIRED) gentoo-dev 2006-07-11 13:11:42 UTC
Please assign portage-utils related bugs to portage-utils@ vs tools-portage@
Comment 3 TGL 2006-07-11 13:48:49 UTC
(In reply to comment #2)
> Please assign portage-utils related bugs to portage-utils@ vs tools-portage@
> 

If only i could...  The "Assign To" field is no more editable by users since a few months.  It's now only filled automatically, depending on the component you select.  Hence the CC i added for you to pick it.
But yes, next time i'll leave it without a component, so that it's wranglers who get the spam and not portage-tools@.
Comment 4 solar (RETIRED) gentoo-dev 2006-07-17 18:35:02 UTC
Patch failed to apply cleanly to CVS revision 1.31 of qfile.c
I fixed up the rejects and committed it as cvs revision: 1.32
Comment 5 solar (RETIRED) gentoo-dev 2006-07-18 07:07:13 UTC
I want to revert this patch as it causes segfaults.

$ ./q file /bin/* > /dev/null 
Segmentation fault
$ cvs diff -r 1.31 qfile.c > qfile-1.32.diff
$ cat qfile-1.32.diff | patch -R -p0
$ ./q file /bin/* > /dev/null
$ echo $?
0

Added patch back and strace shows.

1576  open("/var/db/pkg/app-arch/bzip2-1.0.3-r5/CONTENTS", O_RDONLY) = 5
1576  fstat64(5, {st_mode=S_IFREG|0644, st_size=2024, ...}) = 0
1576  mmap2(NULL, 131072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x527c2000
1576  read(5, "dir /bin\nsym /bin/bzegrep -> bzg"..., 131072) = 2024
1576  fstat64(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
1576  ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x5c34d780) = -1 ENOTTY (Inappropriate ioctl for device)
1576  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x527c1000
1576  --- SIGSEGV (Segmentation fault) @ 0 (0) ---
1576  +++ killed by SIGSEGV +++

We will have to solve this before the release of .20
Comment 6 solar (RETIRED) gentoo-dev 2006-07-18 07:11:30 UTC
Here is a little debug info.
solar@onyx /var/cvsroot/gentoo-projects/portage-utils $ gdb -q ./q
Using host libthread_db library "/lib/libthread_db.so.1".
gdb> run file /bin/* 
profile ../usr/portage/profiles/hardened/x86/2.6/make.defaults
profile /etc/make.globals
profile /etc/make.conf
ACCEPT_LICENSE = *
INSTALL_MASK = 
ARCH = 
CONFIG_PROTECT = /usr/lib/X11/xkb
NOCOLOR = 0
FEATURES = noman noinfo nodoc sandbox distlocks metadata-transfer buildpkg noinfo nodoc -splitdebug -installsources confcache -distclean cvs
PORTDIR = /usr/portage
PORTAGE_BINHOST = ftp://tinderbox.x86.dev.gentoo.org/hardened/x86/
PORTAGE_TMPDIR = /var/tmp
PKGDIR = /usr/portage/packages/x86/
ROOT = /
q: lookup_applet(): found applet q at 0x804efd0
q: lookup_applet(): Looking up applet (file) by short name
q: lookup_applet(): found applet by short name qfile
file: qfile_main(): argc=145 argv[0]=file argv[1]=/bin/Mail
app-arch/bzip2 (/bin/bzegrep)

Program received signal SIGSEGV, Segmentation fault.
_______________________________________________________________________________
     eax:00000000 ebx:080C1DD0  ecx:080C1E38  edx:000000A1     eflags:00010202
     esi:0000000B edi:BFFFA5A9  esp:BFFFA4D0  ebp:BFFFB9C8     eip:08051BF4
     cs:0073  ds:007B  es:007B  fs:0000  gs:0000  ss:007B    o d I t s z a p c 
[007B:BFFFA4D0]---------------------------------------------------------[stack]
BFFFA500 : 18 04 0A 08  78 1D 0A 08 - 44 28 07 08  01 00 00 00 ....x...D(......
BFFFA4F0 : C3 1E 0A 08  00 00 00 00 - A8 08 0A 08  60 06 0A 08 ............`...
BFFFA4E0 : 2A 1E 0C 08  3B 2A 06 08 - 00 00 00 00  00 00 00 00 *...;*..........
BFFFA4D0 : D0 1D 0C 08  A4 A5 FF BF - 21 1E 0C 08  40 E6 06 08 ........!...@...
[007B:BFFFA5A9]---------------------------------------------------------[ data]
BFFFA5A9 : 62 7A 65 67  72 65 70 00 - 2D 3E 20 62  7A 67 72 65 bzegrep.-> bzgre
BFFFA5B9 : 70 00 31 31  33 32 33 33 - 32 30 31 38  00 00 66 66 p.1132332018..ff
[0073:08051BF4]---------------------------------------------------------[ code]
0x8051bf4 <qfile+596>:	movw   $0x1,(%eax,%esi,2)
0x8051bfa <qfile+602>:	inc    %esi
0x8051bfb <qfile+603>:	jmp    0x8051b60 <qfile+448>
0x8051c00 <qfile+608>:	mov    0xffffeb40(%ebp),%edx
0x8051c06 <qfile+614>:	mov    0x8(%edx),%eax
0x8051c09 <qfile+617>:	mov    %eax,(%esp)
------------------------------------------------------------------------------
0x08051bf4 in qfile (path=0x80a1d78 "/var/db/pkg/app-arch", argc=0x90, base_names=0x80a0418, dir_names=0x80a0660, real_dir_names=0x80a08a8, non_orphans=0x0) at qfile.c:130
130					non_orphans[i] = 1;
Comment 7 solar (RETIRED) gentoo-dev 2006-07-18 07:14:34 UTC
And a backtrace.


gdb> bt full
#0  0x08051bf4 in qfile (path=0x80a1d78 "/var/db/pkg/app-arch", argc=0x90, base_names=0x80a0418, dir_names=0x80a0660, real_dir_names=0x80a08a8, non_orphans=0x0) at qfile.c:130
	e = (contents_entry *) 0x8072844
	fp = (FILE *) 0x80c1e70
	dir = (DIR *) 0x80a1d98
	dentry = (struct dirent *) 0x0
	entry_basename = 0xbfffa5a9 "bzegrep"
	entry_dirname = 0x80c1e00 ""
	p = 0x80c1e04 ""
	buf = "sym /bin/bzegrep\000-> bzgrep\0001132332018\000\000ffd0957d78a87d437a498a24b5\0001147185899\000\0002e4ff354b800\0001147185899\000\000\000\000\000\000\000\000\0009\000\000\000\000\0001671137\000\00020\000\000232\000\000\000\000\0009\000\0007171\000\000\000667171\000\0001\000\0001\000\000\000\00071\000\000@:
Comment 8 solar (RETIRED) gentoo-dev 2006-07-18 07:14:34 UTC
And a backtrace.


gdb> bt full
#0  0x08051bf4 in qfile (path=0x80a1d78 "/var/db/pkg/app-arch", argc=0x90, base_names=0x80a0418, dir_names=0x80a0660, real_dir_names=0x80a08a8, non_orphans=0x0) at qfile.c:130
	e = (contents_entry *) 0x8072844
	fp = (FILE *) 0x80c1e70
	dir = (DIR *) 0x80a1d98
	dentry = (struct dirent *) 0x0
	entry_basename = 0xbfffa5a9 "bzegrep"
	entry_dirname = 0x80c1e00 ""
	p = 0x80c1e04 ""
	buf = "sym /bin/bzegrep\000-> bzgrep\0001132332018\000\000ffd0957d78a87d437a498a24b5\0001147185899\000\0002e4ff354b800\0001147185899\000\000\000\000\000\000\000\000\0009\000\000\000\000\0001671137\000\00020\000\000232\000\000\000\000\0009\000\0007171\000\000\000667171\000\0001\000\0001\000\000\000\00071\000\000@:¾\a@¸\n\002\000H\005\b\bà\003\b\b Y\023@Ì=\023@à\003\b\b Y\023@"...
	pkg = "app-arch/bzip2-1.0.3-r5\000-r11\0004.2\000\0001\0001\0001\000 ¥ÿ¿t¥ÿ¿±ª\a@ ¥ÿ¿uD¢Ã'æ\006\b\000\000\000\000'æ\006\bÌ=\023@\020\000\000\000\030æ\006\b\234¦ÿ¿}R\a@ ¥ÿ¿n1\006\bЦÿ¿\030æ\006\b\000\000\000\000@¦ÿ¿Ì¦ÿ¿°\006\a\b ¥"
	atom = (depend_atom *) 0x80c1dd0
	i = 0xb
	path_ok = 0x1
#1  0x080526de in qfile_main (argc=0x91, argv=0xbfffeb48) at qfile.c:247
	tmppath = "/bin", '\0' <repeats 4091 times>
	abspath = "/bin\000znew", '\0' <repeats 4086 times>
	dir = (DIR *) 0x80803e0
	dentry = (struct dirent *) 0x0
	i = 0x90
	p = 0x80a1d78 "/var/db/pkg/app-arch"
	basenames = (char **) 0x80a0418
	dirnames = (char **) 0x80a0660
	realdirnames = (char **) 0x80a08a8
	pwd = 0xbffffca4 "/var/cvsroot/gentoo-projects/portage-utils"
	non_orphans = (short int *) 0x0
	search_orphans = 0x8a8
	__FUNCTION__ = "qfile_main"
#2  0x0804f333 in q_main (argc=0x92, argv=0xbfffeb48) at q.c:132
	buf = '\0' <repeats 1392 times>, "hàÿ¿\000`\023@´o\001@(âÿ¿o[\000@\000`\023@Ô\034\000\000\003\000\000\0002\000\000\000ÿÿÿÿ", '\0' <repeats 45 times>, " \021\000À\224\021\000À\224\021\000\000\000\000\000\005\000\000\000\000 \021\000\000à\021\000\020Ò\021\000Ôü\021\000\000\220\021\000\003\000\000\000\216\002\001@", '\0' <repeats 12 times>, "\216\002\001@\000\000\000\000\000\000\000\000´o\001@\000\000\000\000\000\000\000\000¼àÿ¿´o\001@\017\000\000\000\020z\001@Ìàÿ¿å\003\001@\b\000\000\000\017\000\000\000´o\001@\fáÿ¿µ\215\000@h|\001@\000z\001@\017\000\000\000h|\001"...
	i = 0x0
	p = 0x1 <Address 0x1 out of bounds>
	func = (APPLET) 0x80c1e38
	__FUNCTION__ = "q_main"
#3  0x0804f43b in main (argc=0x0, argv=0xbfffeb44) at main.c:1011
No locals.
gdb> 
Comment 9 solar (RETIRED) gentoo-dev 2006-07-18 07:22:52 UTC
$ ./qfile /bin/bzegrep
Segmentation fault

$ ls -l  /bin/bzegrep
lrwxrwxrwx  1 root root 6 Nov 18  2005 /bin/bzegrep -> bzgrep


$ ltrace -o woof ./qfile /bin/bzegrep

$ tail -n50  woof 
__strtol_internal("1147185899", NULL, 10)                                                                               = 1147185899
strrchr("/usr/share/man/man1/upx.1.gz", '/')                                                                            = "/upx.1.gz"
strcmp("upx.1.gz", "bzegrep")                                                                                           = 1
fgets("obj /usr/share/man/man1/upx.1.gz", 1024, 0x80a3cc8)                                                              = NULL
fclose(0x80a3cc8)                                                                                                       = 0
readdir(0xb7fdf008)                                                                                                     = 0xb7fdf128
asprintf(0xbfffa52c, 0x80637bd, 0x80a3c40, 0xb7fdf133, 0xb7fdf11b)                                                      = 44
fopen("/var/db/pkg/app-arch/bzip2-1.0.3"..., "r")                                                                       = 0x80a3cc8
free(0x80a3bd8)                                                                                                         = <void>
__xpg_basename(0x80a3c40, 0x8062715, 0x80a3c40, 0xb7fdf133, 0xb7fdf11b)                                                 = 0x80a3c4c
snprintf("app-arch/bzip2-1.0.3-r5", 126, "%s/%s", "app-arch", "bzip2-1.0.3-r5")                                         = 23
fgets("dir /bin\n", 1024, 0x80a3cc8)                                                                                    = 0xbfffa5b0
strrchr("dir /bin\n", '\n')                                                                                             = "\n"
strrchr("/bin", '/')                                                                                                    = "/bin"
strcmp("bin", "bzegrep")                                                                                                = -1
fgets("sym /bin/bzegrep -> bzgrep 11323"..., 1024, 0x80a3cc8)                                                           = 0xbfffa5b0
strrchr("sym /bin/bzegrep -> bzgrep 11323"..., '\n')                                                                    = "\n"
strrchr("/bin/bzegrep -> bzgrep 113233201"..., ' ')                                                                     = " 1132332018"
strstr("/bin/bzegrep -> bzgrep", " -> ")                                                                                = " -> bzgrep"
__strtol_internal("1132332018", NULL, 10)                                                                               = 1132332018
strrchr("/bin/bzegrep", '/')                                                                                            = "/bzegrep"
strcmp("bzegrep", "bzegrep")                                                                                            = 0
__strdup(0xbfffa5b4, 0, 10, 0, 0xeac22f0a)                                                                              = 0x80a3e38
strrchr("/bin/bzegrep", '/')                                                                                            = "/bzegrep"
strcmp("/bin", "/bin")                                                                                                  = 0
free(0x80a3e38)                                                                                                         = <void>
strlen("app-arch/bzip2-1.0.3-r5")                                                                                       = 23
malloc(105)                                                                                                             = 0x80a3e50
memcpy(0x80a3ea1, "app-arch/bzip2-1.0.3-r5", 23)                                                                        = 0x80a3ea1
strrchr("app-arch/bzip2-1.0.3-r5", '/')                                                                                 = "/bzip2-1.0.3-r5"
strrchr("app-arch", '/')                                                                                                = NULL
strstr("bzip2-1.0.3-r5", ".ebuild")                                                                                     = NULL
strlen("bzip2-1.0.3-r5")                                                                                                = 14
__ctype_b_loc()                                                                                                         = 0x40137938
__strtol_internal("5", NULL, 10)                                                                                        = 5
strchr("bzip2-1.0.3", '_')                                                                                              = NULL
strlen("bzip2-1.0.3")                                                                                                   = 11
__ctype_b_loc()                                                                                                         = 0x40137938
__ctype_b_loc()                                                                                                         = 0x40137938
__ctype_b_loc()                                                                                                         = 0x40137938
__ctype_b_loc()                                                                                                         = 0x40137938
__ctype_b_loc()                                                                                                         = 0x40137938
strlen("1.0.3")                                                                                                         = 5
sprintf("1.0.3-r5", "%s-r%i", "1.0.3", 5)                                                                               = 8
sprintf("bzip2-1.0.3-r5", "%s-%s", "bzip2", "1.0.3-r5")                                                                 = 14
printf("%s%s/%s%s%s", "\033[00;01m", "app-arch", "\033[36;01m", "bzip2", "\033[00;00m")                                 = 38
printf(" (%s)\n", "/bin/bzegrep")                                                                                       = 16
free(0x80a3e50)                                                                                                         = <void>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
Comment 10 TGL 2006-07-18 11:57:47 UTC
Created attachment 92150 [details, diff]
qfile-orphans-fix.patch

Oops, sorry for the breakage... and thanks for your debug infos.
Here is a patch which fixes it (the 2nd chunk).  It also fixes a bug on "/foo" queries (1st chunk), and change output of --orphans (3rd chunk), to report exactly whatever the query arguments was (otherwise, queries like "./foo" were looking weird, since they were reported as "${PWD}/./foo").

The patch is for CVS 1.32.
Comment 11 solar (RETIRED) gentoo-dev 2006-07-18 12:45:01 UTC
cvs ci -m '- fix up segv in initial orphan handling code. attachment#92150 [details, diff] from bug 140019 degrenier@easyconnect' qfile.c 
/var/cvsroot/gentoo-projects/portage-utils/qfile.c,v  <--  qfile.c
new revision: 1.33; previous revision: 1.32
Comment 12 solar (RETIRED) gentoo-dev 2006-07-22 16:07:30 UTC
Released in portage-utils-0.1.20
Comment 13 solar (RETIRED) gentoo-dev 2006-07-23 17:25:28 UTC
TGL,
I'd like to say thank you for this option. It's starting to prove very 
useful to me.  I'm think I can use it to test for binary transactions before installing a binary package perhaps doing something like this.
qfile -o $(scanelf -n -lq -F%n#f| tr , '\n' | sort -u)
Comment 14 TGL 2006-10-11 10:36:52 UTC
(In reply to comment #12)
> I'm think I can use it to test for binary transactions before
> installing a binary package 

FYI, i think it won't really work without some false positives (i mean, without even talking of weird cases where a lib is package.provided and manually installed, or things like that)

Actually, I've just realized that while writing a script which was trying to do revdep-rebuild's job faster, by just looking at the NEEDED files in the vdb, and then calling "qfile -o" on the needed libs to detect the missing ones.  It happened to break on cases like this one, for which i see no good workaround:
 - "net-libs/liblockfile" installs "liblockfile.so.1.0" and a "liblockfile.so" symlink, but no "liblockfile.so.1",
 - ldconfig (i guess), when ran by portage, adds the missing "liblockfile.so.1" symlink,
 - "mail-client/sylpheed-claws" links against "liblockfile.so.1",
 - qfile can't find "liblockfile.so.1" in any CONTENTS files, and thus the script reports "sylpheed-claws" as a candidate for the rebuild.

Or maybe there could be a QA rule stating that ebuilds should always provide all the symlinks for the libs they install, but it sounds hard to justify since nothing is actually broken in the above "liblockfile" example.
Comment 15 solar@gentoo.org 2006-10-12 16:49:10 UTC
I think procmail does it also. I've scanned hundreds of packages using this method 
and fixed a few of the ones I've found that were broken. And yeah you are quite 
right it should become a QA problem at that point.

Side note this is what I've been using.
http://dev.gentoo.org/~solar/portage_misc/bashrc.verify-needed
Comment 16 Jakub Moc (RETIRED) gentoo-dev 2007-11-05 00:27:33 UTC
*** Bug 27652 has been marked as a duplicate of this bug. ***