diff options
author | Miles Bader <miles@gnu.org> | 1996-05-12 21:03:55 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-05-12 21:03:55 +0000 |
commit | 65f8cfc3053272412681a2d162219d436761a954 (patch) | |
tree | 54078d762a1a828df307d25b70320c0429ce135b /proc | |
parent | c3d8ddeb1ad965850fe030c4b2532d0d0103f843 (diff) |
(PI_FETCH_THREAD_DETAILS): New macro.
(S_proc_getprocinfo):
Only allocate thread detail storage if we're actually returning thread
details (a lone PI_FETCH_THREADS simply means "number of threads").
React to errors somewhat more gracefully.
Diffstat (limited to 'proc')
-rw-r--r-- | proc/info.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/proc/info.c b/proc/info.c index a02d453d..dbaf55d7 100644 --- a/proc/info.c +++ b/proc/info.c @@ -338,6 +338,10 @@ S_proc_getprocenv (struct proc *callerp, return get_string_array (p->p_task, p->p_envp, (vm_address_t *)buf, buflen); } +/* Handy abbreviation for all the various thread details. */ +#define PI_FETCH_THREAD_DETAILS \ + (PI_FETCH_THREAD_SCHED | PI_FETCH_THREAD_BASIC | PI_FETCH_THREAD_WAITS) + /* Implement proc_getprocinfo as described in <hurd/proc.defs>. */ kern_return_t S_proc_getprocinfo (struct proc *callerp, @@ -370,8 +374,7 @@ S_proc_getprocinfo (struct proc *callerp, task = p->p_task; msgport = p->p_deadmsg ? MACH_PORT_NULL : p->p_msgport; - if (*flags & (PI_FETCH_THREAD_SCHED | PI_FETCH_THREAD_BASIC - | PI_FETCH_THREAD_WAITS)) + if (*flags & PI_FETCH_THREAD_DETAILS) *flags |= PI_FETCH_THREADS; if (*flags & PI_FETCH_THREADS) @@ -385,8 +388,9 @@ S_proc_getprocinfo (struct proc *callerp, else nthreads = 0; - structsize = - sizeof (struct procinfo) + nthreads * sizeof (pi->threadinfos[0]); + structsize = sizeof (struct procinfo); + if (*flags & PI_FETCH_THREAD_DETAILS) + structsize += nthreads * sizeof (pi->threadinfos[0]); if (structsize / sizeof (int) > *piarraylen) { @@ -432,7 +436,8 @@ S_proc_getprocinfo (struct proc *callerp, for (i = 0; i < nthreads; i++) { - pi->threadinfos[i].died = 0; + if (*flags & PI_FETCH_THREAD_DETAILS) + pi->threadinfos[i].died = 0; if (*flags & PI_FETCH_THREAD_BASIC) { thcount = THREAD_BASIC_INFO_COUNT; @@ -442,30 +447,39 @@ S_proc_getprocinfo (struct proc *callerp, if (err == MACH_SEND_INVALID_DEST) { pi->threadinfos[i].died = 1; + err = 0; continue; } else if (err) - break; + /* Something screwy, give up on this bit of info. */ + { + *flags &= ~PI_FETCH_THREAD_BASIC; + err = 0; + } } if (*flags & PI_FETCH_THREAD_SCHED) { thcount = THREAD_SCHED_INFO_COUNT; - if (!err) - err = thread_info (thds[i], THREAD_SCHED_INFO, - (int *)&pi->threadinfos[i].pis_si, - &thcount); + err = thread_info (thds[i], THREAD_SCHED_INFO, + (int *)&pi->threadinfos[i].pis_si, + &thcount); if (err == MACH_SEND_INVALID_DEST) { pi->threadinfos[i].died = 1; + err = 0; continue; } - if (err && err != ESRCH) - break; + if (err) + /* Something screwy, give up o nthis bit of info. */ + { + *flags &= ~PI_FETCH_THREAD_SCHED; + err = 0; + } } /* Note that there are thread wait entries only for threads not marked - dead. */ + dead. */ if (*flags & PI_FETCH_THREAD_WAITS) { |