Bug 232702 - fuser does not list id of processes that have a file
Summary: fuser does not list id of processes that have a file
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Gleb Smirnoff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-26 09:50 UTC by Ali Abdallah
Modified: 2023-01-23 15:45 UTC (History)
4 users (show)

See Also:


Attachments
Fix looping over active processes (840 bytes, patch)
2022-05-25 09:22 UTC, Ali Abdallah
no flags Details | Diff
better code, I believe (965 bytes, patch)
2023-01-06 06:08 UTC, Gleb Smirnoff
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Abdallah 2018-10-26 09:50:04 UTC
less .vimrc
on another term tab

fuser .vimrc
.vimrc:

gives no pid, on FreeBSD 11.2 the above works as expected.

filesystem is UFS2.
Comment 1 Alexey Dokuchaev freebsd_committer freebsd_triage 2022-05-24 18:42:05 UTC
It might be the same issue as bug #259504.  Could you update past that change (if you're running -CURRENT, you should probably know how/what to do) and see if the problem disappears?
Comment 2 Ali Abdallah 2022-05-25 09:22:07 UTC
Created attachment 234203 [details]
Fix looping over active processes

I haven't tested fuser since long time. I'm running 13.1 now on multiple machines, fuser sometimes gets active processes opening a specific file, and sometimes not! 

It seemed random for me, but after having a closer look at the code, I think the following loop is wrong:

while(cnt--)
    if (p->ki_stat != SZOMB)
        dofiles(procstat, p++, reqfiles, nfiles);

The above might skip active process entries, and IMHO it should be as follows

while(cnt--) {
    if (p->ki_stat != SZOMB) {
        dofiles(procstat, p, reqfiles, nfiles);
    }
    p++;
}

Attached a tiny patch that fixes the issue for me.
Comment 3 Alexey Dokuchaev freebsd_committer freebsd_triage 2022-05-25 09:37:55 UTC
(In reply to Ali Abdallah from comment #2)
> Fix looping over active processes
Thanks a lot for your time and this investigation Ali!  Andriy, since you've fixed similar bug #259504, could you please take look at this as well?
Comment 4 Ali Abdallah 2022-08-26 20:19:53 UTC
Any change to get the proposed patch committed?
Comment 5 Gleb Smirnoff freebsd_committer freebsd_triage 2023-01-06 06:08:02 UTC
What about this code:

for (i = 0 ; i < cnt; i++)
    if (procs[i].ki_stat != SZOMB)
        dofiles(procstat, &procs[i], reqfiles, nfiles);


Attached patch also fixes type of cnt.
Comment 6 Gleb Smirnoff freebsd_committer freebsd_triage 2023-01-06 06:08:34 UTC
Created attachment 239294 [details]
better code, I believe
Comment 7 Eugene Grosbein freebsd_committer freebsd_triage 2023-01-06 06:22:00 UTC
Reassign to glebius as discussed.
Comment 8 Gleb Smirnoff freebsd_committer freebsd_triage 2023-01-06 06:25:28 UTC
Ali, please confirm you agree with suggested patch and I will commit it promptly.
Comment 9 Ali Abdallah 2023-01-09 08:12:00 UTC
Gleb yes I agree with the fix, and yes it is a better code. Thanks!
Comment 10 commit-hook freebsd_committer freebsd_triage 2023-01-09 16:44:28 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=dd2b23006caa2323a12749dfc0d831a26a79bc5b

commit dd2b23006caa2323a12749dfc0d831a26a79bc5b
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2023-01-09 16:40:20 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2023-01-09 16:40:20 +0000

    fuser: fix loop over kinfo_proc array

    The previous code would skip as many entries at the end of the
    array as there were zombies in the list.  While here fix type
    of cnt.

    Submitted by:   Ali Abdallah <ali.abdallah suse.com>
    PR:             232702
    MFC After:      2 weeks

 usr.bin/fstat/fuser.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Comment 11 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-01-10 03:07:48 UTC
Eugene, Gleb, thank you guys for doing the legwork.  Ali, sorry it took us so long!
Comment 12 commit-hook freebsd_committer freebsd_triage 2023-01-23 15:45:10 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=82ed3fb02543af31840fdb2b0c26c77f3ae6cd5e

commit 82ed3fb02543af31840fdb2b0c26c77f3ae6cd5e
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2023-01-09 16:40:20 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2023-01-23 15:43:46 +0000

    fuser: fix loop over kinfo_proc array

    The previous code would skip as many entries at the end of the
    array as there were zombies in the list.  While here fix type
    of cnt.

    Submitted by:   Ali Abdallah <ali.abdallah suse.com>
    PR:             232702

    (cherry picked from commit dd2b23006caa2323a12749dfc0d831a26a79bc5b)

 usr.bin/fstat/fuser.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)