From a16910aa4e95a18eff20842cd3516f8dd33dba8e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 4 Feb 2012 21:27:43 -0600 Subject: [PATCH] capability: add capability_index_stats() for getting statistics about the capability broker system --- include/capability.h | 1 + src/capability.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/capability.h b/include/capability.h index 757b61fa..c3caec8d 100644 --- a/include/capability.h +++ b/include/capability.h @@ -34,5 +34,6 @@ extern void capability_index_destroy(struct CapabilityIndex *); extern const char *capability_index_list(struct CapabilityIndex *, unsigned int capability_mask); extern unsigned int capability_index_mask(struct CapabilityIndex *); extern unsigned int capability_index_get_required(struct CapabilityIndex *); +extern void capability_index_stats(void (*cb)(const char *line, void *privdata), void *privdata); #endif diff --git a/src/capability.c b/src/capability.c index c4236cb2..9906db0d 100644 --- a/src/capability.c +++ b/src/capability.c @@ -207,3 +207,33 @@ capability_index_get_required(struct CapabilityIndex *idx) return mask; } + +void +capability_index_stats(void (*cb)(const char *line, void *privdata), void *privdata) +{ + rb_dlink_node *node; + char buf[BUFSIZE]; + + RB_DLINK_FOREACH(node, capability_indexes.head) + { + struct CapabilityIndex *idx = node->data; + struct DictionaryIter iter; + struct CapabilityEntry *entry; + + rb_snprintf(buf, sizeof buf, "'%s': allocated bits - %d", idx->name, (idx->highest_bit - 1)); + cb(buf, privdata); + + DICTIONARY_FOREACH(entry, &iter, idx->cap_dict) + { + rb_snprintf(buf, sizeof buf, "bit %d: '%s'", entry->value, entry->cap); + cb(buf, privdata); + } + + rb_snprintf(buf, sizeof buf, "'%s': remaining bits - %ld", idx->name, + (sizeof(unsigned int) * 8) - (idx->highest_bit - 1)); + cb(buf, privdata); + } + + rb_snprintf(buf, sizeof buf, "%ld capability indexes", rb_dlink_list_length(&capability_indexes)); + cb(buf, privdata); +}