summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-21 17:38:46 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-09-10 23:30:09 +0200
commit176ec926aec9642768615d5875171c24fb10e6b7 (patch)
tree9223a684ff222c88dd145ed178817b948c6f8bb5
parent75ec1eeaf6a3f08a01471821c9445b9334ff3bd5 (diff)
utils: implement portinfo --query-process
Implement portinfo --query-process (hopefully) as envisaged by a comment in portinfo.c. We use the new Hurd server introspection protocol to obtain information about the objects related to ports: % utils/portinfo --receive --query-process 5586 77 77: receive [bucket: diskfs_port_bucket, class: diskfs_protid_class, node{inode: 48194, hard: 1, weak: 1}, path: hello/hurd/developers_:)] * libshouldbeinlibc/Makefile (OBJS): Add hurd_portUser.o. * libshouldbeinlibc/portinfo.c (show_portinfo_query): New function. (print_port_info): Use show_portinfo_query if desired. * libshouldbeinlibc/portinfo.h (PORTINFO_QUERY): New macro. * utils/portinfo.c (argp_option): Drop #if 0. (parse_opt): Handle --query-process.
-rw-r--r--libshouldbeinlibc/Makefile2
-rw-r--r--libshouldbeinlibc/portinfo.c69
-rw-r--r--libshouldbeinlibc/portinfo.h1
-rw-r--r--utils/portinfo.c3
4 files changed, 72 insertions, 3 deletions
diff --git a/libshouldbeinlibc/Makefile b/libshouldbeinlibc/Makefile
index 633d60eb..a41a8798 100644
--- a/libshouldbeinlibc/Makefile
+++ b/libshouldbeinlibc/Makefile
@@ -36,6 +36,6 @@ installhdrs = idvec.h timefmt.h maptime.h \
installhdrsubdir = .
-OBJS = $(SRCS:.c=.o)
+OBJS = $(SRCS:.c=.o) hurd_portUser.o
include ../Makeconf
diff --git a/libshouldbeinlibc/portinfo.c b/libshouldbeinlibc/portinfo.c
index e6305c6e..f99b7894 100644
--- a/libshouldbeinlibc/portinfo.c
+++ b/libshouldbeinlibc/portinfo.c
@@ -17,10 +17,77 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+#include <assert.h>
+#include <error.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "portinfo.h"
+#include "hurd_port_U.h"
+
+static void
+show_portinfo_query (mach_port_t task, mach_port_t name,
+ unsigned show, FILE *stream)
+{
+ error_t err;
+ static mach_port_t introspection_port;
+ static mach_port_t for_task;
+
+ if (task != for_task)
+ {
+ mach_port_t *ports;
+ size_t ports_len;
+
+ err = mach_ports_lookup (task, &ports, &ports_len);
+ if (! err)
+ {
+ size_t i;
+ if (MACH_PORT_VALID (introspection_port))
+ mach_port_deallocate (mach_task_self (), introspection_port);
+
+ for (i = 0; i < ports_len; i++)
+ if (i == HURD_PORT_REGISTER_INTROSPECTION)
+ introspection_port = ports[i];
+ else
+ {
+ if (MACH_PORT_VALID (ports[i]))
+ mach_port_deallocate (mach_task_self (), ports[i]);
+ }
+ }
+ else
+ introspection_port = MACH_PORT_DEAD;
+
+ for_task = task;
+ }
+
+ if (! MACH_PORT_VALID (introspection_port))
+ return;
+
+ string_t info; /* XXX */
+ err = hurd_port_debug_info (introspection_port, name, 100, info);
+ if (err)
+ {
+ if (err != EINVAL)
+ error (0, err, "hurd_port_debug_info");
+ return;
+ }
+
+ if (strlen (info) > 0)
+ fprintf (stream, " [%s", info);
+
+ if (show & PORTINFO_DETAILS)
+ {
+ unsigned int hard, weak;
+ err = hurd_port_get_refcounts (introspection_port, name, 100,
+ &hard, &weak);
+ if (! err)
+ fprintf (stream, ", hard: %u, weak: %u", hard, weak);
+ }
+
+ fprintf (stream, "]");
+}
+
/* Prints info about NAME in TASK to STREAM, in a way described by the flags
in SHOW. If TYPE is non-zero, it should be what mach_port_type returns
@@ -83,6 +150,8 @@ print_port_info (mach_port_t name, mach_port_type_t type, task_t task,
status.mps_nsrequest ? ", ns-req" : "");
}
}
+ if (show & PORTINFO_QUERY)
+ show_portinfo_query (task, name, show, stream);
}
if (type & MACH_PORT_TYPE_SEND)
{
diff --git a/libshouldbeinlibc/portinfo.h b/libshouldbeinlibc/portinfo.h
index 143c2898..bd96eb87 100644
--- a/libshouldbeinlibc/portinfo.h
+++ b/libshouldbeinlibc/portinfo.h
@@ -31,6 +31,7 @@
#define PORTINFO_DETAILS 0x1
#define PORTINFO_MEMBERS 0x4
#define PORTINFO_HEX_NAMES 0x8
+#define PORTINFO_QUERY 0x10
/* Prints info about NAME in TASK to STREAM, in a way described by the flags
in SHOW. If TYPE is non-zero, it should be what mach_port_type returns
diff --git a/utils/portinfo.c b/utils/portinfo.c
index 4c403526..27998db0 100644
--- a/utils/portinfo.c
+++ b/utils/portinfo.c
@@ -44,10 +44,8 @@ static const struct argp_option options[] = {
{"verbose", 'v', 0, 0, "Give more detailed information"},
{"members", 'm', 0, 0, "Show members of port-sets"},
{"hex-names", 'x', 0, 0, "Show port names in hexadecimal"},
-#if 0 /* XXX implement this */
{"query-process", 'q', 0, 0, "Query the process itself for the identity of"
" the ports in question -- requires the process be in a sane state"},
-#endif
{"hold", '*', 0, OPTION_HIDDEN},
{0,0,0,0, "Selecting which names to show:", 2},
@@ -249,6 +247,7 @@ main (int argc, char **argv)
case 'v': show |= PORTINFO_DETAILS; break;
case 'm': show |= PORTINFO_MEMBERS; break;
case 'x': show |= PORTINFO_HEX_NAMES; break;
+ case 'q': show |= PORTINFO_QUERY; break;
case 'r': only |= MACH_PORT_TYPE_RECEIVE; break;
case 's': only |= MACH_PORT_TYPE_SEND; break;