From 53fd2c3bf958859f6b518681ff65f5dff9e23f70 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Jul 2010 18:29:32 -0700 Subject: Add debug option to resolver test tool --- tools/resolv-test.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tools/resolv-test.c') diff --git a/tools/resolv-test.c b/tools/resolv-test.c index e8dba36f..637c9e36 100644 --- a/tools/resolv-test.c +++ b/tools/resolv-test.c @@ -24,6 +24,7 @@ #endif #include +#include #include #include @@ -56,12 +57,36 @@ static void resolv_result(GResolvResultStatus status, g_main_loop_quit(main_loop); } +static gboolean option_debug = FALSE; + +static GOptionEntry options[] = { + { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, + "Enable debug output" }, + { NULL }, +}; + int main(int argc, char *argv[]) { + GOptionContext *context; + GError *error = NULL; struct sigaction sa; GResolv *resolv; int index = 0; + context = g_option_context_new(NULL); + g_option_context_add_main_entries(context, options, NULL); + + if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { + if (error != NULL) { + g_printerr("%s\n", error->message); + g_error_free(error); + } else + g_printerr("An unknown error occurred\n"); + exit(1); + } + + g_option_context_free(context); + if (argc < 2) { printf("missing argument\n"); return 1; @@ -73,7 +98,8 @@ int main(int argc, char *argv[]) return 1; } - g_resolv_set_debug(resolv, resolv_debug, "RESOLV"); + if (option_debug == TRUE) + g_resolv_set_debug(resolv, resolv_debug, "RESOLV"); main_loop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3