From 680c54fd4616649763a50b122df6cff53b9e62bd Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Tue, 18 Dec 2007 13:06:48 +0100 Subject: [PATCH] Support defining the default callback handler with an environment variable --- lib/socket.c | 22 +++++++++++++++++++++- src/utils.c | 30 +----------------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index dccfbec..aae8f54 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -96,6 +96,26 @@ #include #include +static int default_cb = NL_CB_DEFAULT; + +static void __init init_default_cb(void) +{ + char *nlcb; + + if ((nlcb = getenv("NLCB"))) { + if (!strcasecmp(nlcb, "default")) + default_cb = NL_CB_DEFAULT; + else if (!strcasecmp(nlcb, "verbose")) + default_cb = NL_CB_VERBOSE; + else if (!strcasecmp(nlcb, "debug")) + default_cb = NL_CB_DEBUG; + else { + fprintf(stderr, "Unknown value for NLCB, valid values: " + "{default | verbose | debug}\n"); + } + } +} + static uint32_t used_ports_map[32]; static uint32_t generate_local_port(void) @@ -175,7 +195,7 @@ struct nl_handle *nl_handle_alloc(void) { struct nl_cb *cb; - cb = nl_cb_alloc(NL_CB_DEFAULT); + cb = nl_cb_alloc(default_cb); if (!cb) { nl_errno(ENOMEM); return NULL; diff --git a/src/utils.c b/src/utils.c index b3a11a1..b43758a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -13,37 +13,9 @@ #include -static struct nl_cb *nltool_cb; - int nltool_init(int argc, char *argv[]) { - char *nlcb = getenv("NLCB"); - int cbset = NL_CB_VERBOSE; - - if (nlcb) { - if (!strcasecmp(nlcb, "default")) - cbset = NL_CB_DEFAULT; - else if (!strcasecmp(nlcb, "verbose")) - cbset = NL_CB_VERBOSE; - else if (!strcasecmp(nlcb, "debug")) - cbset = NL_CB_DEBUG; - else { - fprintf(stderr, "Unknown value for NLCB, valid values: " - "{default | verbose | debug}\n"); - goto errout; - } - } - - nltool_cb = nl_cb_alloc(cbset); - if (nltool_cb == NULL) { - fprintf(stderr, "Cannot allocate callback handle\n"); - goto errout; - } - return 0; - -errout: - return -1; } int nltool_connect(struct nl_handle *nlh, int protocol) @@ -60,7 +32,7 @@ int nltool_connect(struct nl_handle *nlh, int protocol) struct nl_handle *nltool_alloc_handle(void) { - return nl_handle_alloc_cb(nltool_cb); + return nl_handle_alloc(); } struct nl_addr *nltool_addr_parse(const char *str)