summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2013-05-03 21:11:57 +0000
committerjhb <jhb@FreeBSD.org>2013-05-03 21:11:57 +0000
commit679fa5ed4e91b1d9e2002d8da43d9c31056fe7a4 (patch)
tree4b4ec8c6d14c8986e2139b96edf75a870d996980 /usr.bin
parent66bb8e0f75e5284e0b64916ea8295efb5ca1fff6 (diff)
downloadFreeBSD-src-679fa5ed4e91b1d9e2002d8da43d9c31056fe7a4.zip
FreeBSD-src-679fa5ed4e91b1d9e2002d8da43d9c31056fe7a4.tar.gz
Similar to 233760 and 236717, export some more useful info about the
kernel-based POSIX semaphore descriptors to userland via procstat(1) and fstat(1): - Change sem file descriptors to track the pathname they are associated with and add a ksem_info() method to copy the path out to a caller-supplied buffer. - Use the fo_stat() method of shared memory objects and ksem_info() to export the path, mode, and value of a semaphore via struct kinfo_file. - Add a struct semstat to the libprocstat(3) interface along with a procstat_get_sem_info() to export the mode and value of a semaphore. - Teach fstat about semaphores and to display their path, mode, and value. MFC after: 2 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/fstat/fstat.12
-rw-r--r--usr.bin/fstat/fstat.c29
2 files changed, 31 insertions, 0 deletions
diff --git a/usr.bin/fstat/fstat.1 b/usr.bin/fstat/fstat.1
index 7403a8e..268b70f 100644
--- a/usr.bin/fstat/fstat.1
+++ b/usr.bin/fstat/fstat.1
@@ -155,6 +155,8 @@ using a symbolic format (see
otherwise, the mode is printed
as an octal number.
.It Li SZ\&|DV
+If the file is a semaphore,
+prints the current value of the semaphore.
If the file is not a character or block special, prints the size of
the file in bytes.
Otherwise, if the
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 265791d..1aeee67 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_sem_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,
@@ -294,6 +296,9 @@ print_file_info(struct procstat *procstat, struct filestat *fst,
case PS_FST_TYPE_SHM:
print_shm_info(procstat, fst);
break;
+ case PS_FST_TYPE_SEM:
+ print_sem_info(procstat, fst);
+ break;
default:
if (vflg)
fprintf(stderr,
@@ -424,6 +429,30 @@ print_pts_info(struct procstat *procstat, struct filestat *fst)
}
static void
+print_sem_info(struct procstat *procstat, struct filestat *fst)
+{
+ struct semstat sem;
+ char errbuf[_POSIX2_LINE_MAX];
+ char mode[15];
+ int error;
+
+ error = procstat_get_sem_info(procstat, fst, &sem, errbuf);
+ if (error != 0) {
+ printf("* error");
+ return;
+ }
+ if (nflg) {
+ printf(" ");
+ (void)snprintf(mode, sizeof(mode), "%o", sem.mode);
+ } else {
+ printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
+ strmode(sem.mode, mode);
+ }
+ printf(" %10s %6u", mode, sem.value);
+ print_access_flags(fst->fs_fflags);
+}
+
+static void
print_shm_info(struct procstat *procstat, struct filestat *fst)
{
struct shmstat shm;
OpenPOWER on IntegriCloud