Summary: | fuser does not list id of processes that have a file | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Ali Abdallah <ali.abdallah> | ||||||
Component: | kern | Assignee: | Gleb Smirnoff <glebius> | ||||||
Status: | Closed FIXED | ||||||||
Severity: | Affects Some People | CC: | avg, danfe, eugen, glebius | ||||||
Priority: | --- | ||||||||
Version: | CURRENT | ||||||||
Hardware: | Any | ||||||||
OS: | Any | ||||||||
Attachments: |
|
Description
Ali Abdallah
2018-10-26 09:50:04 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? 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.
(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? Any change to get the proposed patch committed? 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. Created attachment 239294 [details]
better code, I believe
Reassign to glebius as discussed. Ali, please confirm you agree with suggested patch and I will commit it promptly. Gleb yes I agree with the fix, and yes it is a better code. Thanks! 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(-) Eugene, Gleb, thank you guys for doing the legwork. Ali, sorry it took us so long! 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(-) |