From 9dc1dea9df10d4248cb6f0be5db2cde6f27aed41 Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Fri, 29 Jun 2012 21:23:47 +0000 Subject: [PATCH] minimal ps_to_http secondary-pubsub-url fixes don't print ERROR when no secondary-pubsub-url has been specified delete timer before setting it again for secondary-pubsub-url --- ps_to_http/ps_to_http.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/ps_to_http/ps_to_http.c b/ps_to_http/ps_to_http.c index 1c8e731..4187d12 100644 --- a/ps_to_http/ps_to_http.c +++ b/ps_to_http/ps_to_http.c @@ -175,7 +175,7 @@ void free_destination_urls() int main(int argc, char **argv) { char *pubsub_url; - char *secondary_pubsub_url = NULL; + char *secondary_pubsub_url; char *address; int port; char *path; @@ -215,23 +215,26 @@ int main(int argc, char **argv) } else { fprintf(stderr, "ERROR: failed to parse pubsub_url\n"); } - if (secondary_pubsub_url && simplehttp_parse_url(secondary_pubsub_url, strlen(secondary_pubsub_url), &address, &port, &path)) { + if (secondary_pubsub_url) { + if (simplehttp_parse_url(secondary_pubsub_url, strlen(secondary_pubsub_url), &address, &port, &path)) { pubsubclient_init(address, port, path, process_message_cb, error_cb, NULL); - if (option_get_int("max_silence") > 0) { - _DEBUG("Registering timer.\n"); - max_silence_time.tv_sec = option_get_int("max_silence"); - evtimer_set(&silence_ev, silence_cb, NULL); - evtimer_add(&silence_ev, &max_silence_time); - } + if (option_get_int("max_silence") > 0) { + _DEBUG("Registering timer.\n"); + max_silence_time.tv_sec = option_get_int("max_silence"); + evtimer_del(&silence_ev); + evtimer_set(&silence_ev, silence_cb, NULL); + evtimer_add(&silence_ev, &max_silence_time); + } - pubsubclient_run(); + pubsubclient_run(); - free(address); - free(path); - free(secondary_pubsub_url); - } else { - fprintf(stderr, "ERROR: failed to parse secondary_pubsub_url\n"); + free(address); + free(path); + free(secondary_pubsub_url); + } else { + fprintf(stderr, "ERROR: failed to parse secondary_pubsub_url\n"); + } } free_destination_urls();