diff options
author | Thomas Graf <tgraf@redhat.com> | 2012-04-21 13:49:09 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@redhat.com> | 2012-04-21 13:49:09 (GMT) |
commit | 2ed371eb597ad8761c4adc59c32252f5327c65d9 (patch) | |
tree | dceaa29b1bebb4070196e8b4f1a919085d9ad66f /tests/test-cache-mngr.c | |
parent | 516536625fb6bd3b3d28cf4bc47b29e9b352cf30 (diff) | |
download | libnl-2ed371eb597ad8761c4adc59c32252f5327c65d9.zip libnl-2ed371eb597ad8761c4adc59c32252f5327c65d9.tar.gz libnl-2ed371eb597ad8761c4adc59c32252f5327c65d9.tar.bz2 |
test-cache-mngr: Allow for management of arbitary caches via argument string
Let the user specify a list of cache types to add to the manager
as arguments instead of adding a static list.
Uses the newly added nl_cache_mngr_info() to constantly print
information about the manager.
Diffstat (limited to 'tests/test-cache-mngr.c')
-rw-r--r-- | tests/test-cache-mngr.c | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/tests/test-cache-mngr.c b/tests/test-cache-mngr.c index 528ae18..da17018 100644 --- a/tests/test-cache-mngr.c +++ b/tests/test-cache-mngr.c @@ -5,14 +5,14 @@ static int quit = 0; +static struct nl_dump_params dp = { + .dp_type = NL_DUMP_LINE, +}; + + static void change_cb(struct nl_cache *cache, struct nl_object *obj, int action, void *data) { - struct nl_dump_params dp = { - .dp_type = NL_DUMP_LINE, - .dp_fd = stdout, - }; - if (action == NL_ACT_NEW) printf("NEW "); else if (action == NL_ACT_DEL) @@ -31,8 +31,10 @@ static void sigint(int arg) int main(int argc, char *argv[]) { struct nl_cache_mngr *mngr; - struct nl_cache *lc, *nc, *ac, *rc; - int err; + struct nl_cache *cache; + int err, i; + + dp.dp_fd = stdout; signal(SIGINT, sigint); @@ -41,27 +43,19 @@ int main(int argc, char *argv[]) nl_cli_fatal(err, "Unable to allocate cache manager: %s", nl_geterror(err)); - if ((err = nl_cache_mngr_add(mngr, "route/link", &change_cb, NULL, &lc)) < 0) - nl_cli_fatal(err, "Unable to add cache route/link: %s", - nl_geterror(err)); - - if ((err = nl_cache_mngr_add(mngr, "route/neigh", &change_cb, NULL, &nc)) < 0) - nl_cli_fatal(err, "Unable to add cache route/neigh: %s", - nl_geterror(err)); - - if ((err = nl_cache_mngr_add(mngr, "route/addr", &change_cb, NULL, &ac)) < 0) - nl_cli_fatal(err, "Unable to add cache route/addr: %s", - nl_geterror(err)); - - if ((err = nl_cache_mngr_add(mngr, "route/route", &change_cb, NULL, &rc)) < 0) - nl_cli_fatal(err, "Unable to add cache route/route: %s", - nl_geterror(err)); + for (i = 1; i < argc; i++) { + err = nl_cache_mngr_add(mngr, argv[i], &change_cb, NULL, &cache); + if (err < 0) + nl_cli_fatal(err, "Unable to add cache %s: %s", + argv[i], nl_geterror(err)); + } while (!quit) { - int err = nl_cache_mngr_poll(mngr, 5000); + int err = nl_cache_mngr_poll(mngr, 1000); if (err < 0 && err != -NLE_INTR) nl_cli_fatal(err, "Polling failed: %s", nl_geterror(err)); + nl_cache_mngr_info(mngr, &dp); } nl_cache_mngr_free(mngr); |