Use kvm_getprocs2 so independant of kernel version
(change aggreed by christos)
This commit is contained in:
parent
5aef2cf2a4
commit
7e2ddd8ef0
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: fstat.c,v 1.57 2002/10/26 06:03:50 yamt Exp $ */
|
/* $NetBSD: fstat.c,v 1.58 2003/01/19 18:14:06 dsl Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1988, 1993
|
* Copyright (c) 1988, 1993
|
||||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
|
static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: fstat.c,v 1.57 2002/10/26 06:03:50 yamt Exp $");
|
__RCSID("$NetBSD: fstat.c,v 1.58 2003/01/19 18:14:06 dsl Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ int maxfiles;
|
|||||||
|
|
||||||
kvm_t *kd;
|
kvm_t *kd;
|
||||||
|
|
||||||
void dofiles __P((struct kinfo_proc *));
|
void dofiles __P((struct kinfo_proc2 *));
|
||||||
int ext2fs_filestat __P((struct vnode *, struct filestat *));
|
int ext2fs_filestat __P((struct vnode *, struct filestat *));
|
||||||
int getfname __P((char *));
|
int getfname __P((char *));
|
||||||
void getinetproto __P((int));
|
void getinetproto __P((int));
|
||||||
@ -175,7 +175,7 @@ main(argc, argv)
|
|||||||
char **argv;
|
char **argv;
|
||||||
{
|
{
|
||||||
struct passwd *passwd;
|
struct passwd *passwd;
|
||||||
struct kinfo_proc *p, *plast;
|
struct kinfo_proc2 *p, *plast;
|
||||||
int arg, ch, what;
|
int arg, ch, what;
|
||||||
char *memf, *nlistf;
|
char *memf, *nlistf;
|
||||||
char buf[_POSIX2_LINE_MAX];
|
char buf[_POSIX2_LINE_MAX];
|
||||||
@ -263,7 +263,7 @@ main(argc, argv)
|
|||||||
if (nlistf == NULL && memf == NULL)
|
if (nlistf == NULL && memf == NULL)
|
||||||
(void)setgid(getgid());
|
(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));
|
errx(1, "%s", kvm_geterr(kd));
|
||||||
}
|
}
|
||||||
if (nflg)
|
if (nflg)
|
||||||
@ -278,7 +278,7 @@ main(argc, argv)
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
for (plast = &p[cnt]; p < plast; ++p) {
|
for (plast = &p[cnt]; p < plast; ++p) {
|
||||||
if (p->kp_proc.p_stat == SZOMB)
|
if (p->p_stat == SZOMB)
|
||||||
continue;
|
continue;
|
||||||
dofiles(p);
|
dofiles(p);
|
||||||
}
|
}
|
||||||
@ -311,33 +311,31 @@ pid_t Pid;
|
|||||||
* print open files attributed to this process
|
* print open files attributed to this process
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
dofiles(kp)
|
dofiles(p)
|
||||||
struct kinfo_proc *kp;
|
struct kinfo_proc2 *p;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct filedesc0 filed0;
|
struct filedesc0 filed0;
|
||||||
#define filed filed0.fd_fd
|
#define filed filed0.fd_fd
|
||||||
struct cwdinfo cwdi;
|
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;
|
Pid = p->p_pid;
|
||||||
Comm = p->p_comm;
|
Comm = p->p_comm;
|
||||||
|
|
||||||
if (p->p_fd == NULL || p->p_cwdi == NULL)
|
if (p->p_fd == NULL || p->p_cwdi == NULL)
|
||||||
return;
|
return;
|
||||||
if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (!KVM_READ(p->p_cwdi, &cwdi, sizeof(cwdi))) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles ||
|
if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles ||
|
||||||
filed.fd_freefile > filed.fd_lastfile + 1) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -353,7 +351,7 @@ dofiles(kp)
|
|||||||
* ktrace vnode, if one
|
* ktrace vnode, if one
|
||||||
*/
|
*/
|
||||||
if (p->p_tracep)
|
if (p->p_tracep)
|
||||||
ftrans(p->p_tracep, TRACE);
|
ftrans((struct file *)(intptr_t)p->p_tracep, TRACE);
|
||||||
/*
|
/*
|
||||||
* open files
|
* open files
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user