]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stats: prepare the connection for closing before dumping
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Sep 2009 17:27:35 +0000 (19:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Sep 2009 21:52:16 +0000 (23:52 +0200)
We will need to modify the stats dump functions so that they can
be used in interactive mode. For this, we want their caller to
prepare the connection for a close, not themselves to do it.
Let's simply move the stream_int_retnclose() out.

src/dumpstats.c
src/proto_http.c

index 681ae8931dd92d8eaacfa90fbe0b18a08d73c7d7..97de0e9f26948b1b68e5361c669d2a8c2f5dadb2 100644 (file)
@@ -272,16 +272,19 @@ int stats_sock_parse_request(struct session *s, char *line)
                        s->data_ctx.stats.flags |= STAT_SHOW_STAT;
                        s->data_ctx.stats.flags |= STAT_FMT_CSV;
                        s->ana_state = STATS_ST_REP;
+                       stream_int_retnclose(s->rep->cons, NULL);
                        buffer_install_hijacker(s, s->rep, stats_dump_raw_to_buffer);
                }
                else if (strcmp(args[1], "info") == 0) {
                        s->data_ctx.stats.flags |= STAT_SHOW_INFO;
                        s->data_ctx.stats.flags |= STAT_FMT_CSV;
                        s->ana_state = STATS_ST_REP;
+                       stream_int_retnclose(s->rep->cons, NULL);
                        buffer_install_hijacker(s, s->rep, stats_dump_raw_to_buffer);
                }
                else if (strcmp(args[1], "sess") == 0) {
                        s->ana_state = STATS_ST_REP;
+                       stream_int_retnclose(s->rep->cons, NULL);
                        buffer_install_hijacker(s, s->rep, stats_dump_sess_to_buffer);
                }
                else if (strcmp(args[1], "errors") == 0) {
@@ -291,6 +294,7 @@ int stats_sock_parse_request(struct session *s, char *line)
                                s->data_ctx.errors.iid  = -1;
                        s->data_ctx.errors.px = NULL;
                        s->ana_state = STATS_ST_REP;
+                       stream_int_retnclose(s->rep->cons, NULL);
                        buffer_install_hijacker(s, s->rep, stats_dump_errors_to_buffer);
                }
                else { /* neither "stat" nor "info" nor "sess" */
@@ -391,7 +395,6 @@ int stats_dump_raw(struct session *s, struct buffer *rep, struct uri_auth *uri)
                /* the function had not been called yet, let's prepare the
                 * buffer for a response.
                 */
-               stream_int_retnclose(rep->cons, &msg);
                s->data_state = DATA_ST_HEAD;
                /* fall through */
 
@@ -538,7 +541,9 @@ int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
                chunk_printf(&msg, sizeof(trash), "\r\n");
 
                s->txn.status = 200;
-               stream_int_retnclose(rep->cons, &msg); // send the start of the response.
+               if (buffer_write_chunk(rep, &msg) >= 0)
+                       return 0;
+
                msg.len = 0;
 
                if (!(s->flags & SN_ERR_MASK))  // this is not really an error but it is
@@ -1404,7 +1409,6 @@ void stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
                 * this pointer. We know we have reached the end when this
                 * pointer points back to the head of the sessions list.
                 */
-               stream_int_retnclose(rep->cons, &msg);
                LIST_INIT(&s->data_ctx.sess.bref.users);
                s->data_ctx.sess.bref.ref = sessions.n;
                s->data_state = DATA_ST_LIST;
@@ -1647,7 +1651,6 @@ void stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
                /* the function had not been called yet, let's prepare the
                 * buffer for a response.
                 */
-               stream_int_retnclose(rep->cons, &msg);
                s->data_ctx.errors.px = proxy;
                s->data_ctx.errors.buf = 0;
                s->data_ctx.errors.bol = 0;
index a159769b6cf04184701ff7aba8fd31487a9d3112..fd768874a728d482ac8af5a42108d6792e7ec716 100644 (file)
@@ -3257,7 +3257,9 @@ void produce_content(struct session *s, struct buffer *rep)
        }
        else if (s->data_source == DATA_SRC_STATS) {
                /* dump server statistics */
-               int ret = stats_dump_http(s, rep, s->be->uri_auth);
+               int ret;
+               stream_int_retnclose(rep->cons, NULL);
+               ret = stats_dump_http(s, rep, s->be->uri_auth);
                if (ret >= 0)
                        return;
                /* -1 indicates an error */