Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jan 2023 16:43:48 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: dd2b23006caa - main - fuser: fix loop over kinfo_proc array
Message-ID:  <202301091643.309GhmBt079548@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by glebius:

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(-)

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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301091643.309GhmBt079548>