]> granicus.if.org Git - apache/commitdiff
mod_heartmonitor: No need to search twice for the same value + fix some style
authorChristophe Jaillet <jailletc36@apache.org>
Sun, 31 Jan 2016 17:10:27 +0000 (17:10 +0000)
committerChristophe Jaillet <jailletc36@apache.org>
Sun, 31 Jan 2016 17:10:27 +0000 (17:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1727842 13f79535-47bb-0310-9956-ffa450edef68

modules/cluster/mod_heartmonitor.c

index 1389e27edab8027bf8d476fb536f45e4c8e3e486..965fef5899288e09aec2da2b0dfc2e49797942c0 100644 (file)
@@ -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",