summaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
authorantrik <antrik@users.sf.net>2009-06-20 12:29:06 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-09-18 20:34:20 +0200
commitbe9be179a2cde041fbe042362ee80f9874233953 (patch)
tree22ae322b09d7e6b81b6b984c235a1e865774f8e8 /proc
parent7cecc5f97fb28126a7d930efe44d3a03a64ba272 (diff)
Obtain number of ports in proc and libps
Add (and implement) a proc RPC to obtain the number of Mach ports used by the target task. Add infrastructure in libps to read this information. * hurd/process.defs (proc_getnports): New RPC. * hurd/process_request.defs (proc_getnports_request): New RPC. * libps/procstat.c (proc_stat_set_flags): Call proc_getnports RPC if needed. * libps/ps.h (proc_stat): New `num_ports' field. (PSTAT_NUM_PORTS): New macro. (proc_stat_num_ports): New macro. * libps/spec.c (ps_get_num_ports): New function. (ps_num_ports_getter): New variable. (specs): New entry for `ps_num_ports_getter'. * proc/info.c (S_proc_getnports): New function.
Diffstat (limited to 'proc')
-rw-r--r--proc/info.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/proc/info.c b/proc/info.c
index 18cb69fc..445fcd8b 100644
--- a/proc/info.c
+++ b/proc/info.c
@@ -765,3 +765,35 @@ S_proc_get_tty (struct proc *p, pid_t pid,
{
return EOPNOTSUPP; /* XXX */
}
+
+/* Implement proc_getnports as described in <hurd/process.defs>. */
+kern_return_t
+S_proc_getnports (struct proc *callerp,
+ pid_t pid,
+ mach_msg_type_number_t *nports)
+{
+ struct proc *p = pid_find (pid);
+ mach_port_array_t names;
+ mach_msg_type_number_t ncount;
+ mach_port_type_array_t types;
+ mach_msg_type_number_t tcount;
+ error_t err = 0;
+
+ /* No need to check CALLERP here; we don't use it. */
+
+ if (!p)
+ return ESRCH;
+
+ err = mach_port_names (p->p_task, &names, &ncount, &types, &tcount);
+ if (err == KERN_INVALID_TASK)
+ err = ESRCH;
+
+ if (!err) {
+ *nports = ncount;
+
+ munmap (names, ncount * sizeof (mach_port_t));
+ munmap (types, tcount * sizeof (mach_port_type_t));
+ }
+
+ return err;
+}