summaryrefslogtreecommitdiff
path: root/debian/patches/introspection0004-utils-implement-portinfo-query-process.patch
blob: 7a4f5627856ec5919796c553fd494f70880d1735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
From d67d47e283efaf34a37ff440a43c33a1bd4fee24 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 21 May 2014 17:38:46 +0200
Subject: [PATCH hurd 4/8] 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.
---
 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 633d60e..a41a879 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 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.4