[master] c4d8fad Make listening to stdout/err a convenience function
Poul-Henning Kamp
phk at FreeBSD.org
Tue Mar 27 11:48:11 UTC 2018
commit c4d8fadc5490306576e0d5ed2284cca9cd2d3177
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Mar 27 11:20:19 2018 +0000
Make listening to stdout/err a convenience function
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 387181c..8878e1d 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -132,6 +132,7 @@ struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg);
void vtc_expect(struct vtclog *, const char *, const char *, const char *,
const char *, const char *);
void vtc_wait4(struct vtclog *, long, int, int, int);
+void *vtc_record(struct vtclog *, int);
/* vtc_term.c */
struct term *Term_New(struct vtclog *, int, int);
diff --git a/bin/varnishtest/vtc_subr.c b/bin/varnishtest/vtc_subr.c
index 1a9ff10..39cafbe 100644
--- a/bin/varnishtest/vtc_subr.c
+++ b/bin/varnishtest/vtc_subr.c
@@ -31,15 +31,19 @@
#include <sys/types.h>
#include <errno.h>
#include <math.h>
+#include <poll.h>
#include <string.h>
#include <stdint.h>
+#include <unistd.h>
#include <sys/wait.h>
#include <sys/resource.h>
+#include "vtc.h"
+
#include "vct.h"
#include "vnum.h"
#include "vre.h"
-#include "vtc.h"
+#include "vtcp.h"
struct vsb *
vtc_hex_to_bin(struct vtclog *vl, const char *arg)
@@ -180,3 +184,34 @@ vtc_wait4(struct vtclog *vl, long pid,
WIFSIGNALED(status) ? WTERMSIG(status) : 0,
WCOREDUMP(status));
}
+
+void *
+vtc_record(struct vtclog *vl, int fd)
+{
+ char buf[65536];
+ struct pollfd fds[1];
+ int i;
+
+ (void)VTCP_nonblocking(fd);
+ while (1) {
+ memset(fds, 0, sizeof fds);
+ fds->fd = fd;
+ fds->events = POLLIN;
+ i = poll(fds, 1, 10000);
+ if (i == 0)
+ continue;
+ if (fds->revents & POLLIN) {
+ i = read(fd, buf, sizeof buf - 1);
+ if (i > 0) {
+ buf[i] = '\0';
+ vtc_dump(vl, 3, "debug", buf, -2);
+ }
+ }
+ if (fds->revents & (POLLERR|POLLHUP)) {
+ vtc_log(vl, 4, "STDOUT poll 0x%x", fds->revents);
+ break;
+ }
+ }
+ return (NULL);
+}
+
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index a1a5ed8..d09d7cf 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -374,32 +374,9 @@ static void *
varnish_thread(void *priv)
{
struct varnish *v;
- char buf[65536];
- struct pollfd fds[1];
- int i;
CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC);
- (void)VTCP_nonblocking(v->fds[0]);
- while (1) {
- memset(fds, 0, sizeof fds);
- fds->fd = v->fds[0];
- fds->events = POLLIN;
- i = poll(fds, 1, 10000);
- if (i == 0)
- continue;
- if (fds->revents & POLLIN) {
- i = read(v->fds[0], buf, sizeof buf - 1);
- if (i > 0) {
- buf[i] = '\0';
- vtc_dump(v->vl, 3, "debug", buf, -2);
- }
- }
- if (fds->revents & (POLLERR|POLLHUP)) {
- vtc_log(v->vl, 4, "STDOUT poll 0x%x", fds->revents);
- break;
- }
- }
- return (NULL);
+ return (vtc_record(v->vl, v->fds[0]));
}
/**********************************************************************
More information about the varnish-commit
mailing list