Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

qfile use broken by merge-usr

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
18 posts • Page 1 of 1
Author
Message
Frautoincnam
Guru
Guru
Posts: 368
Joined: Fri May 19, 2017 5:16 am

qfile use broken by merge-usr

  • Quote

Post by Frautoincnam » Tue Nov 25, 2025 6:12 pm

A while back, I followed the procedure at https://wiki.gentoo.org/wiki/Merge-usr[b][/b], which created the following symbolic links:

Code: Select all

/usr/sbin -> /bin
/bin -> /usr/bin
/sbin -> /usr/bin
/lib -> /usr/lib
/lib64 -> /usr/lib64
I never had any problems with it, except for one major drawback: the qfile tool in app-portage/portage-utils is completely broken.

For example: iproute2 installs the ip binary in /bin. rkhunter finds the modified /usr/bin/ip binary and reports it to me. To see which package this binary belongs to, I run qfile /usr/bin/ip, and of course, it finds nothing.

I do have an idea (*) to solve this problem, but it's cumbersome and might overlap with an existing solution, so I'd prefer to ask the question first.

(*) Create a database, populated with data by `emerge` on each installation/uninstallation, and use a tool that accesses it to replace `qfile`.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3526
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Tue Nov 25, 2025 7:09 pm

This is a known issue. There were discussions here on the forums but I can't find them. Maybe try looking at the bug tracker, because I think one of the devs mentioned it was being considered.

Another idea is to grep in /var/db/pkg for the symlinks, rather than using information from emerge. It would be easier that way. You don't even need to grep, just populate the DB, all the information is there. Then you can modify it so you can query it in the way you like.

Best Regards,
Georgi
Top
Frautoincnam
Guru
Guru
Posts: 368
Joined: Fri May 19, 2017 5:16 am

  • Quote

Post by Frautoincnam » Tue Nov 25, 2025 7:18 pm

logrusx wrote:This is a known issue. There were discussions here on the forums but I can't find them. Maybe try looking at the bug tracker, because I think one of the devs mentioned it was being considered.
I've already searched, and I haven't found anything conclusive, hence my question here.
Another idea is to grep in /var/db/pkg for the symlinks, rather than using information from emerge. It would be easier that way. You don't even need to grep, just populate the DB, all the information is there. Then you can modify it so you can query it in the way you like.
But no, because in /var/db/pkg I'll have the path installed by the package, and that doesn't correspond to the path rkhunter is looking for. That's the heart of the problem. If the path in /var/db/pkg were the path on the filesystem, then qfile would give the correct information, and my question wouldn't make sense.

Code: Select all

# grep "/ip " /var/db/pkg/sys-apps/iproute2-6.17.0/CONTENTS 
obj /bin/ip 6184b13d58bbb226d641f9e789f00d2e 1762840324
# which ip
/usr/bin/ip
Top
Hu
Administrator
Administrator
Posts: 24380
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Nov 25, 2025 7:18 pm

The Wiki page linked by the OP includes at the bottom a link to [Tracker] /usr merge. That bug in turn blocks (among others) app-portage/gentoolkit unable to identify which package files belongs to after merge-usr. That is for gentoolkit, not portage-utils as OP reports, but the principle is the same and some of the comments there may be informative.
Top
grknight
Retired Dev
Retired Dev
Posts: 2549
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Tue Nov 25, 2025 7:20 pm

Frautoincnam wrote:(*) Create a database, populated with data by `emerge` on each installation/uninstallation, and use a tool that accesses it to replace `qfile`.
This is exactly what is happening with qfile. It asks the emerge installed file database if it installed a certain file. That database says no and qfile reports what it has.
Top
Frautoincnam
Guru
Guru
Posts: 368
Joined: Fri May 19, 2017 5:16 am

  • Quote

Post by Frautoincnam » Tue Nov 25, 2025 7:23 pm

grknight wrote:
Frautoincnam wrote:(*) Create a database, populated with data by `emerge` on each installation/uninstallation, and use a tool that accesses it to replace `qfile`.
This is exactly what is happening with qfile. It asks the emerge installed file database if it installed a certain file. That database says no and qfile reports what it has.
I meant recording the TRUE path, according to symlinks, not the package path registered in package CONTENTS
Hu wrote:The Wiki page linked by the OP includes at the bottom a link to [Tracker] /usr merge. That bug in turn blocks (among others) app-portage/gentoolkit unable to identify which package files belongs to after merge-usr. That is for gentoolkit, not portage-utils as OP reports, but the principle is the same and some of the comments there may be informative.
Thanks. Never saw this link. I'll have a look.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3526
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Tue Nov 25, 2025 7:41 pm

Frautoincnam wrote:
Another idea is to grep in /var/db/pkg for the symlinks, rather than using information from emerge. It would be easier that way. You don't even need to grep, just populate the DB, all the information is there. Then you can modify it so you can query it in the way you like.
But no, because in /var/db/pkg I'll have the path installed by the package, and that doesn't correspond to the path rkhunter is looking for.
Knowing which paths are symlinks, you can modify the database to reflect the real paths.

Best Regards,
Georgi
Top
Frautoincnam
Guru
Guru
Posts: 368
Joined: Fri May 19, 2017 5:16 am

  • Quote

Post by Frautoincnam » Tue Nov 25, 2025 7:45 pm

logrusx wrote:Knowing which paths are symlinks, you can modify the database to reflect the real paths.
That's exactly what I'm talking about.

My question wasn't about what I could implement, but about whether something already exists so I don't invent it unnecessarily.
Top
sublogic
Guru
Guru
User avatar
Posts: 385
Joined: Mon Mar 21, 2022 3:02 am
Location: Pennsylvania, USA

Re: qfile use broken by merge-usr

  • Quote

Post by sublogic » Wed Nov 26, 2025 1:07 am

Frautoincnam wrote:[ . . .] To see which package this binary belongs to, I run qfile /usr/bin/ip, and of course, it finds nothing.
As a workaround, try running qfile ip without the full path.

If running in a script, do qfile $(basename $filepath) .

One drawback is that you can get multiple hits.

Code: Select all

$ qfile python
dev-lang/python: /usr/lib/python-exec/python3.14/python
dev-lang/python: /usr/lib/python-exec/python3.13/python
dev-lang/python-exec: /usr/bin/python
sys-apps/file: /usr/share/misc/magic/python
(This system is still split-user.)
The practical unit of "Learning Experience" is the milli-Gentoo.
Top
Frautoincnam
Guru
Guru
Posts: 368
Joined: Fri May 19, 2017 5:16 am

Re: qfile use broken by merge-usr

  • Quote

Post by Frautoincnam » Wed Nov 26, 2025 2:13 am

sublogic wrote:As a workaround, try running qfile ip without the full path.
That's a pretty good idea. I wasn't aware of it.

But the fact that it can produce multiple results isn't ideal for me since I've already set up my database.

Code: Select all

# qfile ip
app-shells/bash-completion: /usr/share/bash-completion/completions/ip
sys-apps/iproute2: /bin/ip
But thanks anyway for suggesting it.
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4679
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Nov 26, 2025 12:03 pm

Hm.
Interesting problem.

Code: Select all

zucca@M2-Air ~ $ qfile /bin/ip
sys-apps/iproute2: /bin/ip
zucca@M2-Air ~ $ realpath /bin/ip
/usr/bin/ip
zucca@M2-Air ~ $ qfile /usr/bin/ip
zucca@M2-Air ~ $ 
Resolving symlinks early may give false negative.

Code: Select all

zucca@M2-Air ~ $ qlist sys-apps/iproute2 | grep '/ip$'
/bin/ip
... and since the ebuild file (subsequently probably the makefile) installs the binary into /bin, were it a symlink or not, it's hard to perform an "unresolving of symlinks".

Now that the actual file resides at /usr/bin/ip if user queries that file with qfile, we'd need to know if any component of the path were a target of a symlink somewhere and then expand the query to those locations too. Potentially a very expensive search.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3526
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Wed Nov 26, 2025 12:10 pm

Zucca wrote:Potentially a very expensive search.
No, it's not. It's linear time and potential symliks are only a fixed number.

Brute force solution would be M*N where M is the depth of the path and N - the number of fixed symlinks.

Best Regards,
Georgi
Last edited by logrusx on Wed Nov 26, 2025 12:43 pm, edited 1 time in total.
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4679
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Nov 26, 2025 12:14 pm

Well yes, if you have some already known fixed locations of common symlinks then it's not too much of a hassle.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4679
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Thu Jan 08, 2026 11:37 am

Zucca wrote:Hm.
Interesting problem.

Code: Select all

zucca@M2-Air ~ $ qfile /bin/ip
sys-apps/iproute2: /bin/ip
zucca@M2-Air ~ $ realpath /bin/ip
/usr/bin/ip
zucca@M2-Air ~ $ qfile /usr/bin/ip
zucca@M2-Air ~ $ 
I found a "solution":

Code: Select all

emerge -qp /usr/bin/ip | cut -d ']' -f 2

Code: Select all

emerge -qp /usr/bin/ip | awk -F '] ' '{print $2}'
I find this rather interesting that it even works... qfile and equery b, both, fail this.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3526
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Thu Jan 08, 2026 12:26 pm

Zucca wrote: I find this rather interesting that it even works... qfile and equery b, both, fail this.
Because qfile and equery simply grep in /ver/db/pkg. The emerge command actually spins up portage and is able to do much more stuff. That's even evident from the delay and the fan noise it produces.

You've just found another way to do it. I guess whoever wrote equery or qfile wouldn't have done it if they knew this trick :)

If it at all existed back then as I recall portage had been pure bash up until one point. I'm not sure I've experienced that personally but certainly portage was much less capable 18 years ago when I first tried Gentoo.

Best Regards,
Georgi
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4679
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Thu Jan 08, 2026 12:43 pm

Ok.

I had the impression that equery uses actual portage routines/libs rather than directly querying database.
Haven't really dug into the source code of either q applets or equery.

It makes sens then.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3526
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Thu Jan 08, 2026 12:57 pm

Now that you mention it, I don't have recollection of where I know that. I think I've seen a developer quote about it but I may be wrong. All I know is equery does stuff the simplest way possible and in regards to that, they both use the same mechanism with qfile.

EDIT: actually I found the thread. It's not exactly what I said but still:
grknight wrote: equery belongs, and other tools like qfile, use the portage database and not actual locations.
Best Regards,
Georgi
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4679
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Fri Jan 30, 2026 10:55 am

portageq kinda works:

Code: Select all

$ portageq owners / /usr/bin/ip
sys-apps/iproute2-6.17.0
	/bin/ip
None of the installed packages claim these files:
	/usr/bin/ip
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Post Reply

18 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy