[master] 79889bc Also \n terminate in the NONL case where no quoting is necessary.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Jan 19 18:30:06 CET 2017
commit 79889bc2ff512ea2850cb5bd88b35677e3b660c1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jan 19 17:16:19 2017 +0000
Also \n terminate in the NONL case where no quoting is necessary.
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index dbe4508..e0d2744 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -723,15 +723,39 @@ static const struct cmds cmds[] = {
{ NULL, NULL }
};
+static const char *tfn;
+
+int
+fail_out(void)
+{
+ unsigned old_err;
+
+ old_err = vtc_error;
+ if (!vtc_stop)
+ vtc_stop = 1;
+ vtc_log(vltop, 1, "RESETTING after %s", tfn);
+ reset_cmds(cmds);
+ vtc_error |= old_err;
+
+ if (vtc_error)
+ vtc_log(vltop, 1, "TEST %s FAILED", tfn);
+ else
+ vtc_log(vltop, 1, "TEST %s completed", tfn);
+
+ if (vtc_stop > 1)
+ return (1);
+ return (vtc_error);
+}
+
int
exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen)
{
- unsigned old_err;
FILE *f;
(void)signal(SIGPIPE, SIG_IGN);
+ tfn = fn;
vtc_loginit(logbuf, loglen);
vltop = vtc_logopen("top");
AN(vltop);
@@ -755,19 +779,5 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
vtc_thread = pthread_self();
parse_string(script, cmds, NULL, vltop);
- old_err = vtc_error;
- if (!vtc_stop)
- vtc_stop = 1;
- vtc_log(vltop, 1, "RESETTING after %s", fn);
- reset_cmds(cmds);
- vtc_error |= old_err;
-
- if (vtc_error)
- vtc_log(vltop, 1, "TEST %s FAILED", fn);
- else
- vtc_log(vltop, 1, "TEST %s completed", fn);
-
- if (vtc_stop > 1)
- return (1);
- return (vtc_error);
+ return(fail_out());
}
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 8f999ad..14f3340 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -57,6 +57,7 @@ struct cmds {
void parse_string(const char *spec, const struct cmds *cmd, void *priv,
struct vtclog *vl);
+int fail_out(void);
#define CMD(n) cmd_f cmd_##n
CMD(delay);
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 46f6d68..a25b235 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -524,14 +524,18 @@ http_rxchar(struct http *hp, int n, int eof)
i = poll(pfd, 1, hp->timeout);
if (i < 0 && errno == EINTR)
continue;
- if (i == 0)
+ if (i == 0) {
vtc_log(hp->vl, hp->fatal,
"HTTP rx timeout (fd:%d %u ms)",
hp->fd, hp->timeout);
- if (i < 0)
+ continue;
+ }
+ if (i < 0) {
vtc_log(hp->vl, hp->fatal,
"HTTP rx failed (fd:%d poll: %s)",
hp->fd, strerror(errno));
+ continue;
+ }
assert(i > 0);
assert(hp->prxbuf + n < hp->nrxbuf);
i = read(hp->fd, hp->rxbuf + hp->prxbuf, n);
@@ -541,14 +545,18 @@ http_rxchar(struct http *hp, int n, int eof)
hp->fd, pfd[0].revents, n, i);
if (i == 0 && eof)
return (i);
- if (i == 0)
+ if (i == 0) {
vtc_log(hp->vl, hp->fatal,
"HTTP rx EOF (fd:%d read: %s) %d",
hp->fd, strerror(errno), n);
- if (i < 0)
+ return (-1);
+ }
+ if (i < 0) {
vtc_log(hp->vl, hp->fatal,
"HTTP rx failed (fd:%d read: %s)",
hp->fd, strerror(errno));
+ return (-1);
+ }
hp->prxbuf += i;
hp->rxbuf[hp->prxbuf] = '\0';
n -= i;
@@ -563,9 +571,10 @@ http_rxchunk(struct http *hp)
int l, i;
l = hp->prxbuf;
- do
- (void)http_rxchar(hp, 1, 0);
- while (hp->rxbuf[hp->prxbuf - 1] != '\n');
+ do {
+ if (http_rxchar(hp, 1, 0) < 0)
+ return (-1);
+ } while (hp->rxbuf[hp->prxbuf - 1] != '\n');
vtc_dump(hp->vl, 4, "len", hp->rxbuf + l, -1);
i = strtoul(hp->rxbuf + l, &q, 16);
bprintf(hp->chunklen, "%d", i);
@@ -573,25 +582,31 @@ http_rxchunk(struct http *hp)
(*q != '\0' && !vct_islws(*q))) {
vtc_log(hp->vl, hp->fatal, "chunked fail %02x @ %td",
*q, q - (hp->rxbuf + l));
+ return (-1);
}
assert(q != hp->rxbuf + l);
assert(*q == '\0' || vct_islws(*q));
hp->prxbuf = l;
if (i > 0) {
- (void)http_rxchar(hp, i, 0);
- vtc_dump(hp->vl, 4, "chunk",
- hp->rxbuf + l, i);
+ if (http_rxchar(hp, i, 0) < 0)
+ return (-1);
+ vtc_dump(hp->vl, 4, "chunk", hp->rxbuf + l, i);
}
l = hp->prxbuf;
- (void)http_rxchar(hp, 2, 0);
- if(!vct_iscrlf(hp->rxbuf + l))
+ if (http_rxchar(hp, 2, 0) < 0)
+ return (-1);
+ if(!vct_iscrlf(hp->rxbuf + l)) {
vtc_log(hp->vl, hp->fatal,
"Wrong chunk tail[0] = %02x",
hp->rxbuf[l] & 0xff);
- if(!vct_iscrlf(hp->rxbuf + l + 1))
+ return (-1);
+ }
+ if(!vct_iscrlf(hp->rxbuf + l + 1)) {
vtc_log(hp->vl, hp->fatal,
"Wrong chunk tail[1] = %02x",
hp->rxbuf[l + 1] & 0xff);
+ return (-1);
+ }
hp->prxbuf = l;
hp->rxbuf[l] = '\0';
return (i);
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 309a10b..8914e43 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -101,6 +101,18 @@ vtc_logclose(struct vtclog *vl)
FREE_OBJ(vl);
}
+static void __attribute__((__noreturn__))
+vtc_logfail(void)
+{
+
+ vtc_error = 2;
+ if (pthread_self() != vtc_thread) {
+ fprintf(stderr, "FAIL thread %p\n", pthread_self());
+ pthread_exit(NULL);
+ } else
+ exit(fail_out());
+}
+
static const char * const lead[] = {
"----",
"* ",
@@ -162,11 +174,9 @@ vtc_fatal(struct vtclog *vl, const char *fmt, ...)
va_end(ap);
REL_VL(vl);
- vtc_error = 2;
- if (pthread_self() != vtc_thread)
- pthread_exit(NULL);
- while(1) continue;
+ vtc_logfail();
}
+
void
vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...)
{
@@ -184,9 +194,7 @@ vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...)
if (lvl > 0)
return;
if (lvl == 0)
- vtc_error = 2;
- if (pthread_self() != vtc_thread)
- pthread_exit(NULL);
+ vtc_logfail();
}
/**********************************************************************
@@ -213,11 +221,8 @@ vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len)
VSB_printf(vl->vsb, "%s [...] (%d)", buf, len - 1024);
}
REL_VL(vl);
- if (lvl == 0) {
- vtc_error = 2;
- if (pthread_self() != vtc_thread)
- pthread_exit(NULL);
- }
+ if (lvl == 0)
+ vtc_logfail();
}
/**********************************************************************
@@ -255,11 +260,8 @@ vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx,
if (!nl)
VSB_printf(vl->vsb, "\n");
REL_VL(vl);
- if (lvl == 0) {
- vtc_error = 2;
- if (pthread_self() != vtc_thread)
- pthread_exit(NULL);
- }
+ if (lvl == 0)
+ vtc_logfail();
}
/**********************************************************************/
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index ebc8b4d..7cdf3fc 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -227,6 +227,9 @@ tst_cb(const struct vev *ve, int what)
free(jp->tmpdir);
VSB_destroy(&v);
+ if (jp->killed)
+ printf("# top TEST %s TIMED OUT (kill -9)\n",
+ jp->tst->filename);
if (ecode > 1) {
printf("# top TEST %s FAILED (%.3f)",
jp->tst->filename, t);
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index 99e6f50..bc72919 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -544,6 +544,8 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
}
if (!quote && !(how & (VSB_QUOTE_JSON|VSB_QUOTE_CSTR))) {
(void)VSB_bcat(s, p, len);
+ if ((how & VSB_QUOTE_NONL) && p[len-1] != '\n')
+ (void)VSB_putc(s, '\n');
return;
}
@@ -595,7 +597,7 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
}
if (how & VSB_QUOTE_CSTR)
(void)VSB_putc(s, '"');
- if ((how & VSB_QUOTE_NONL && !nl))
+ if ((how & VSB_QUOTE_NONL) && !nl)
(void)VSB_putc(s, '\n');
}
More information about the varnish-commit
mailing list