From 818edad80ccf91825554f0088e2e3d8a0c5a6785 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Wed, 25 Aug 2010 14:31:57 +0200 Subject: libps (fetch_procinfo): Fix non-set flag PSTAT_TASK_EVENTS The fetch_procinfo function failed to set the PSTAT_TASK_EVENTS when those has been retreived. It should be noted that GNU Mach does not support the TASK_EVENTS_INFO flavor, so this is of minor importance. The new code also checks that all the requested proc server flags related to a given proc_stat flags have been returned before setting the proc_stat flag in question. * libps/procstat.c (fetch_procinfo): Add map array containing `ps_flags_t' and `procinfo' flags. Use it in a loop to check for flags in `need' and `have' and set them in `pi_flags'. Likewise to check for flags in `pi_flags' and set them in `have'. --- libps/procstat.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/libps/procstat.c b/libps/procstat.c index 33a01cc1..44dc3292 100644 --- a/libps/procstat.c +++ b/libps/procstat.c @@ -109,20 +109,22 @@ fetch_procinfo (process_t server, pid_t pid, struct procinfo **pi, size_t *pi_size, char **waits, size_t *waits_len) { + static const struct { ps_flags_t ps_flag; int pi_flags; } map[] = + { + { PSTAT_TASK_BASIC, PI_FETCH_TASKINFO }, + { PSTAT_TASK_EVENTS, PI_FETCH_TASKEVENTS }, + { PSTAT_NUM_THREADS, PI_FETCH_THREADS }, + { PSTAT_THREAD_BASIC, PI_FETCH_THREAD_BASIC | PI_FETCH_THREADS }, + { PSTAT_THREAD_SCHED, PI_FETCH_THREAD_SCHED | PI_FETCH_THREADS }, + { PSTAT_THREAD_WAITS, PI_FETCH_THREAD_WAITS | PI_FETCH_THREADS }, + { 0, } + }; int pi_flags = 0; + int i; - if ((need & PSTAT_TASK_BASIC) && !(*have & PSTAT_TASK_BASIC)) - pi_flags |= PI_FETCH_TASKINFO; - if ((need & PSTAT_TASK_EVENTS) && !(*have & PSTAT_TASK_EVENTS)) - pi_flags |= PI_FETCH_TASKEVENTS; - if ((need & PSTAT_NUM_THREADS) && !(*have & PSTAT_NUM_THREADS)) - pi_flags |= PI_FETCH_THREADS; - if ((need & PSTAT_THREAD_BASIC) && !(*have & PSTAT_THREAD_BASIC)) - pi_flags |= PI_FETCH_THREAD_BASIC | PI_FETCH_THREADS; - if ((need & PSTAT_THREAD_SCHED) && !(*have & PSTAT_THREAD_SCHED)) - pi_flags |= PI_FETCH_THREAD_SCHED | PI_FETCH_THREADS; - if ((need & PSTAT_THREAD_WAITS) && !(*have & PSTAT_THREAD_WAITS)) - pi_flags |= PI_FETCH_THREAD_WAITS | PI_FETCH_THREADS; + for (i = 0; map[i].ps_flag; i++) + if ((need & map[i].ps_flag) && !(*have & map[i].ps_flag)) + pi_flags |= map[i].pi_flags; if (pi_flags || ((need & PSTAT_PROC_INFO) && !(*have & PSTAT_PROC_INFO))) { @@ -137,16 +139,9 @@ fetch_procinfo (process_t server, pid_t pid, /* Update *HAVE to reflect what we've successfully fetched. */ { *have |= PSTAT_PROC_INFO; - if (pi_flags & PI_FETCH_TASKINFO) - *have |= PSTAT_TASK_BASIC; - if (pi_flags & PI_FETCH_THREADS) - *have |= PSTAT_NUM_THREADS; - if (pi_flags & PI_FETCH_THREAD_BASIC) - *have |= PSTAT_THREAD_BASIC; - if (pi_flags & PI_FETCH_THREAD_SCHED) - *have |= PSTAT_THREAD_SCHED; - if (pi_flags & PI_FETCH_THREAD_WAITS) - *have |= PSTAT_THREAD_WAITS; + for (i = 0; map[i].ps_flag; i++) + if ((pi_flags & map[i].pi_flags) == map[i].pi_flags) + *have |= map[i].ps_flag; } return err; } -- cgit v1.2.3