bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH hurd 4/8] utils: implement portinfo --query-process


From: Justus Winter
Subject: [PATCH hurd 4/8] utils: implement portinfo --query-process
Date: Thu, 23 Oct 2014 17:16:42 +0200

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.
---
 libshouldbeinlibc/Makefile   |  2 +-
 libshouldbeinlibc/portinfo.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
 libshouldbeinlibc/portinfo.h |  1 +
 utils/portinfo.c             |  3 +-
 4 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/libshouldbeinlibc/Makefile b/libshouldbeinlibc/Makefile
index 14a7939..cedd2c8 100644
--- a/libshouldbeinlibc/Makefile
+++ b/libshouldbeinlibc/Makefile
@@ -32,6 +32,6 @@ installhdrs = idvec.h timefmt.h maptime.h \
              wire.h portinfo.h portxlate.h cacheq.h ugids.h nullauth.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 e6305c6..f99b789 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 143c289..bd96eb8 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 4c40352..27998db 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;
-- 
2.1.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]