From: Christophe Jaillet Date: Sun, 31 Jan 2016 17:10:27 +0000 (+0000) Subject: mod_heartmonitor: No need to search twice for the same value + fix some style X-Git-Tag: 2.5.0-alpha~2233 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f68e384a26cb0293f8dbc6739625c292eead0dc;p=apache mod_heartmonitor: No need to search twice for the same value + fix some style git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1727842 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/cluster/mod_heartmonitor.c b/modules/cluster/mod_heartmonitor.c index 1389e27eda..965fef5899 100644 --- a/modules/cluster/mod_heartmonitor.c +++ b/modules/cluster/mod_heartmonitor.c @@ -272,6 +272,7 @@ static apr_status_t hm_file_update_stat(hm_ctx_t *ctx, hm_server_t *s, apr_pool_ char buf[4096]; const char *ip; apr_size_t bsize = sizeof(buf); + apr_brigade_cleanup(tmpbb); if (APR_BRIGADE_EMPTY(bb)) { break; @@ -293,45 +294,55 @@ static apr_status_t hm_file_update_stat(hm_ctx_t *ctx, hm_server_t *s, apr_pool_ t = strchr(buf, ' '); if (t) { ip = apr_pstrmemdup(pool, buf, t - buf); - } else { + } + else { ip = NULL; } + if (!ip || buf[0] == '#') { /* copy things we can't process */ apr_file_printf(fp, "%s\n", buf); - } else if (strcmp(ip, s->ip) !=0 ) { + } + else if (strcmp(ip, s->ip) != 0 ) { hm_server_t node; apr_time_t seen; + const char *val; + /* Update seen time according to the last file modification */ apr_table_clear(hbt); qs_to_table(apr_pstrdup(pool, t), hbt, pool); - if (apr_table_get(hbt, "busy")) { - node.busy = atoi(apr_table_get(hbt, "busy")); - } else { + if ((val = apr_table_get(hbt, "busy"))) { + node.busy = atoi(val); + } + else { node.busy = 0; } - if (apr_table_get(hbt, "ready")) { - node.ready = atoi(apr_table_get(hbt, "ready")); - } else { + if ((val = apr_table_get(hbt, "ready"))) { + node.ready = atoi(val); + } + else { node.ready = 0; } - if (apr_table_get(hbt, "lastseen")) { - node.seen = atoi(apr_table_get(hbt, "lastseen")); - } else { + if ((val = apr_table_get(hbt, "lastseen"))) { + node.seen = atoi(val); + } + else { node.seen = SEEN_TIMEOUT; } seen = fage + node.seen; - if (apr_table_get(hbt, "port")) { - node.port = atoi(apr_table_get(hbt, "port")); - } else { + if ((val = apr_table_get(hbt, "port"))) { + node.port = atoi(val); + } + else { node.port = 80; } apr_file_printf(fp, "%s &ready=%u&busy=%u&lastseen=%u&port=%u\n", ip, node.ready, node.busy, (unsigned int) seen, node.port); - } else { + } + else { apr_time_t seen; seen = apr_time_sec(now - s->seen); apr_file_printf(fp, "%s &ready=%u&busy=%u&lastseen=%u&port=%u\n",