summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorart <art@openbsd.org>1998-09-07 01:04:13 +0000
committerart <art@openbsd.org>1998-09-07 01:04:13 +0000
commitbee62cd90751dbad8f89a55c8b6b66b1892a673d (patch)
treef9265241ff9532abf77819b5d963804999cbeffe
parentOptionally use make SUDO=sudo build to build as non-root (diff)
downloadwireguard-openbsd-bee62cd90751dbad8f89a55c8b6b66b1892a673d.tar.xz
wireguard-openbsd-bee62cd90751dbad8f89a55c8b6b66b1892a673d.zip
support for pipes
-rw-r--r--usr.bin/fstat/fstat.18
-rw-r--r--usr.bin/fstat/fstat.c50
2 files changed, 53 insertions, 5 deletions
diff --git a/usr.bin/fstat/fstat.1 b/usr.bin/fstat/fstat.1
index 60454f4bd71..1c0336e7c1e 100644
--- a/usr.bin/fstat/fstat.1
+++ b/usr.bin/fstat/fstat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fstat.1,v 1.7 1998/08/30 22:45:15 deraadt Exp $
+.\" $OpenBSD: fstat.1,v 1.8 1998/09/07 01:04:13 art Exp $
.\" Copyright (c) 1987, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -210,6 +210,12 @@ and port.
A ``*'' is used to indicate an INADDR_ANY binding. In this case, the
use of the arrow (``<--'' or ``-->'') indicates the direction the socket
connection was created.
+.Sh PIPES
+Every pipe is printed as an address which is the same for both sides of
+the pipe and a state that is built of the letters 'RWE'.
+W - The pipe blocks waiting for the reader to read data.
+R - The pipe blocks waiting for the writer to write data.
+E - The pipe is in EOF state.
.Sh BUGS
Since
.Nm fstat
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index c1609b062e0..85007816b6a 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.18 1998/09/06 22:48:46 art Exp $ */
+/* $OpenBSD: fstat.c,v 1.19 1998/09/07 01:04:13 art Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$OpenBSD: fstat.c,v 1.18 1998/09/06 22:48:46 art Exp $";
+static char *rcsid = "$OpenBSD: fstat.c,v 1.19 1998/09/07 01:04:13 art Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -80,6 +80,8 @@ static char *rcsid = "$OpenBSD: fstat.c,v 1.18 1998/09/06 22:48:46 art Exp $";
#include <arpa/inet.h>
+#include <sys/pipe.h>
+
#include <ctype.h>
#include <errno.h>
#include <kvm.h>
@@ -144,6 +146,7 @@ void socktrans __P((struct socket *, int));
void usage __P((void));
void vtrans __P((struct vnode *, int, int));
int getfname __P((char *));
+void pipetrans __P((struct pipe *, int));
int
main(argc, argv)
@@ -350,8 +353,10 @@ dofiles(kp)
else if (file.f_type == DTYPE_SOCKET) {
if (checkfile == 0)
socktrans((struct socket *)file.f_data, i);
- }
- else {
+ } else if (file.f_type == DTYPE_PIPE) {
+ if (checkfile == 0)
+ pipetrans((struct pipe *)file.f_data, i);
+ } else {
dprintf("unknown file type %d for file %d of pid %d",
file.f_type, i, Pid);
}
@@ -626,6 +631,43 @@ getmnton(m)
}
void
+pipetrans(pipe, i)
+ struct pipe *pipe;
+ int i;
+{
+ struct pipe pi;
+ void *maxaddr;
+
+ PREFIX(i);
+
+ printf(" ");
+
+ /* fill in socket */
+ if (!KVM_READ(pipe, &pi, sizeof(struct pipe))) {
+ dprintf("can't read pipe at %p", pipe);
+ goto bad;
+ }
+
+ /*
+ * We don't have enough space to fit both peer and own address, so
+ * we select the higher address so both ends of the pipe have the
+ * same visible addr. (it's the higher address because when the other
+ * end closes, it becomes 0)
+ */
+ maxaddr = MAX(pipe, pi.pipe_peer);
+
+ printf("pipe %p state: %s%s%s", maxaddr,
+ (pi.pipe_state & PIPE_WANTR) ? "R" : "",
+ (pi.pipe_state & PIPE_WANTW) ? "W" : "",
+ (pi.pipe_state & PIPE_EOF) ? "E" : "");
+
+ printf("\n");
+ return;
+bad:
+ printf("* error\n");
+}
+
+void
socktrans(sock, i)
struct socket *sock;
int i;