Subject: bin/17578: change fstat to use kvm_getproc2 instead of kvm_getproc
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dsl@l8s.co.uk>
List: netbsd-bugs
Date: 07/12/2002 15:39:57
>Number:         17578
>Category:       bin
>Synopsis:       change fstat to use kvm_getproc2 instead of kvm_getproc
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 12 07:39:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     David Laight
>Release:        NetBSD 1.6B
>Organization:
no
>Environment:
System: NetBSD snowdrop 1.6B NetBSD 1.6B (GENERIC) #18: Wed Jul 10 14:41:14 BST 2002
dsl@snowdrop:/oldroot/usr/bsd-current/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	fstat uses kvm_getprocs() to obtain information about
	processes.  This data returned by this fuction contains
	structures that are likely to be kernel dependant.

	Replacing the calls with kvm_getproc2() will remove
	any links between fstat and the kernel headers.
>How-To-Repeat:
>Fix:
	Apply the following diffs:
Index: fstat.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/fstat/fstat.c,v
retrieving revision 1.55
diff -u -r1.55 fstat.c
--- fstat.c	2002/02/12 03:28:20	1.55
+++ fstat.c	2002/07/12 14:33:17
@@ -148,7 +148,7 @@
 
 kvm_t *kd;
 
-void	dofiles __P((struct kinfo_proc *));
+void	dofiles __P((struct kinfo_proc2 *));
 int	ext2fs_filestat __P((struct vnode *, struct filestat *));
 int	getfname __P((char *));
 void	getinetproto __P((int));
@@ -174,7 +174,7 @@
 	char **argv;
 {
 	struct passwd *passwd;
-	struct kinfo_proc *p, *plast;
+	struct kinfo_proc2 *p, *plast;
 	int arg, ch, what;
 	char *memf, *nlistf;
 	char buf[_POSIX2_LINE_MAX];
@@ -262,7 +262,7 @@
 	if (nlistf == NULL && memf == NULL)
 		(void)setgid(getgid());
 
-	if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) {
+	if ((p = kvm_getproc2(kd, what, arg, sizeof *p, &cnt)) == NULL) {
 		errx(1, "%s", kvm_geterr(kd));
 	}
 	if (nflg)
@@ -277,7 +277,7 @@
 		putchar('\n');
 
 	for (plast = &p[cnt]; p < plast; ++p) {
-		if (p->kp_proc.p_stat == SZOMB)
+		if (p->p_stat == SZOMB)
 			continue;
 		dofiles(p);
 	}
@@ -310,33 +310,31 @@
  * print open files attributed to this process
  */
 void
-dofiles(kp)
-	struct kinfo_proc *kp;
+dofiles(p)
+	struct kinfo_proc2 *p;
 {
 	int i;
 	struct filedesc0 filed0;
 #define	filed	filed0.fd_fd
 	struct cwdinfo cwdi;
-	struct proc *p = &kp->kp_proc;
-	struct eproc *ep = &kp->kp_eproc;
 
-	Uname = user_from_uid(ep->e_ucred.cr_uid, 0);
+	Uname = user_from_uid(p->p_uid, 0);
 	Pid = p->p_pid;
 	Comm = p->p_comm;
 
 	if (p->p_fd == NULL || p->p_cwdi == NULL)
 		return;
 	if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) {
-		warnx("can't read filedesc at %p for pid %d", p->p_fd, Pid);
+		warnx("can't read filedesc at %#llx for pid %d", p->p_fd, Pid);
 		return;
 	}
 	if (!KVM_READ(p->p_cwdi, &cwdi, sizeof(cwdi))) {
-		warnx("can't read cwdinfo at %p for pid %d", p->p_cwdi, Pid);
+		warnx("can't read cwdinfo at %#llx for pid %d", p->p_cwdi, Pid);
 		return;
 	}
 	if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles ||
 	    filed.fd_freefile > filed.fd_lastfile + 1) {
-		dprintf("filedesc corrupted at %p for pid %d", p->p_fd, Pid);
+		dprintf("filedesc corrupted at %#llx for pid %d", p->p_fd, Pid);
 		return;
 	}
 	/*
@@ -352,7 +350,7 @@
 	 * ktrace vnode, if one
 	 */
 	if (p->p_tracep)
-		ftrans(p->p_tracep, TRACE);
+		ftrans((struct file *)(intptr_t)p->p_tracep, TRACE);
 	/*
 	 * open files
 	 */
>Release-Note:
>Audit-Trail:
>Unformatted: