git: 82ed3fb02543 - stable/13 - fuser: fix loop over kinfo_proc array
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Jan 2023 15:44:40 UTC
The branch stable/13 has been updated by glebius: 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(-) diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c index ad4aebf4a2cb..2d9aa72875f4 100644 --- a/usr.bin/fstat/fuser.c +++ b/usr.bin/fstat/fuser.c @@ -163,12 +163,12 @@ int do_fuser(int argc, char *argv[]) { struct consumer *consumer; - struct kinfo_proc *p, *procs; + struct kinfo_proc *procs; struct procstat *procstat; struct reqfile *reqfiles; char *ep, *nlistf, *memf; - int ch, cnt, sig; - unsigned int i, nfiles; + int ch, sig; + unsigned int i, cnt, nfiles; sig = SIGKILL; /* Default to kill. */ nlistf = NULL; @@ -253,10 +253,9 @@ do_fuser(int argc, char *argv[]) /* * Walk through process table and look for matching files. */ - p = procs; - while(cnt--) - if (p->ki_stat != SZOMB) - dofiles(procstat, p++, reqfiles, nfiles); + for (i = 0; i < cnt; i++) + if (procs[i].ki_stat != SZOMB) + dofiles(procstat, &procs[i], reqfiles, nfiles); for (i = 0; i < nfiles; i++) { fprintf(stderr, "%s:", reqfiles[i].name);