Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 639498 - sys-apps/portage-2.3.13-r1: emerge confuses /proc/$pid/exe symlink values (internal value)
Summary: sys-apps/portage-2.3.13-r1: emerge confuses /proc/$pid/exe symlink values (in...
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-02 12:32 UTC by Evert
Modified: 2017-12-03 15:39 UTC (History)
0 users

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


Attachments
emerge --info (emerge--info.txt,6.23 KB, text/plain)
2017-12-02 12:32 UTC, Evert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Evert 2017-12-02 12:32:11 UTC
Created attachment 507684 [details]
emerge --info

After emerge of any package which currently has any binary running, its /proc/$pid/exe symlink value changes
from /path/to/binary
to /var/tmp/portage/$CATEGORY/$PF/image/path/to/binary (deleted)

Examples:
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 10:52 /proc/29264/exe -> /usr/sbin/sshd
# emerge -1 net-misc/openssh &>/dev/null 
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 10:52 /proc/29264/exe -> /var/tmp/portage/net-misc/openssh-7.5_p1-r3/image/usr/sbin/sshd (deleted)

# ls -l /proc/$(pgrep -x named)/exe
lrwxrwxrwx 1 named named 0  2 dec 10:54 /proc/8910/exe -> /usr/sbin/named
# emerge -1 net-dns/bind &>/dev/null
# ls -l /proc/$(pgrep -x named)/exe
lrwxrwxrwx 1 named named 0  2 dec 10:54 /proc/8910/exe -> /var/tmp/portage/net-dns/bind-9.11.1_p3/image/usr/sbin/named (deleted)

# ls -l /proc/$(pgrep -u root -x systemd)/exe
lrwxrwxrwx 1 root root 0 22 nov 20:55 /proc/1/exe -> /usr/lib64/systemd/systemd
# emerge -1 sys-apps/systemd &>/dev/null
# ls -l /proc/$(pgrep -u root -x systemd)/exe
lrwxrwxrwx 1 root root 0 22 nov 20:55 /proc/1/exe -> /var/tmp/portage/sys-apps/systemd-233-r6/image/usr/lib/systemd/systemd (deleted)


Without emerge, I can reproduce something similar - /proc/$pid/exe symlink value changes:
# systemctl restart sshd  # ensure valid sshd /proc/$pid/exe symlink
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 11:51 /proc/32339/exe -> /usr/sbin/sshd
# cp -p /usr/sbin/sshd{,.save}  # simulate new (compiled) binary/inode
# mv /usr/sbin/sshd{,.moved}  # simulate preserve action
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 11:51 /proc/32339/exe -> /usr/sbin/sshd.moved
# rm /usr/sbin/sshd.moved  # simulate removal of preserved file
# mv /usr/sbin/sshd{.save,}  # simulate installation of new binary
# ls -l /proc/$(pgrep -u root -x sshd)/exe /usr/sbin/sshd*
lrwxrwxrwx 1 root root      0  2 dec 11:51 /proc/32339/exe -> /usr/sbin/sshd.moved (deleted)
-rwxr-xr-x 1 root root 770808  2 dec 10:53 /usr/sbin/sshd

So, it seems, at install time, emerge does something like this:
1. move current installed files to /var/tmp/portage/$CATEGORY/$PF/image/path/to/files (*this* causes the confusion)
2. install the new package/files in place
3. remove /var/tmp/portage/$CATEGORY/$PF/image/path/to/files

Obviously this works but /proc/$pid/exe symlinks get confused by this.
It beats me why emerge preserves current installed files (which get deleted anyway) but I if this preserve action is really needed, it would be better to simply copy it (something like this):
1. *copy* current installed files to /var/tmp/portage/$CATEGORY/$PF/image/path/to/files (*no* /proc/$pid/exe symlink value change)
2. install the new binary in place
3. remove /var/tmp/portage/$CATEGORY/$PF/image/path/to/files

Example:
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 11:55 /proc/304/exe -> /usr/sbin/sshd
# cp -p /usr/sbin/sshd /usr/sbin/sshd.new  # new compiled binary
# cp -p /usr/sbin/sshd /usr/sbin/sshd.preserve  # preserve/copy current binary
# mv /usr/sbin/sshd.new /usr/sbin/sshd  # install new compiled binary
# rm /usr/sbin/sshd.preserve  # remove the preserved/copied  binary
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  2 dec 11:55 /proc/304/exe -> /usr/sbin/sshd (deleted)

This way, /proc/$pid/exe symlinks will not get confused (contain internal portage values) about the current (still) running binary.
Comment 1 Zac Medico gentoo-dev 2017-12-02 20:22:00 UTC
The kernel gets confused when portage uses the rename function to move files from /var/tmp/portage/ to the root filesystem. There's a workaround involving mounts suggested in bug 481320, comment #44.
Comment 2 Evert 2017-12-03 15:39:47 UTC
Never thought this would be a kernel bug, looks like you're right:

# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  3 dec 16:35 /proc/3584/exe -> /usr/sbin/sshd
# cp -p /usr/sbin/sshd /var/tmp/portage/sshd
# mv /var/tmp/portage/sshd /usr/sbin/sshd
# ls -l /proc/$(pgrep -u root -x sshd)/exe
lrwxrwxrwx 1 root root 0  3 dec 16:35 /proc/3584/exe -> /var/tmp/portage/sshd (deleted)

Thanks!