Control: tags -1 + upstream
Control: fixed -1 4.89+dfsg-0.1

Dear Maintainer,
I just tried to find some more informations about this issue.

The lsof version 4.89+dfsg-0.1 did not show this issue, therefore
Stretch is not affected. It started with version 4.91+dfsg-1 which
is already contained in Buster.

As far as I see, the issue is /proc/[pid]/stat contains
usually a single line with all process informations.
Therefore lsof needs to parse that line.

It looks like linux delivers the process name parenthesised and
cropped to the first 16 characters.

Then lsof 4.91 got a change to handle process names with parenthesises
better, therefore counts them in the process name.

Therefore there is an issue with process names where parenthesises are
beyond the 16 character limit or the number of left parenthesises is
higher than the right parenthesises.

The minimal example to demonstrate the issue would be:

    root@debian:~# perl -E '$0 = "("; print "My PID is $$\n"; <STDIN>'
    My PID is 13957

    root@debian:~# lsof -p 13957
    root@debian:~# hexdump -C /proc/13957/stat
    00000000  31 33 39 35 37 20 28 28  29 20 53 20 34 39 32 36  |13957 (() S 
4926|
    ...

The source location is around lsof-4.91+dfsg/dialects/linux/dproc.c,
lines 1568 to 1602.


Looking at 'ps aux', a different approach is used there:
The file /proc/[pid]/stat gets read as a whole and then
searched for the first '(' and then in reverse direction
from the end for the ')'.
In procps-3.3.15/proc/readproc.c, lines 597 and 600.
Maybe lsof could also use libprocps7 for that, too?


Kind regards,
Bernhard


PS.: It looks like the value set by perl is even when terminated a
lot longer than '('. Therefore 'ps aux' prints a lot of spaces
for the process name. Would that justify to open an bug there too?

root@debian:~# hexdump -C /proc/13957/cmdline
00000000  28 00 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |(.              |
00000010  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000100  00                                                |.|
00000101
# Minimal Qemu VMs 2019-08-19


##########

apt update
apt dist-upgrade

reboot


##########


root@debian:~# cat /etc/debian_version 
bullseye/sid
root@debian:~# perl -E '$0 = "with-hyphen (and paren)"; print "My PID is $$\n"; 
<STDIN>'
My PID is 473
...

root@debian:~# lsof -p 473
root@debian:~# ps aux | grep 473
root       473  0.0  0.1  10572  4532 pts/0    S+   22:42   0:00 with-hyphen 
(and paren)                                                                     
                                                                                
                                                                                
                          
root       494  0.0  0.0   6088   828 pts/1    S+   23:19   0:00 grep 473
root@debian:~# 


#########


root@debian:~# cat /etc/debian_version 
10.0
root@debian:~# perl -E '$0 = "with-hyphen (and paren)"; print "My PID is $$\n"; 
<STDIN>'
My PID is 456
...

root@debian:~# lsof -p 456
root@debian:~# ps aux | grep 456
root       456  0.0  0.1  10572  4228 pts/0    S+   22:43   0:00 with-hyphen 
(and paren)                                                                     
                                                                                
                                                                                
                          
root       486  0.0  0.0   6088   892 pts/1    S+   23:18   0:00 grep 456
root@debian:~# 


#########


root@debian:~# cat /etc/debian_version 
9.9
root@debian:~# perl -E '$0 = "with-hyphen (and paren)"; print "My PID is $$\n"; 
<STDIN>'
My PID is 519
...

root@debian:~# lsof -p 519
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
with-hyph 519 root  cwd    DIR    8,1     4096 1048579 /root
with-hyph 519 root  rtd    DIR    8,1     4096       2 /
with-hyph 519 root  txt    REG    8,1  2021960  919288 /usr/bin/perl
with-hyph 519 root  mem    REG    8,1    39256  655504 
/lib/x86_64-linux-gnu/libcrypt-2.24.so
with-hyph 519 root  mem    REG    8,1  1689360  655486 
/lib/x86_64-linux-gnu/libc-2.24.so
with-hyph 519 root  mem    REG    8,1   135440  655655 
/lib/x86_64-linux-gnu/libpthread-2.24.so
with-hyph 519 root  mem    REG    8,1  1063328  655508 
/lib/x86_64-linux-gnu/libm-2.24.so
with-hyph 519 root  mem    REG    8,1    14640  655506 
/lib/x86_64-linux-gnu/libdl-2.24.so
with-hyph 519 root  mem    REG    8,1   153288  655396 
/lib/x86_64-linux-gnu/ld-2.24.so
with-hyph 519 root  mem    REG    8,1  1679840  918472 
/usr/lib/locale/locale-archive
with-hyph 519 root    0u   CHR  136,0      0t0       3 /dev/pts/0
with-hyph 519 root    1u   CHR  136,0      0t0       3 /dev/pts/0
with-hyph 519 root    2u   CHR  136,0      0t0       3 /dev/pts/0
root@debian:~# 


--> Got introduced between Stretch and Buster release?
2017-06-17: Initial release: 9.0
2019-07-06: Initial release: 10.0


#########


/etc/approx/approx.conf
debian-10-buster-snapshot.debian.org                          
https://snapshot.debian.org/archive/debian/20170701T000000Z/


sources.list
deb     [check-valid-until=no] 
http://192.168.178.25:9999/debian-10-buster-snapshot.debian.org/ buster main


dpkg --purge apt-listchanges
rm /var/lib/apt/lists/192*
apt update -o "Acquire::Languages=none"
apt dist-upgrade



20170701: works
20171001: works
20180101: works
20180401: works
20180701: works
20181001: works
20190101: works
20190115: works
20190118: works
20190121: works

    apt apt-utils debconf debconf-i18n krb5-locales libapt-inst2.0 
libapt-pkg5.0 libcurl3-gnutls libgssapi-krb5-2 libk5crypto3 libkrb5-3 
libkrb5support0 libpython-stdlib libpython2-stdlib lsof python python-minimal 
python2 python2-minimal python3-pkg-resources
  --> installs lsof amd64 4.91+dfsg-1
  
20190124: fails
20190201: fails
20190401: fails



##########


Bullseye/testing amd64 qemu VM 2019-08-20



apt install mc strace gdb dpkg-dev devscripts lsof-dbgsym procps-dbgsym 
libprocps7-dbgsym
apt build-dep lsof



mkdir /home/benutzer/source/lsof/orig -p
cd    /home/benutzer/source/lsof/orig
apt source lsof
cd

mkdir /home/benutzer/source/procps/orig -p
cd    /home/benutzer/source/procps/orig
apt source procps
cd




mkdir /home/benutzer/source/lsof/upstream -p
cd    /home/benutzer/source/lsof/upstream
wget 
https://www.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/OLD/lsof_4.89.tar.gz
wget 
https://www.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/OLD/lsof_4.90.tar.gz
wget 
https://www.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_4.91.tar.gz

tar -zxf lsof_4.89.tar.gz
cd lsof_4.89
tar -xf lsof_4.89_src.tar
cd lsof_4.89_src
git init
git add .
git commit -m "lsof_4.89.tar.gz"
cd ../..

tar -zxf lsof_4.90.tar.gz
cd lsof_4.90
tar -xf lsof_4.90_src.tar
cd lsof_4.90_src
mv ../../lsof_4.89/lsof_4.89_src/.git .
git add .
git commit -m "lsof_4.90.tar.gz"

tar -zxf lsof_4.91.tar.gz
cd lsof_4.91
tar -xf lsof_4.91_src.tar
cd lsof_4.91_src
mv ../../lsof_4.90/lsof_4.90_src/.git .
git add .
git commit -m "lsof_4.91.tar.gz"







gdb -q --args lsof -p 4929

set width 0
set pagination off
directory /home/benutzer/source/lsof/orig/lsof-4.91+dfsg
directory /home/benutzer/source/lsof/orig/lsof-4.91+dfsg/dialects/linux
tb main
run




##########



root@debian:~# perl -E '$0 = "12345678901234567890"; print "My PID is $$\n"; 
<STDIN>'
My PID is 13939
root@debian:~# hexdump -C /proc/13939/stat
00000000  31 33 39 33 39 20 28 31  32 33 34 35 36 37 38 39  |13939 (123456789|
00000010  30 31 32 33 34 35 29 20  53 20 34 39 32 36 20 31  |012345) S 4926 1|
...

root@debian:~# hexdump -C /proc/13942/stat
00000000  31 33 39 34 32 20 28 28  29 20 53 20 34 39 32 36  |13942 (() S 4926|
...
*
00000130  33 38 36 20 30 0a                                 |386 0.|
00000136
root@debian:~# lsof -p 13942
root@debian:~# ps aux | grep 13942
root     13942  0.0  0.1  10572  4648 pts/2    S+   10:34   0:00 (              
                                                                                
                                                                                
                                                                                
 
root     13947  0.0  0.0   6088   888 pts/4    S+   10:35   0:00 grep 13942



http://man7.org/linux/man-pages/man5/proc.5.html



##########


gdb -q --args ps aux -q 13957

set width 0
set pagination off
directory /home/benutzer/source/procps/orig/procps-3.3.15
b stat2proc
y
run
cont

Reply via email to