From 9933f301dd2070d1a9d0465f7424181663b654e3 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Thu, 18 Feb 2016 15:07:33 +0000 Subject: [PATCH] Merge r1727842 from trunk: mod_heartmonitor: No need to search twice for the same value + fix some style Submitted by: jailletc36 Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1731086 13f79535-47bb-0310-9956-ffa450edef68 --- STATUS | 4 --- modules/cluster/mod_heartmonitor.c | 41 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/STATUS b/STATUS index 71634dd7ed..309cf7e57b 100644 --- a/STATUS +++ b/STATUS @@ -112,10 +112,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) mod_heartmonitor: No need to search twice for the same value + fix some style - trunk patch: http://svn.apache.org/r1727842 - 2.4.x patch: trunk works - +1: jailletc36, jim, rpluem PATCHES PROPOSED TO BACKPORT FROM TRUNK: [ New proposals should be added at the end of the list ] 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", -- 2.50.1