diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-05-21 17:38:46 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2015-09-10 23:30:09 +0200 |
commit | 176ec926aec9642768615d5875171c24fb10e6b7 (patch) | |
tree | 9223a684ff222c88dd145ed178817b948c6f8bb5 /libshouldbeinlibc | |
parent | 75ec1eeaf6a3f08a01471821c9445b9334ff3bd5 (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.
Diffstat (limited to 'libshouldbeinlibc')
-rw-r--r-- | libshouldbeinlibc/Makefile | 2 | ||||
-rw-r--r-- | libshouldbeinlibc/portinfo.c | 69 | ||||
-rw-r--r-- | libshouldbeinlibc/portinfo.h | 1 |
3 files changed, 71 insertions, 1 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 |