summaryrefslogtreecommitdiff
path: root/usr.bin/fstat
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2012-04-01 18:22:48 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2012-04-01 18:22:48 +0000
commite506e182dda35a3ac977e9057552439dd24245f5 (patch)
treec2db61e497320454ff8abdab4b6faede73162985 /usr.bin/fstat
parent87d94367b96bdad25d621c1d906750b9aa1502b9 (diff)
downloadsrc-test-e506e182dda35a3ac977e9057552439dd24245f5.tar.gz
src-test-e506e182dda35a3ac977e9057552439dd24245f5.zip
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 the fo_stat() method of shared memory objects and shm_path() to export the path, mode, and size of a shared memory object via struct kinfo_file. - Add a struct shmstat to the libprocstat(3) interface along with a procstat_get_shm_info() to export the mode and size of a shared memory object. - 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. MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=233760
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r--usr.bin/fstat/fstat.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 6014dddc47c2b..fe225a04d3846 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -84,6 +84,8 @@ static void print_pipe_info(struct procstat *procstat,
struct filestat *fst);
static void print_pts_info(struct procstat *procstat,
struct filestat *fst);
+static void print_shm_info(struct procstat *procstat,
+ struct filestat *fst);
static void print_socket_info(struct procstat *procstat,
struct filestat *fst);
static void print_vnode_info(struct procstat *procstat,
@@ -289,6 +291,9 @@ print_file_info(struct procstat *procstat, struct filestat *fst,
case PS_FST_TYPE_PTS:
print_pts_info(procstat, fst);
break;
+ case PS_FST_TYPE_SHM:
+ print_shm_info(procstat, fst);
+ break;
default:
if (vflg)
fprintf(stderr,
@@ -419,6 +424,30 @@ print_pts_info(struct procstat *procstat, struct filestat *fst)
}
static void
+print_shm_info(struct procstat *procstat, struct filestat *fst)
+{
+ struct shmstat shm;
+ char errbuf[_POSIX2_LINE_MAX];
+ char mode[15];
+ int error;
+
+ error = procstat_get_shm_info(procstat, fst, &shm, errbuf);
+ if (error != 0) {
+ printf("* error");
+ return;
+ }
+ if (nflg) {
+ printf(" ");
+ (void)snprintf(mode, sizeof(mode), "%o", shm.mode);
+ } else {
+ printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
+ strmode(shm.mode, mode);
+ }
+ printf(" %10s %6ju", mode, shm.size);
+ print_access_flags(fst->fs_fflags);
+}
+
+static void
print_vnode_info(struct procstat *procstat, struct filestat *fst)
{
struct vnstat vn;