aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2012-06-06 21:57:03 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2012-06-06 21:57:03 +0000
commit60accff2c0a4ee488eb59ae6678b93f6275931bb (patch)
treebbe6067b56263203c05d54088e1960fd958d754b /usr.bin
parent9ec1e7275faaa749dab55d6666dee438d3ab6042 (diff)
downloadsrc-60accff2c0a4ee488eb59ae6678b93f6275931bb.tar.gz
src-60accff2c0a4ee488eb59ae6678b93f6275931bb.zip
MFC 233760:
Export some more useful info about shared memory objects to userland via procstat(1) and fstat(1): - Change shm file descriptors to track the pathname they are associated with and add a shm_path() method to copy the path out to a caller-supplied buffer. - Use shm_path() to export the path of a shared memory object via struct kinfo_file. - Change procstat to always print out the path for a given object if it is valid. - Teach fstat about shared memory objects and to display their path, mode, and size.
Notes
Notes: svn path=/stable/8/; revision=236699
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/fstat/fstat.c57
-rw-r--r--usr.bin/procstat/procstat_files.c10
2 files changed, 59 insertions, 8 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index f82e964395b2..f693302b543e 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
#define _WANT_FILE
#include <sys/file.h>
#include <sys/conf.h>
+#include <sys/mman.h>
#define _KERNEL
#include <sys/pipe.h>
#include <sys/mount.h>
@@ -155,6 +156,7 @@ char *getmnton(struct mount *m);
void pipetrans(struct pipe *pi, int i, int flag);
void socktrans(struct socket *sock, int i);
void ptstrans(struct tty *tp, int i, int flag);
+void shmtrans(struct shmfd *shmp, int i, int flag);
void getinetproto(int number);
int getfname(const char *filename);
void usage(void);
@@ -418,6 +420,12 @@ dofiles(struct kinfo_proc *kp)
ptstrans(file.f_data, i, file.f_flag);
}
#endif
+#ifdef DTYPE_SHM
+ else if (file.f_type == DTYPE_SHM) {
+ if (checkfile == 0)
+ shmtrans(file.f_data, i, file.f_flag);
+ }
+#endif
else {
dprintf(stderr,
"unknown file type %d for file %d of pid %d\n",
@@ -939,6 +947,55 @@ bad:
printf("* error\n");
}
+void
+shmtrans(struct shmfd *shmp, int i, int flag)
+{
+ struct shmfd shm;
+ char name[MAXPATHLEN];
+ char mode[15];
+ char rw[3];
+ unsigned j;
+
+ PREFIX(i);
+
+ if (!KVM_READ(shmp, &shm, sizeof(struct shmfd))) {
+ dprintf(stderr, "can't read shm at %p\n", shmp);
+ goto bad;
+ }
+
+ if (shm.shm_path != NULL) {
+ for (j = 0; j < sizeof(name) - 1; j++) {
+ if (!KVM_READ(shm.shm_path + j, name + j, 1))
+ break;
+ if (name[j] == '\0')
+ break;
+ }
+ name[j] = '\0';
+ } else
+ name[0] = '\0';
+
+ rw[0] = '\0';
+ if (flag & FREAD)
+ strcat(rw, "r");
+ if (flag & FWRITE)
+ strcat(rw, "w");
+
+ shm.shm_mode |= S_IFREG;
+ if (nflg) {
+ printf(" ");
+ (void)snprintf(mode, sizeof(mode), "%o", shm.shm_mode);
+ } else {
+ printf(" %-15s", name[0] != '\0' ? name : "-");
+ strmode(shm.shm_mode, mode);
+ }
+ printf(" %10s %6ju", mode, shm.shm_size);
+ printf(" %2s\n", rw);
+
+ return;
+bad:
+ printf("* error\n");
+}
+
/*
* Read the cdev structure in the kernel in order to work out the
* associated dev_t
diff --git a/usr.bin/procstat/procstat_files.c b/usr.bin/procstat/procstat_files.c
index debb0e44a20f..e54aa562038e 100644
--- a/usr.bin/procstat/procstat_files.c
+++ b/usr.bin/procstat/procstat_files.c
@@ -277,13 +277,6 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp)
printf("%7c ", '-');
switch (kif->kf_type) {
- case KF_TYPE_VNODE:
- case KF_TYPE_FIFO:
- case KF_TYPE_PTS:
- printf("%-3s ", "-");
- printf("%-18s", kif->kf_path);
- break;
-
case KF_TYPE_SOCKET:
printf("%-3s ",
protocol_to_string(kif->kf_sock_domain,
@@ -312,7 +305,8 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp)
default:
printf("%-3s ", "-");
- printf("%-18s", "-");
+ printf("%-18s", kif->kf_path[0] != '\0' ?
+ kif->kf_path : "-");
}
printf("\n");