]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: snapshot: merge the captured data after the descriptor
authorWilly Tarreau <w@1wt.eu>
Fri, 7 Sep 2018 18:07:17 +0000 (20:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Sep 2018 18:07:17 +0000 (20:07 +0200)
Instead of having a separate area for the captured data, we now have a
contigous block made of the descriptor and the data. At the moment, since
the area is dynamically allocated, we can adjust its size to what is
needed, but the idea is to quickly switch to a pool and an LRU list.

include/types/proxy.h
src/proxy.c

index ca3bc7de230a9d6b6b85a23b6f752dcd3f473f29..2d1b881965927bf0cafd977856658f2e91820f65 100644 (file)
@@ -225,7 +225,7 @@ struct error_snapshot {
        /**** common part ****/
        struct timeval when;            /* date of this event, (tv_sec == 0) means "never" */
        /* @16 */
-       char *buf;                      /* copy of the beginning of the message (may be NULL) */
+       void (*show)(struct buffer *, const struct error_snapshot *); /* dump function */
        unsigned long long buf_ofs;     /* relative position of the buffer's input inside its container */
        /* @32 */
        unsigned int buf_out;           /* pending output bytes _before_ the buffer's input (0..buf->data-1) */
@@ -239,10 +239,10 @@ struct error_snapshot {
        unsigned int ev_id;             /* event number (counter incremented for each capture) */
        /* @68: 4 bytes hole here */
        struct sockaddr_storage src;    /* client's address */
-       void (*show)(struct buffer *, const struct error_snapshot *); /* dump function */
 
        /**** protocol-specific part ****/
        union error_snapshot_ctx ctx;
+       char buf[0];                    /* copy of the beginning of the message for bufsize bytes */
 };
 
 struct email_alert {
index 9f9fec878c8332ecc6f4f41b8097e03f6d41c247..0fbfce9c609d5f9ecf5ea637832cf94340ee2f0c 100644 (file)
@@ -1360,25 +1360,22 @@ void proxy_capture_error(struct proxy *proxy, int is_back,
 
        ev_id = HA_ATOMIC_XADD(&error_snapshot_id, 1);
 
-       es = malloc(sizeof(*es));
+       buf_len = b_data(buf) - buf_out;
+
+       es = malloc(sizeof(*es) + buf_len);
        if (!es)
                return;
 
-       es->ev_id    = ev_id;
+       es->buf_len = buf_len;
+       es->ev_id   = ev_id;
 
-       buf_len = b_data(buf) - buf_out;
        len1 = b_size(buf) - buf_len;
        if (len1 > buf_len)
                len1 = buf_len;
-       len2 = buf_len - len1;
-
-       es->buf_len = buf_len;
-
-       if (!es->buf)
-               es->buf = malloc(global.tune.bufsize);
 
-       if (es->buf) {
+       if (len1) {
                memcpy(es->buf, b_peek(buf, buf_out), len1);
+               len2 = buf_len - len1;
                if (len2)
                        memcpy(es->buf + len1, b_orig(buf), len2);
        }
@@ -2119,7 +2116,7 @@ static int cli_io_handler_show_errors(struct appctx *appctx)
                }
 
                /* OK, ptr >= 0, so we have to dump the current line */
-               while (es->buf && appctx->ctx.errors.ptr < es->buf_len && appctx->ctx.errors.ptr < global.tune.bufsize) {
+               while (appctx->ctx.errors.ptr < es->buf_len && appctx->ctx.errors.ptr < global.tune.bufsize) {
                        int newptr;
                        int newline;