1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-07-08 11:02:48 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1988, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-07-08 11:02:48 +00:00
|
|
|
#if 0
|
1997-03-11 13:43:33 +00:00
|
|
|
static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
|
1997-07-08 11:02:48 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
1998-05-16 21:35:37 +00:00
|
|
|
#include <sys/un.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/unpcb.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/filedesc.h>
|
1995-04-10 00:38:15 +00:00
|
|
|
#include <sys/queue.h>
|
1996-08-24 08:01:29 +00:00
|
|
|
#include <sys/pipe.h>
|
1999-12-29 05:07:58 +00:00
|
|
|
#define _KERNEL
|
2001-05-23 23:03:00 +00:00
|
|
|
#include <sys/conf.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/file.h>
|
2002-08-14 16:34:13 +00:00
|
|
|
#include <sys/mount.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
2001-12-17 13:42:46 +00:00
|
|
|
#include <fs/devfs/devfs.h>
|
2000-12-04 09:21:05 +00:00
|
|
|
#undef _KERNEL
|
1995-06-27 11:07:30 +00:00
|
|
|
#include <nfs/nfsproto.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <nfs/rpcv2.h>
|
2001-09-18 23:34:44 +00:00
|
|
|
#include <nfsclient/nfs.h>
|
|
|
|
#include <nfsclient/nfsnode.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-03-16 02:02:34 +00:00
|
|
|
|
2000-04-05 05:45:40 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1997-07-08 11:02:48 +00:00
|
|
|
#include <err.h>
|
1996-09-29 19:25:10 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <kvm.h>
|
1997-03-11 13:43:33 +00:00
|
|
|
#include <limits.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-03-11 13:43:33 +00:00
|
|
|
#include <unistd.h>
|
1999-07-02 13:25:49 +00:00
|
|
|
#include <netdb.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-03-16 02:02:34 +00:00
|
|
|
#include "fstat.h"
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#define TEXT -1
|
|
|
|
#define CDIR -2
|
|
|
|
#define RDIR -3
|
|
|
|
#define TRACE -4
|
2000-04-05 05:45:40 +00:00
|
|
|
#define MMAP -5
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
DEVS *devs;
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
struct nlist nl[] = {
|
|
|
|
{ "" },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int fsflg, /* show files on same filesystem as file(s) argument */
|
|
|
|
pflg, /* show files open by a particular pid */
|
|
|
|
uflg; /* show files open by a particular (effective) user */
|
|
|
|
int checkfile; /* true if restricting to particular files or filesystems */
|
|
|
|
int nflg; /* (numerical) display f.s. and rdev as dev_t */
|
|
|
|
int vflg; /* display errors in locating kernel data objects etc... */
|
2000-04-05 05:45:40 +00:00
|
|
|
int mflg; /* include memory-mapped files */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct file **ofiles; /* buffer of pointers to file structures */
|
|
|
|
int maxfiles;
|
|
|
|
#define ALLOC_OFILES(d) \
|
|
|
|
if ((d) > maxfiles) { \
|
|
|
|
free(ofiles); \
|
|
|
|
ofiles = malloc((d) * sizeof(struct file *)); \
|
|
|
|
if (ofiles == NULL) { \
|
1997-07-08 11:02:48 +00:00
|
|
|
err(1, NULL); \
|
1994-05-27 12:33:43 +00:00
|
|
|
} \
|
|
|
|
maxfiles = (d); \
|
|
|
|
}
|
|
|
|
|
2002-06-06 18:39:53 +00:00
|
|
|
char *memf, *nlistf;
|
1994-05-27 12:33:43 +00:00
|
|
|
kvm_t *kd;
|
|
|
|
|
2002-06-06 18:39:53 +00:00
|
|
|
static void fstat_kvm(int, int);
|
|
|
|
static void fstat_sysctl(int, int);
|
2002-03-22 01:22:50 +00:00
|
|
|
void dofiles(struct kinfo_proc *kp);
|
|
|
|
void dommap(struct kinfo_proc *kp);
|
|
|
|
void vtrans(struct vnode *vp, int i, int flag);
|
|
|
|
int ufs_filestat(struct vnode *vp, struct filestat *fsp);
|
|
|
|
int nfs_filestat(struct vnode *vp, struct filestat *fsp);
|
|
|
|
int devfs_filestat(struct vnode *vp, struct filestat *fsp);
|
|
|
|
char *getmnton(struct mount *m);
|
|
|
|
void pipetrans(struct pipe *pi, int i, int flag);
|
|
|
|
void socktrans(struct socket *sock, int i);
|
|
|
|
void getinetproto(int number);
|
2002-03-30 14:03:53 +00:00
|
|
|
int getfname(const char *filename);
|
2002-03-22 01:22:50 +00:00
|
|
|
void usage(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-08-24 08:01:29 +00:00
|
|
|
|
|
|
|
int
|
1994-05-27 12:33:43 +00:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
2002-03-30 14:03:53 +00:00
|
|
|
struct passwd *passwd;
|
1994-05-27 12:33:43 +00:00
|
|
|
int arg, ch, what;
|
|
|
|
|
|
|
|
arg = 0;
|
|
|
|
what = KERN_PROC_ALL;
|
|
|
|
nlistf = memf = NULL;
|
2000-04-05 05:45:40 +00:00
|
|
|
while ((ch = getopt(argc, argv, "fmnp:u:vN:M:")) != -1)
|
1994-05-27 12:33:43 +00:00
|
|
|
switch((char)ch) {
|
|
|
|
case 'f':
|
|
|
|
fsflg = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
2000-04-05 05:45:40 +00:00
|
|
|
case 'm':
|
|
|
|
mflg = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'n':
|
|
|
|
nflg = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if (pflg++)
|
|
|
|
usage();
|
|
|
|
if (!isdigit(*optarg)) {
|
1997-07-10 06:41:33 +00:00
|
|
|
warnx("-p requires a process id");
|
1994-05-27 12:33:43 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
what = KERN_PROC_PID;
|
|
|
|
arg = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
if (uflg++)
|
|
|
|
usage();
|
1997-07-08 11:02:48 +00:00
|
|
|
if (!(passwd = getpwnam(optarg)))
|
|
|
|
errx(1, "%s: unknown uid", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
what = KERN_PROC_UID;
|
|
|
|
arg = passwd->pw_uid;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
vflg = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*(argv += optind)) {
|
|
|
|
for (; *argv; ++argv) {
|
|
|
|
if (getfname(*argv))
|
|
|
|
checkfile = 1;
|
|
|
|
}
|
|
|
|
if (!checkfile) /* file(s) specified, but none accessable */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1995-05-30 06:41:30 +00:00
|
|
|
if (fsflg && !checkfile) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/* -f with no files means use wd */
|
|
|
|
if (getfname(".") == 0)
|
|
|
|
exit(1);
|
|
|
|
checkfile = 1;
|
|
|
|
}
|
|
|
|
|
2002-06-06 18:39:53 +00:00
|
|
|
if (memf != NULL)
|
|
|
|
fstat_kvm(what, arg);
|
|
|
|
else
|
|
|
|
fstat_sysctl(what, arg);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_header(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nflg)
|
|
|
|
printf("%s",
|
|
|
|
"USER CMD PID FD DEV INUM MODE SZ|DV R/W");
|
|
|
|
else
|
|
|
|
printf("%s",
|
|
|
|
"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W");
|
|
|
|
if (checkfile && fsflg == 0)
|
|
|
|
printf(" NAME\n");
|
|
|
|
else
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fstat_kvm(int what, int arg)
|
|
|
|
{
|
|
|
|
struct kinfo_proc *p, *plast;
|
|
|
|
char buf[_POSIX2_LINE_MAX];
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
ALLOC_OFILES(256); /* reserve space for file pointers */
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Discard setgid privileges if not the running kernel so that bad
|
|
|
|
* guys can't print interesting stuff from kernel memory.
|
|
|
|
*/
|
|
|
|
if (nlistf != NULL || memf != NULL)
|
|
|
|
setgid(getgid());
|
|
|
|
|
1997-07-08 11:02:48 +00:00
|
|
|
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL)
|
|
|
|
errx(1, "%s", buf);
|
2001-08-31 16:26:37 +00:00
|
|
|
setgid(getgid());
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifdef notdef
|
1997-07-08 11:02:48 +00:00
|
|
|
if (kvm_nlist(kd, nl) != 0)
|
|
|
|
errx(1, "no namelist: %s", kvm_geterr(kd));
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
1997-07-08 11:02:48 +00:00
|
|
|
if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL)
|
|
|
|
errx(1, "%s", kvm_geterr(kd));
|
1994-05-27 12:33:43 +00:00
|
|
|
for (plast = &p[cnt]; p < plast; ++p) {
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (p->ki_stat == SZOMB)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
dofiles(p);
|
2000-04-05 05:45:40 +00:00
|
|
|
if (mflg)
|
|
|
|
dommap(p);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2002-06-06 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fstat_sysctl(int what, int arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* not yet implemented */
|
|
|
|
fstat_kvm(what, arg);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2002-03-30 14:03:53 +00:00
|
|
|
const char *Uname, *Comm;
|
1994-05-27 12:33:43 +00:00
|
|
|
int Pid;
|
|
|
|
|
|
|
|
#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \
|
|
|
|
switch(i) { \
|
|
|
|
case TEXT: \
|
|
|
|
printf(" text"); \
|
|
|
|
break; \
|
|
|
|
case CDIR: \
|
|
|
|
printf(" wd"); \
|
|
|
|
break; \
|
|
|
|
case RDIR: \
|
|
|
|
printf(" root"); \
|
|
|
|
break; \
|
|
|
|
case TRACE: \
|
|
|
|
printf(" tr"); \
|
|
|
|
break; \
|
2000-04-05 05:45:40 +00:00
|
|
|
case MMAP: \
|
|
|
|
printf(" mmap"); \
|
|
|
|
break; \
|
1994-05-27 12:33:43 +00:00
|
|
|
default: \
|
|
|
|
printf(" %4d", i); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print open files attributed to this process
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dofiles(kp)
|
|
|
|
struct kinfo_proc *kp;
|
|
|
|
{
|
1997-07-08 11:02:48 +00:00
|
|
|
int i;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct file file;
|
|
|
|
struct filedesc0 filed0;
|
|
|
|
#define filed filed0.fd_fd
|
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
Uname = user_from_uid(kp->ki_uid, 0);
|
|
|
|
Pid = kp->ki_pid;
|
|
|
|
Comm = kp->ki_comm;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_fd == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (!KVM_READ(kp->ki_fd, &filed0, sizeof (filed0))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read filedesc at %p for pid %d\n",
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
(void *)kp->ki_fd, Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* root directory vnode, if one
|
|
|
|
*/
|
|
|
|
if (filed.fd_rdir)
|
|
|
|
vtrans(filed.fd_rdir, RDIR, FREAD);
|
|
|
|
/*
|
|
|
|
* current working directory vnode
|
|
|
|
*/
|
|
|
|
vtrans(filed.fd_cdir, CDIR, FREAD);
|
|
|
|
/*
|
|
|
|
* ktrace vnode, if one
|
|
|
|
*/
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_tracep)
|
|
|
|
vtrans(kp->ki_tracep, TRACE, FREAD|FWRITE);
|
1996-08-24 13:43:46 +00:00
|
|
|
/*
|
|
|
|
* text vnode, if one
|
|
|
|
*/
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_textvp)
|
|
|
|
vtrans(kp->ki_textvp, TEXT, FREAD);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* open files
|
|
|
|
*/
|
|
|
|
#define FPSIZE (sizeof (struct file *))
|
|
|
|
ALLOC_OFILES(filed.fd_lastfile+1);
|
|
|
|
if (filed.fd_nfiles > NDFILE) {
|
|
|
|
if (!KVM_READ(filed.fd_ofiles, ofiles,
|
|
|
|
(filed.fd_lastfile+1) * FPSIZE)) {
|
|
|
|
dprintf(stderr,
|
1998-07-06 21:01:54 +00:00
|
|
|
"can't read file structures at %p for pid %d\n",
|
|
|
|
(void *)filed.fd_ofiles, Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
bcopy(filed0.fd_dfiles, ofiles, (filed.fd_lastfile+1) * FPSIZE);
|
|
|
|
for (i = 0; i <= filed.fd_lastfile; i++) {
|
|
|
|
if (ofiles[i] == NULL)
|
|
|
|
continue;
|
|
|
|
if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read file %d at %p for pid %d\n",
|
|
|
|
i, (void *)ofiles[i], Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (file.f_type == DTYPE_VNODE)
|
|
|
|
vtrans((struct vnode *)file.f_data, i, file.f_flag);
|
|
|
|
else if (file.f_type == DTYPE_SOCKET) {
|
|
|
|
if (checkfile == 0)
|
|
|
|
socktrans((struct socket *)file.f_data, i);
|
|
|
|
}
|
1996-08-24 08:01:29 +00:00
|
|
|
#ifdef DTYPE_PIPE
|
|
|
|
else if (file.f_type == DTYPE_PIPE) {
|
|
|
|
if (checkfile == 0)
|
|
|
|
pipetrans((struct pipe *)file.f_data, i,
|
2001-06-18 06:29:31 +00:00
|
|
|
file.f_flag);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef DTYPE_FIFO
|
|
|
|
else if (file.f_type == DTYPE_FIFO) {
|
|
|
|
if (checkfile == 0)
|
|
|
|
vtrans((struct vnode *)file.f_data, i,
|
|
|
|
file.f_flag);
|
1996-08-24 08:01:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
else {
|
1995-05-30 06:41:30 +00:00
|
|
|
dprintf(stderr,
|
2001-06-18 06:29:31 +00:00
|
|
|
"unknown file type %d for file %d of pid %d\n",
|
|
|
|
file.f_type, i, Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-05 05:45:40 +00:00
|
|
|
void
|
|
|
|
dommap(kp)
|
|
|
|
struct kinfo_proc *kp;
|
|
|
|
{
|
|
|
|
vm_map_t map;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct vmspace vmspace;
|
2000-04-05 05:45:40 +00:00
|
|
|
struct vm_map_entry entry;
|
|
|
|
vm_map_entry_t entryp;
|
|
|
|
struct vm_object object;
|
|
|
|
vm_object_t objp;
|
|
|
|
int prot, fflags;
|
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (!KVM_READ(kp->ki_vmspace, &vmspace, sizeof(vmspace))) {
|
|
|
|
dprintf(stderr,
|
|
|
|
"can't read vmspace at %p for pid %d\n",
|
|
|
|
(void *)kp->ki_vmspace, Pid);
|
2000-04-05 05:45:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
map = &vmspace.vm_map;
|
|
|
|
|
2001-02-15 22:42:44 +00:00
|
|
|
for (entryp = map->header.next;
|
|
|
|
entryp != &kp->ki_vmspace->vm_map.header; entryp = entry.next) {
|
2000-04-05 05:45:40 +00:00
|
|
|
if (!KVM_READ(entryp, &entry, sizeof(entry))) {
|
|
|
|
dprintf(stderr,
|
|
|
|
"can't read vm_map_entry at %p for pid %d\n",
|
|
|
|
(void *)entryp, Pid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.eflags & MAP_ENTRY_IS_SUB_MAP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((objp = entry.object.vm_object) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (; objp; objp = object.backing_object) {
|
|
|
|
if (!KVM_READ(objp, &object, sizeof(object))) {
|
|
|
|
dprintf(stderr,
|
|
|
|
"can't read vm_object at %p for pid %d\n",
|
|
|
|
(void *)objp, Pid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prot = entry.protection;
|
|
|
|
fflags = (prot & VM_PROT_READ ? FREAD : 0) |
|
|
|
|
(prot & VM_PROT_WRITE ? FWRITE : 0);
|
|
|
|
|
|
|
|
switch (object.type) {
|
|
|
|
case OBJT_VNODE:
|
|
|
|
vtrans((struct vnode *)object.handle, MMAP, fflags);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
void
|
|
|
|
vtrans(vp, i, flag)
|
|
|
|
struct vnode *vp;
|
|
|
|
int i;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
struct vnode vn;
|
|
|
|
struct filestat fst;
|
2002-09-14 18:51:10 +00:00
|
|
|
char rw[3], mode[15], tagstr[12], *tagptr;
|
2002-03-30 14:03:53 +00:00
|
|
|
const char *badtype, *filename;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
filename = badtype = NULL;
|
|
|
|
if (!KVM_READ(vp, &vn, sizeof (struct vnode))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read vnode at %p for pid %d\n",
|
|
|
|
(void *)vp, Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-14 18:51:10 +00:00
|
|
|
if (!KVM_READ(&vp->v_tag, &tagptr, sizeof tagptr) ||
|
|
|
|
!KVM_READ(tagptr, tagstr, sizeof tagstr)) {
|
|
|
|
dprintf(stderr, "can't read v_tag at %p for pid %d\n",
|
|
|
|
(void *)vp, Pid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tagstr[sizeof(tagstr) - 1] = '\0';
|
|
|
|
if (vn.v_type == VNON)
|
1994-05-27 12:33:43 +00:00
|
|
|
badtype = "none";
|
|
|
|
else if (vn.v_type == VBAD)
|
|
|
|
badtype = "bad";
|
2002-09-14 18:51:10 +00:00
|
|
|
else {
|
|
|
|
if (!strcmp("ufs", tagstr)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!ufs_filestat(&vn, &fst))
|
|
|
|
badtype = "error";
|
2002-09-14 18:51:10 +00:00
|
|
|
} else if (!strcmp("devfs", tagstr)) {
|
2001-12-17 13:42:46 +00:00
|
|
|
if (!devfs_filestat(&vn, &fst))
|
|
|
|
badtype = "error";
|
2002-09-14 18:51:10 +00:00
|
|
|
} else if (!strcmp("nfs", tagstr)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!nfs_filestat(&vn, &fst))
|
|
|
|
badtype = "error";
|
2002-09-14 18:51:10 +00:00
|
|
|
} else if (!strcmp("msdosfs", tagstr)) {
|
2000-03-16 02:02:34 +00:00
|
|
|
if (!msdosfs_filestat(&vn, &fst))
|
|
|
|
badtype = "error";
|
2002-09-14 18:51:10 +00:00
|
|
|
} else if (!strcmp("isofs", tagstr)) {
|
2000-03-16 02:02:34 +00:00
|
|
|
if (!isofs_filestat(&vn, &fst))
|
|
|
|
badtype = "error";
|
2002-09-14 18:51:10 +00:00
|
|
|
} else {
|
|
|
|
static char unknown[32];
|
|
|
|
snprintf(unknown, sizeof unknown, "?(%s)", tagstr);
|
2002-03-30 14:03:53 +00:00
|
|
|
badtype = unknown;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checkfile) {
|
|
|
|
int fsmatch = 0;
|
2002-03-30 14:03:53 +00:00
|
|
|
DEVS *d;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (badtype)
|
|
|
|
return;
|
|
|
|
for (d = devs; d != NULL; d = d->next)
|
|
|
|
if (d->fsid == fst.fsid) {
|
|
|
|
fsmatch = 1;
|
|
|
|
if (d->ino == fst.fileid) {
|
|
|
|
filename = d->name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fsmatch == 0 || (filename == NULL && fsflg == 0))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PREFIX(i);
|
|
|
|
if (badtype) {
|
|
|
|
(void)printf(" - - %10s -\n", badtype);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nflg)
|
|
|
|
(void)printf(" %2d,%-2d", major(fst.fsid), minor(fst.fsid));
|
|
|
|
else
|
|
|
|
(void)printf(" %-8s", getmnton(vn.v_mount));
|
|
|
|
if (nflg)
|
|
|
|
(void)sprintf(mode, "%o", fst.mode);
|
|
|
|
else
|
|
|
|
strmode(fst.mode, mode);
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf(" %6ld %10s", fst.fileid, mode);
|
1994-05-27 12:33:43 +00:00
|
|
|
switch (vn.v_type) {
|
|
|
|
case VBLK:
|
|
|
|
case VCHR: {
|
|
|
|
char *name;
|
|
|
|
|
1995-05-30 06:41:30 +00:00
|
|
|
if (nflg || ((name = devname(fst.rdev, vn.v_type == VCHR ?
|
1994-05-27 12:33:43 +00:00
|
|
|
S_IFCHR : S_IFBLK)) == NULL))
|
|
|
|
printf(" %2d,%-2d", major(fst.rdev), minor(fst.rdev));
|
|
|
|
else
|
|
|
|
printf(" %6s", name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
1997-08-31 01:27:04 +00:00
|
|
|
printf(" %6lu", fst.size);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
rw[0] = '\0';
|
|
|
|
if (flag & FREAD)
|
|
|
|
strcat(rw, "r");
|
|
|
|
if (flag & FWRITE)
|
|
|
|
strcat(rw, "w");
|
|
|
|
printf(" %2s", rw);
|
|
|
|
if (filename && !fsflg)
|
|
|
|
printf(" %s", filename);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ufs_filestat(vp, fsp)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct filestat *fsp;
|
|
|
|
{
|
|
|
|
struct inode inode;
|
|
|
|
|
|
|
|
if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read inode at %p for pid %d\n",
|
|
|
|
(void *)VTOI(vp), Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-11-13 21:13:25 +00:00
|
|
|
/*
|
|
|
|
* The st_dev from stat(2) is a udev_t. These kernel structures
|
|
|
|
* contain dev_t structures. We need to convert to udev to make
|
|
|
|
* comparisons
|
|
|
|
*/
|
2001-11-05 20:40:24 +00:00
|
|
|
fsp->fsid = dev2udev(inode.i_dev);
|
1994-05-27 12:33:43 +00:00
|
|
|
fsp->fileid = (long)inode.i_number;
|
|
|
|
fsp->mode = (mode_t)inode.i_mode;
|
|
|
|
fsp->size = (u_long)inode.i_size;
|
2002-06-21 06:18:05 +00:00
|
|
|
#if should_be_but_is_hard
|
1994-05-27 12:33:43 +00:00
|
|
|
fsp->rdev = inode.i_rdev;
|
2002-06-21 06:18:05 +00:00
|
|
|
#else
|
|
|
|
fsp->rdev = 0;
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-12-17 13:42:46 +00:00
|
|
|
int
|
|
|
|
devfs_filestat(vp, fsp)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct filestat *fsp;
|
|
|
|
{
|
|
|
|
struct devfs_dirent devfs_dirent;
|
|
|
|
struct mount mount;
|
|
|
|
struct vnode vnode;
|
|
|
|
|
|
|
|
if (!KVM_READ(vp->v_data, &devfs_dirent, sizeof (devfs_dirent))) {
|
|
|
|
dprintf(stderr, "can't read devfs_dirent at %p for pid %d\n",
|
|
|
|
(void *)vp->v_data, Pid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!KVM_READ(vp->v_mount, &mount, sizeof (mount))) {
|
|
|
|
dprintf(stderr, "can't read mount at %p for pid %d\n",
|
|
|
|
(void *)vp->v_mount, Pid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!KVM_READ(devfs_dirent.de_vnode, &vnode, sizeof (vnode))) {
|
|
|
|
dprintf(stderr, "can't read vnode at %p for pid %d\n",
|
|
|
|
(void *)devfs_dirent.de_vnode, Pid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fsp->fsid = (long)mount.mnt_stat.f_fsid.val[0];
|
|
|
|
fsp->fileid = devfs_dirent.de_inode;
|
|
|
|
fsp->mode = (devfs_dirent.de_mode & ~S_IFMT) | S_IFCHR;
|
|
|
|
fsp->size = 0;
|
|
|
|
fsp->rdev = dev2udev((dev_t)vnode.v_rdev);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
int
|
|
|
|
nfs_filestat(vp, fsp)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct filestat *fsp;
|
|
|
|
{
|
|
|
|
struct nfsnode nfsnode;
|
2002-03-30 14:03:53 +00:00
|
|
|
mode_t mode;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (!KVM_READ(VTONFS(vp), &nfsnode, sizeof (nfsnode))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read nfsnode at %p for pid %d\n",
|
|
|
|
(void *)VTONFS(vp), Pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fsp->fsid = nfsnode.n_vattr.va_fsid;
|
|
|
|
fsp->fileid = nfsnode.n_vattr.va_fileid;
|
|
|
|
fsp->size = nfsnode.n_size;
|
|
|
|
fsp->rdev = nfsnode.n_vattr.va_rdev;
|
|
|
|
mode = (mode_t)nfsnode.n_vattr.va_mode;
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VREG:
|
|
|
|
mode |= S_IFREG;
|
|
|
|
break;
|
|
|
|
case VDIR:
|
|
|
|
mode |= S_IFDIR;
|
|
|
|
break;
|
|
|
|
case VBLK:
|
|
|
|
mode |= S_IFBLK;
|
|
|
|
break;
|
|
|
|
case VCHR:
|
|
|
|
mode |= S_IFCHR;
|
|
|
|
break;
|
|
|
|
case VLNK:
|
|
|
|
mode |= S_IFLNK;
|
|
|
|
break;
|
|
|
|
case VSOCK:
|
|
|
|
mode |= S_IFSOCK;
|
|
|
|
break;
|
|
|
|
case VFIFO:
|
|
|
|
mode |= S_IFIFO;
|
|
|
|
break;
|
1999-07-02 13:25:49 +00:00
|
|
|
case VNON:
|
|
|
|
case VBAD:
|
|
|
|
return 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
fsp->mode = mode;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
getmnton(m)
|
|
|
|
struct mount *m;
|
|
|
|
{
|
|
|
|
static struct mount mount;
|
|
|
|
static struct mtab {
|
|
|
|
struct mtab *next;
|
|
|
|
struct mount *m;
|
|
|
|
char mntonname[MNAMELEN];
|
|
|
|
} *mhead = NULL;
|
2002-03-30 14:03:53 +00:00
|
|
|
struct mtab *mt;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (mt = mhead; mt != NULL; mt = mt->next)
|
|
|
|
if (m == mt->m)
|
|
|
|
return (mt->mntonname);
|
|
|
|
if (!KVM_READ(m, &mount, sizeof(struct mount))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
warnx("can't read mount table at %p", (void *)m);
|
1994-05-27 12:33:43 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
1997-07-08 11:02:48 +00:00
|
|
|
if ((mt = malloc(sizeof (struct mtab))) == NULL)
|
|
|
|
err(1, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
mt->m = m;
|
|
|
|
bcopy(&mount.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN);
|
|
|
|
mt->next = mhead;
|
|
|
|
mhead = mt;
|
|
|
|
return (mt->mntonname);
|
|
|
|
}
|
|
|
|
|
1996-08-24 08:01:29 +00:00
|
|
|
void
|
|
|
|
pipetrans(pi, i, flag)
|
|
|
|
struct pipe *pi;
|
|
|
|
int i;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
struct pipe pip;
|
|
|
|
char rw[3];
|
|
|
|
|
|
|
|
PREFIX(i);
|
|
|
|
|
|
|
|
/* fill in socket */
|
|
|
|
if (!KVM_READ(pi, &pip, sizeof(struct pipe))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read pipe at %p\n", (void *)pi);
|
1996-08-24 08:01:29 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2001-07-25 20:31:20 +00:00
|
|
|
printf("* pipe %8lx <-> %8lx", (u_long)pi, (u_long)pip.pipe_peer);
|
1996-08-24 08:01:29 +00:00
|
|
|
printf(" %6d", (int)pip.pipe_buffer.cnt);
|
|
|
|
rw[0] = '\0';
|
|
|
|
if (flag & FREAD)
|
|
|
|
strcat(rw, "r");
|
|
|
|
if (flag & FWRITE)
|
|
|
|
strcat(rw, "w");
|
|
|
|
printf(" %2s", rw);
|
|
|
|
putchar('\n');
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
printf("* error\n");
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
void
|
|
|
|
socktrans(sock, i)
|
|
|
|
struct socket *sock;
|
|
|
|
int i;
|
|
|
|
{
|
2002-03-30 14:03:53 +00:00
|
|
|
static const char *stypename[] = {
|
1994-05-27 12:33:43 +00:00
|
|
|
"unused", /* 0 */
|
|
|
|
"stream", /* 1 */
|
|
|
|
"dgram", /* 2 */
|
|
|
|
"raw", /* 3 */
|
|
|
|
"rdm", /* 4 */
|
|
|
|
"seqpak" /* 5 */
|
|
|
|
};
|
|
|
|
#define STYPEMAX 5
|
|
|
|
struct socket so;
|
|
|
|
struct protosw proto;
|
|
|
|
struct domain dom;
|
|
|
|
struct inpcb inpcb;
|
|
|
|
struct unpcb unpcb;
|
|
|
|
int len;
|
2002-03-30 14:03:53 +00:00
|
|
|
char dname[32];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
PREFIX(i);
|
|
|
|
|
|
|
|
/* fill in socket */
|
|
|
|
if (!KVM_READ(sock, &so, sizeof(struct socket))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read sock at %p\n", (void *)sock);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in protosw entry */
|
|
|
|
if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read protosw at %p",
|
|
|
|
(void *)so.so_proto);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in domain */
|
|
|
|
if (!KVM_READ(proto.pr_domain, &dom, sizeof(struct domain))) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read domain at %p\n",
|
|
|
|
(void *)proto.pr_domain);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((len = kvm_read(kd, (u_long)dom.dom_name, dname,
|
|
|
|
sizeof(dname) - 1)) < 0) {
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read domain name at %p\n",
|
|
|
|
(void *)dom.dom_name);
|
1994-05-27 12:33:43 +00:00
|
|
|
dname[0] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dname[len] = '\0';
|
|
|
|
|
|
|
|
if ((u_short)so.so_type > STYPEMAX)
|
|
|
|
printf("* %s ?%d", dname, so.so_type);
|
|
|
|
else
|
|
|
|
printf("* %s %s", dname, stypename[so.so_type]);
|
|
|
|
|
1995-05-30 06:41:30 +00:00
|
|
|
/*
|
1994-05-27 12:33:43 +00:00
|
|
|
* protocol specific formatting
|
|
|
|
*
|
|
|
|
* Try to find interesting things to print. For tcp, the interesting
|
|
|
|
* thing is the address of the tcpcb, for udp and others, just the
|
|
|
|
* inpcb (socket pcb). For unix domain, its the address of the socket
|
|
|
|
* pcb and the address of the connected pcb (if connected). Otherwise
|
|
|
|
* just print the protocol number and address of the socket itself.
|
|
|
|
* The idea is not to duplicate netstat, but to make available enough
|
|
|
|
* information for further analysis.
|
|
|
|
*/
|
|
|
|
switch(dom.dom_family) {
|
|
|
|
case AF_INET:
|
2000-02-19 21:46:45 +00:00
|
|
|
case AF_INET6:
|
1994-05-27 12:33:43 +00:00
|
|
|
getinetproto(proto.pr_protocol);
|
|
|
|
if (proto.pr_protocol == IPPROTO_TCP ) {
|
|
|
|
if (so.so_pcb) {
|
|
|
|
if (kvm_read(kd, (u_long)so.so_pcb,
|
|
|
|
(char *)&inpcb, sizeof(struct inpcb))
|
|
|
|
!= sizeof(struct inpcb)) {
|
1995-05-30 06:41:30 +00:00
|
|
|
dprintf(stderr,
|
1998-07-06 21:01:54 +00:00
|
|
|
"can't read inpcb at %p\n",
|
|
|
|
(void *)so.so_pcb);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2001-07-25 20:31:20 +00:00
|
|
|
printf(" %lx", (u_long)inpcb.inp_ppcb);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (so.so_pcb)
|
2001-07-25 20:31:20 +00:00
|
|
|
printf(" %lx", (u_long)so.so_pcb);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case AF_UNIX:
|
|
|
|
/* print address of pcb and connected pcb */
|
|
|
|
if (so.so_pcb) {
|
2001-07-25 20:31:20 +00:00
|
|
|
printf(" %lx", (u_long)so.so_pcb);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb,
|
|
|
|
sizeof(struct unpcb)) != sizeof(struct unpcb)){
|
1998-07-06 21:01:54 +00:00
|
|
|
dprintf(stderr, "can't read unpcb at %p\n",
|
|
|
|
(void *)so.so_pcb);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (unpcb.unp_conn) {
|
|
|
|
char shoconn[4], *cp;
|
|
|
|
|
|
|
|
cp = shoconn;
|
|
|
|
if (!(so.so_state & SS_CANTRCVMORE))
|
|
|
|
*cp++ = '<';
|
|
|
|
*cp++ = '-';
|
|
|
|
if (!(so.so_state & SS_CANTSENDMORE))
|
|
|
|
*cp++ = '>';
|
|
|
|
*cp = '\0';
|
2001-07-25 20:31:20 +00:00
|
|
|
printf(" %s %lx", shoconn,
|
|
|
|
(u_long)unpcb.unp_conn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* print protocol number and socket address */
|
2001-07-25 20:31:20 +00:00
|
|
|
printf(" %d %lx", proto.pr_protocol, (u_long)sock);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
printf("* error\n");
|
|
|
|
}
|
|
|
|
|
1999-11-13 21:13:25 +00:00
|
|
|
|
|
|
|
/*
|
2002-09-27 18:27:10 +00:00
|
|
|
* Read the cdev structure in the kernel (as pointed to by a dev_t)
|
1999-11-13 21:13:25 +00:00
|
|
|
* in order to work out the associated udev_t
|
|
|
|
*/
|
|
|
|
udev_t
|
|
|
|
dev2udev(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
2002-09-27 18:27:10 +00:00
|
|
|
struct cdev si;
|
1999-11-13 21:13:25 +00:00
|
|
|
|
|
|
|
if (KVM_READ(dev, &si, sizeof si)) {
|
|
|
|
return si.si_udev;
|
|
|
|
} else {
|
2001-07-25 20:31:20 +00:00
|
|
|
dprintf(stderr, "can't convert dev_t %x to a udev_t\n", dev);
|
1999-11-13 21:13:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* getinetproto --
|
|
|
|
* print name of protocol number
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
getinetproto(number)
|
|
|
|
int number;
|
|
|
|
{
|
1999-07-02 13:25:49 +00:00
|
|
|
static int isopen;
|
2002-03-30 14:03:53 +00:00
|
|
|
struct protoent *pe;
|
1999-07-02 13:25:49 +00:00
|
|
|
|
|
|
|
if (!isopen)
|
|
|
|
setprotoent(++isopen);
|
|
|
|
if ((pe = getprotobynumber(number)) != NULL)
|
|
|
|
printf(" %s", pe->p_name);
|
|
|
|
else
|
1994-05-27 12:33:43 +00:00
|
|
|
printf(" %d", number);
|
|
|
|
}
|
|
|
|
|
1996-08-24 08:01:29 +00:00
|
|
|
int
|
1994-05-27 12:33:43 +00:00
|
|
|
getfname(filename)
|
2002-03-30 14:03:53 +00:00
|
|
|
const char *filename;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
DEVS *cur;
|
|
|
|
|
|
|
|
if (stat(filename, &statbuf)) {
|
1997-07-08 11:02:48 +00:00
|
|
|
warn("%s", filename);
|
1994-05-27 12:33:43 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1997-07-08 11:02:48 +00:00
|
|
|
if ((cur = malloc(sizeof(DEVS))) == NULL)
|
|
|
|
err(1, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
cur->next = devs;
|
|
|
|
devs = cur;
|
|
|
|
|
|
|
|
cur->ino = statbuf.st_ino;
|
2001-11-05 20:40:24 +00:00
|
|
|
cur->fsid = statbuf.st_dev;
|
1994-05-27 12:33:43 +00:00
|
|
|
cur->name = filename;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void)fprintf(stderr,
|
2000-04-05 05:45:40 +00:00
|
|
|
"usage: fstat [-fmnv] [-p pid] [-u user] [-N system] [-M core] [file ...]\n");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|