diff options
author | Thomas Graf <tgraf@suug.ch> | 2016-08-02 10:10:34 +0200 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2016-08-02 10:14:24 +0200 |
commit | ddcd5e7d24ad57257117402529eacddd8feed2cf (patch) | |
tree | 2f7e42621049d3da73710ff60ff1ad0045c7bea5 | |
parent | df271c43a497799be34b2ccce8283ce9ccbdfd44 (diff) |
Derive initial interface selection based on policy
So far, any output module with a selection capability defaulted to
the first interface in the list as first pick. This uses the policy
configuration instead and thus allows to select which interface to
display first:
Examples:
bmon -p 'em1,*'
bmon -p 'eth*,lo,*'
The first rule that finds a matching interface is used and will
trigger initial selection.
Note that this is *ONLY* evaluated after the first read of the
statistics so if a more preferred interface appears later, the
selection will not be changed.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/element.c | 26 |
2 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,6 @@ +HEAD + * Pick default selected interface based on policy + v3.9 - Jul 19, 2016 * Color support * Add ability to reset statistics from curses UI diff --git a/src/element.c b/src/element.c index d71a337..ebddc2e 100644 --- a/src/element.c +++ b/src/element.c @@ -358,6 +358,26 @@ int element_set_usage_attr(struct element *e, const char *usage) return 0; } +void element_pick_from_policy(struct element_group *g) +{ + if (!list_empty(&allowed)) { + struct policy *p; + + list_for_each_entry(p, &allowed, p_list) { + struct element *e; + + list_for_each_entry(e, &g->g_elements, e_list) { + if (match_mask(p, e->e_name)) { + g->g_current = e; + return; + } + } + } + } + + element_select_first(); +} + struct element *element_current(void) { struct element_group *g; @@ -365,8 +385,12 @@ struct element *element_current(void) if (!(g = group_current())) return NULL; + /* + * If no element is picked yet, pick a default interface according to + * the selection policy. + */ if (!g->g_current) - element_select_first(); + element_pick_from_policy(g); return g->g_current; } |