From 537f26ade59fbe0022f91552001151f043128efd Mon Sep 17 00:00:00 2001 From: Martin Nagy Date: Wed, 20 Jan 2010 15:01:10 +0100 Subject: [PATCH] Adding some test flags --- server/monitor/monitor.c | 29 +++++++++++++++++++++++++++++ server/resolv/async_resolv.c | 40 +++++++++++++++++++++++++++++++--------- server/util/debug.c | 5 +++++ server/util/util.h | 12 +++++++++++- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index b3174bd..116b21e 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -2397,6 +2397,35 @@ static char **parse_args(const char *str) i = 0; } + if (flag_a || flag_b || flag_c) { + num--; + if (flag_a) + num++; + if (flag_b) + num++; + if (flag_c) + num++; + if (flag_x) + num++; + if (flag_y) + num++; + + r = realloc(ret, (num + 2) * sizeof(char *)); + if (!r) goto fail; + ret = r; + ret[num+1] = NULL; + if (flag_a) + ret[num--] = strdup("-a"); + if (flag_b) + ret[num--] = strdup("-b"); + if (flag_c) + ret[num--] = strdup("-c"); + if (flag_x) + ret[num--] = strdup("-x"); + if (flag_y) + ret[num--] = strdup("-y"); + } + free(tmp); return ret; diff --git a/server/resolv/async_resolv.c b/server/resolv/async_resolv.c index ce92c8a..5ff5fd9 100644 --- a/server/resolv/async_resolv.c +++ b/server/resolv/async_resolv.c @@ -136,14 +136,23 @@ add_timeout_timer(struct tevent_context *ev, struct resolv_ctx *ctx) struct timeval tv = { 0 }; struct timeval *tvp; - tvp = ares_timeout(ctx->channel, NULL, &tv); + if (!flag_c) { + tvp = ares_timeout(ctx->channel, NULL, &tv); + } else { + tvp = NULL; + tv.tv_sec = 5; + tv.tv_usec = 0; + } if (tvp == NULL) { tvp = &tv; } + DEBUG(9, ("ares_timeout returned %d seconds, %d useconds\n", tvp->tv_sec, + tvp->tv_usec)); + /* Enforce a minimum of 1 second. */ - if (tvp->tv_sec < 1) { + if (tvp->tv_sec < 1 || flag_b) { tv = tevent_timeval_current_ofs(1, 0); } else { tv = tevent_timeval_current_ofs(tvp->tv_sec, tvp->tv_usec); @@ -160,6 +169,7 @@ static void check_fd_timeouts(struct tevent_context *ev, struct tevent_timer *te, struct timeval current_time, void *private_data) { + struct fd_watch *fd_watch; struct resolv_ctx *ctx = talloc_get_type(private_data, struct resolv_ctx); DEBUG(9, ("Checking for DNS timeouts\n")); @@ -172,7 +182,13 @@ check_fd_timeouts(struct tevent_context *ev, struct tevent_timer *te, */ ctx->timeout_watcher = NULL; - ares_process_fd(ctx->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + if (!flag_x) { + ares_process_fd(ctx->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + } else { + DLIST_FOR_EACH(fd_watch, ctx->fds) { + ares_process_fd(ctx->channel, fd_watch->fd, flag_y ? fd_watch->fd : ARES_SOCKET_BAD); + } + } if (ctx->pending_requests > 0) { add_timeout_timer(ev, ctx); @@ -317,12 +333,18 @@ recreate_ares_channel(struct resolv_ctx *ctx) */ options.sock_state_cb = fd_event; options.sock_state_cb_data = ctx; - options.timeout = ctx->timeout * 1000; - options.tries = 1; - ret = ares_init_options(&new_channel, &options, - ARES_OPT_SOCK_STATE_CB | - ARES_OPT_TIMEOUTMS | - ARES_OPT_TRIES); + + if (!flag_a) { + options.timeout = ctx->timeout * 1000; + options.tries = 1; + ret = ares_init_options(&new_channel, &options, + ARES_OPT_SOCK_STATE_CB | + ARES_OPT_TIMEOUTMS | + ARES_OPT_TRIES); + } else { + ret = ares_init_options(&new_channel, &options, ARES_OPT_SOCK_STATE_CB); + } + if (ret != ARES_SUCCESS) { DEBUG(1, ("Failed to initialize ares channel: %s\n", resolv_strerror(ret))); diff --git a/server/util/debug.c b/server/util/debug.c index aa34e57..7663f6e 100644 --- a/server/util/debug.c +++ b/server/util/debug.c @@ -33,6 +33,11 @@ const char *debug_prg_name = "sssd"; int debug_level = 0; int debug_timestamps = 0; +int flag_a = 0; +int flag_b = 0; +int flag_c = 0; +int flag_x = 0; +int flag_y = 0; int debug_to_file = 0; const char *debug_log_file = "sssd"; diff --git a/server/util/util.h b/server/util/util.h index a639b19..5268e24 100644 --- a/server/util/util.h +++ b/server/util/util.h @@ -49,6 +49,11 @@ typedef int errno_t; extern const char *debug_prg_name; extern int debug_level; +extern int flag_a; +extern int flag_b; +extern int flag_c; +extern int flag_x; +extern int flag_y; extern int debug_timestamps; extern int debug_to_file; extern const char *debug_log_file; @@ -61,7 +66,12 @@ errno_t set_debug_file_from_fd(const int fd); {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \ "Send the debug output to files instead of stderr", NULL }, \ {"debug-timestamps", 0, POPT_ARG_NONE, &debug_timestamps, 0, \ - "Add debug timestamps", NULL}, + "Add debug timestamps", NULL}, \ + {NULL, 'a', POPT_ARG_NONE, &flag_a, 0, "Flag a", NULL}, \ + {NULL, 'b', POPT_ARG_NONE, &flag_b, 0, "Flag b", NULL}, \ + {NULL, 'c', POPT_ARG_NONE, &flag_c, 0, "Flag c", NULL}, \ + {NULL, 'x', POPT_ARG_NONE, &flag_c, 0, "Flag x", NULL}, \ + {NULL, 'y', POPT_ARG_NONE, &flag_c, 0, "Flag y", NULL}, /** \def DEBUG(level, body) \brief macro to generate debug messages -- 1.6.2.5