summaryrefslogtreecommitdiff
path: root/tests/test-cache-mngr.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@deb.localdomain>2008-02-05 12:35:41 +0100
committerThomas Graf <tgr@deb.localdomain>2008-02-05 12:35:41 +0100
commit080727d90b62418cb103f5b0fc6ccecdf8317009 (patch)
tree110a260bbb32929cb3a1e1f2545fba92d273c002 /tests/test-cache-mngr.c
parentdbcdf91a99d0e12d012308328bc6e1894403a99b (diff)
downloadlibnl-080727d90b62418cb103f5b0fc6ccecdf8317009.tar.gz
Free associated caches when freeing cache manager
Caches allocated by the cache manager must be freed again when the cache manager itself is freed. However, the netlink socket is allocated indepdently so it should not be freed.
Diffstat (limited to 'tests/test-cache-mngr.c')
-rw-r--r--tests/test-cache-mngr.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/test-cache-mngr.c b/tests/test-cache-mngr.c
index 4d70e31..9a3da2d 100644
--- a/tests/test-cache-mngr.c
+++ b/tests/test-cache-mngr.c
@@ -1,4 +1,7 @@
#include "../src/utils.h"
+#include <signal.h>
+
+static int quit = 0;
static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int action)
@@ -18,12 +21,19 @@ static void change_cb(struct nl_cache *cache, struct nl_object *obj,
nl_object_dump(obj, &dp);
}
+static void sigint(int arg)
+{
+ quit = 1;
+}
+
int main(int argc, char *argv[])
{
struct nl_cache_mngr *mngr;
struct nl_cache *lc, *nc, *ac, *rc;
struct nl_handle *handle;
+ signal(SIGINT, sigint);
+
nltool_init(argc, argv);
handle = nltool_alloc_handle();
@@ -58,9 +68,9 @@ int main(int argc, char *argv[])
return -1;
}
- for (;;) {
+ while (!quit) {
int err = nl_cache_mngr_poll(mngr, 5000);
- if (err < 0) {
+ if (err < 0 && err != -EINTR) {
nl_perror("nl_cache_mngr_poll()");
return -1;
}
@@ -68,6 +78,7 @@ int main(int argc, char *argv[])
}
nl_cache_mngr_free(mngr);
+ nl_handle_destroy(handle);
return 0;
}