summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_shm.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2012-04-01 18:22:48 +0000
committerjhb <jhb@FreeBSD.org>2012-04-01 18:22:48 +0000
commit506e2f15b93a1584a9103782c48037c858a30609 (patch)
treec2db61e497320454ff8abdab4b6faede73162985 /sys/kern/uipc_shm.c
parentd5bc632dfb8beb870403790342bc3e9573c4f038 (diff)
downloadFreeBSD-src-506e2f15b93a1584a9103782c48037c858a30609.zip
FreeBSD-src-506e2f15b93a1584a9103782c48037c858a30609.tar.gz
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
Diffstat (limited to 'sys/kern/uipc_shm.c')
-rw-r--r--sys/kern/uipc_shm.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index ce7c722..7f75bdc 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -468,6 +468,7 @@ shm_insert(char *path, Fnv32_t fnv, struct shmfd *shmfd)
map->sm_path = path;
map->sm_fnv = fnv;
map->sm_shmfd = shm_hold(shmfd);
+ shmfd->shm_path = path;
LIST_INSERT_HEAD(SHM_HASH(fnv), map, sm_link);
}
@@ -490,6 +491,7 @@ shm_remove(char *path, Fnv32_t fnv, struct ucred *ucred)
FREAD | FWRITE);
if (error)
return (error);
+ map->sm_shmfd->shm_path = NULL;
LIST_REMOVE(map, sm_link);
shm_drop(map->sm_shmfd);
free(map->sm_path, M_SHMFD);
@@ -844,3 +846,15 @@ shm_unmap(struct file *fp, void *mem, size_t size)
VM_OBJECT_UNLOCK(obj);
return (0);
}
+
+void
+shm_path(struct shmfd *shmfd, char *path, size_t size)
+{
+
+ if (shmfd->shm_path == NULL)
+ return;
+ sx_slock(&shm_dict_lock);
+ if (shmfd->shm_path != NULL)
+ strlcpy(path, shmfd->shm_path, size);
+ sx_sunlock(&shm_dict_lock);
+}
OpenPOWER on IntegriCloud