diff options
author | pluknet <pluknet@FreeBSD.org> | 2012-02-03 09:07:53 +0000 |
---|---|---|
committer | pluknet <pluknet@FreeBSD.org> | 2012-02-03 09:07:53 +0000 |
commit | d275eb87ace1f23c7813b08c8a75f8ff041840f0 (patch) | |
tree | ab1b42a2ef9553c53abe3715110b430dcc6c3216 /usr.bin/fstat | |
parent | bc68dfaae933b890c7f70e020e8ecb9c9875767b (diff) | |
download | FreeBSD-src-d275eb87ace1f23c7813b08c8a75f8ff041840f0.zip FreeBSD-src-d275eb87ace1f23c7813b08c8a75f8ff041840f0.tar.gz |
Print the owner process for unix domain sockets when restricted to the
specified files.
PR: bin/143962
MFC after: 2 weeks
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r-- | usr.bin/fstat/fstat.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 6014ddd..9401ef8 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <sys/socketvar.h> #include <sys/sysctl.h> #include <sys/queue.h> +#include <sys/un.h> #include <netinet/in.h> @@ -224,28 +225,53 @@ static void print_file_info(struct procstat *procstat, struct filestat *fst, const char *uname, const char *cmd, int pid) { + struct sockstat sock; struct vnstat vn; DEVS *d; const char *filename; int error, fsmatch = 0; char errbuf[_POSIX2_LINE_MAX]; + error = 0; filename = NULL; if (checkfile != 0) { - if (fst->fs_type != PS_FST_TYPE_VNODE && - fst->fs_type != PS_FST_TYPE_FIFO) + switch (fst->fs_type) { + case PS_FST_TYPE_VNODE: + case PS_FST_TYPE_FIFO: + error = procstat_get_vnode_info(procstat, fst, &vn, errbuf); + break; + case PS_FST_TYPE_SOCKET: + error = procstat_get_socket_info(procstat, fst, &sock, errbuf); + break; + default: return; - error = procstat_get_vnode_info(procstat, fst, &vn, errbuf); + } if (error != 0) return; for (d = devs; d != NULL; d = d->next) - if (d->fsid == vn.vn_fsid) { - fsmatch = 1; - if ((unsigned)d->ino == vn.vn_fileid) { - filename = d->name; - break; + switch (fst->fs_type) { + case PS_FST_TYPE_VNODE: + case PS_FST_TYPE_FIFO: + if (d->fsid == vn.vn_fsid) { + fsmatch = 1; + if ((unsigned)d->ino == vn.vn_fileid) { + filename = d->name; + break; + } + } + break; + case PS_FST_TYPE_SOCKET: + if (sock.dom_family == AF_UNIX) { + fsmatch = 1; + if (strcmp(((struct sockaddr_un *) + (&sock.sa_local))->sun_path, + d->name) == 0) { + filename = d->name; + break; + } } + break; } if (fsmatch == 0 || (filename == NULL && fsflg == 0)) return; |