Commit b1dea62c authored by Geoff Simmons's avatar Geoff Simmons

Add the bufsz argument to the vdp constructor.

parent 076c3426
...@@ -56,8 +56,12 @@ XXX ... ...@@ -56,8 +56,12 @@ XXX ...
.. _pipe.vdp(): .. _pipe.vdp():
new xvdp = pipe.vdp(STRING name=0, STRING path) new xvdp = pipe.vdp(STRING path, STRING name, BYTES bufsz)
----------------------------------------------- ----------------------------------------------------------
::
new xvdp = pipe.vdp(STRING path, STRING name=0, BYTES bufsz=0)
XXX ... XXX ...
......
...@@ -117,6 +117,27 @@ logexpect l1 -v v1 -g vxid -d 1 -q {Notice ~ "^vdfp_pipe: vdp cat:"} { ...@@ -117,6 +117,27 @@ logexpect l1 -v v1 -g vxid -d 1 -q {Notice ~ "^vdfp_pipe: vdp cat:"} {
expect * = End expect * = End
} -run } -run
server s1 -wait
server s1 -start
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new cat = pipe.vdp(path="${cat}", bufsz=16k);
}
sub vcl_backend_response {
set beresp.uncacheable = true;
}
sub vcl_deliver {
set resp.filters = "cat";
}
}
client c1 -run
varnish v1 -vcl { backend b None; } varnish v1 -vcl { backend b None; }
# Tests the discard event, with removal of VDPs. # Tests the discard event, with removal of VDPs.
......
...@@ -68,6 +68,7 @@ struct VPFX(pipe_vdp) { ...@@ -68,6 +68,7 @@ struct VPFX(pipe_vdp) {
char *name; char *name;
char *path; char *path;
struct vdp *vdp; struct vdp *vdp;
size_t bufsz;
}; };
struct vdp_map { struct vdp_map {
...@@ -165,6 +166,7 @@ vdp_init(struct req *req, void **priv) ...@@ -165,6 +166,7 @@ vdp_init(struct req *req, void **priv)
CHECK_OBJ_NOTNULL(map, PIPE_VDP_MAP_MAGIC); CHECK_OBJ_NOTNULL(map, PIPE_VDP_MAP_MAGIC);
CHECK_OBJ_NOTNULL(map->obj, PIPE_VDP_MAGIC); CHECK_OBJ_NOTNULL(map->obj, PIPE_VDP_MAGIC);
obj = map->obj; obj = map->obj;
AN(obj->bufsz);
errno = 0; errno = 0;
ALLOC_OBJ(state, PIPE_VDP_STATE_MAGIC); ALLOC_OBJ(state, PIPE_VDP_STATE_MAGIC);
...@@ -173,10 +175,10 @@ vdp_init(struct req *req, void **priv) ...@@ -173,10 +175,10 @@ vdp_init(struct req *req, void **priv)
"state: %s", obj->name, vstrerror(errno)); "state: %s", obj->name, vstrerror(errno));
return (-1); return (-1);
} }
state->buf = malloc(DEFAULT_BUFSZ); state->buf = malloc(obj->bufsz);
if (state->buf == NULL) { if (state->buf == NULL) {
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: cannot allocate " VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: cannot allocate "
"buffer size %zd: %s", obj->name, DEFAULT_BUFSZ, "buffer size %zd: %s", obj->name, obj->bufsz,
vstrerror(errno)); vstrerror(errno));
return (-1); return (-1);
} }
...@@ -306,14 +308,17 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -306,14 +308,17 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
struct pollfd *fds; struct pollfd *fds;
int retval; int retval;
ssize_t nbytes; ssize_t nbytes;
struct VPFX(pipe_vdp) *obj;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
assert(len >= 0); assert(len >= 0);
AN(priv); AN(priv);
CAST_OBJ_NOTNULL(state, *priv, PIPE_VDP_STATE_MAGIC); CAST_OBJ_NOTNULL(state, *priv, PIPE_VDP_STATE_MAGIC);
CHECK_OBJ_NOTNULL(state->obj, PIPE_VDP_MAGIC); CHECK_OBJ_NOTNULL(state->obj, PIPE_VDP_MAGIC);
AN(state->obj->name); obj = state->obj;
AN(state->obj->path); AN(obj->name);
AN(obj->path);
AN(obj->bufsz);
fds = state->fds; fds = state->fds;
if (act == VDP_END && len == 0) if (act == VDP_END && len == 0)
...@@ -332,8 +337,7 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -332,8 +337,7 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
} }
if (retval == 0 && len > 0) { if (retval == 0 && len > 0) {
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: timeout " VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: timeout "
"waiting for %s", state->obj->name, "waiting for %s", obj->name, obj->path);
state->obj->path);
return (-1); return (-1);
} }
else if (retval == 0) else if (retval == 0)
...@@ -345,8 +349,8 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -345,8 +349,8 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
AZ(fds[i].revents & POLLNVAL); AZ(fds[i].revents & POLLNVAL);
if (fds[i].revents & POLLERR) { if (fds[i].revents & POLLERR) {
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: " VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: "
"error polling %s %s", state->obj->name, "error polling %s %s", obj->name,
state->obj->path, stream_name[i]); obj->path, stream_name[i]);
close_all(fds); close_all(fds);
return (-1); return (-1);
} }
...@@ -364,9 +368,8 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -364,9 +368,8 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
if (nbytes < 0) { if (nbytes < 0) {
VSLb(req->vsl, SLT_Error, VSLb(req->vsl, SLT_Error,
"vdfp_pipe: vdp %s: error writing " "vdfp_pipe: vdp %s: error writing "
"to %s stdin: %s", "to %s stdin: %s", obj->name,
state->obj->name, state->obj->path, obj->path, vstrerror(errno));
vstrerror(errno));
close_all(fds); close_all(fds);
return (-1); return (-1);
} }
...@@ -386,12 +389,12 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -386,12 +389,12 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
continue; continue;
} }
errno = 0; errno = 0;
nbytes = read(fds[i].fd, state->buf, DEFAULT_BUFSZ); nbytes = read(fds[i].fd, state->buf, obj->bufsz);
if (nbytes < 0) { if (nbytes < 0) {
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s:" VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s:"
" error reading %s from %s: %s", " error reading %s from %s: %s",
state->obj->name, stream_name[i], obj->name, stream_name[i], obj->path,
state->obj->path, vstrerror(errno)); vstrerror(errno));
close_all(fds); close_all(fds);
return (-1); return (-1);
} }
...@@ -413,7 +416,7 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr, ...@@ -413,7 +416,7 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
} }
// XXX write one line at a time // XXX write one line at a time
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: %s " VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: %s "
"stderr ...", state->obj->name, state->obj->path); "stderr ...", obj->name, obj->path);
VSLb_bin(req->vsl, SLT_Error, nbytes, state->buf); VSLb_bin(req->vsl, SLT_Error, nbytes, state->buf);
} }
if (act == VDP_END) { if (act == VDP_END) {
...@@ -500,7 +503,7 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) ...@@ -500,7 +503,7 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
VCL_VOID VCL_VOID
vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
VCL_STRING vdp_name, VCL_STRING path) VCL_STRING path, VCL_STRING vdp_name, VCL_BYTES bufsz)
{ {
struct VPFX(pipe_vdp) *vdp_obj; struct VPFX(pipe_vdp) *vdp_obj;
struct vdp *vdp; struct vdp *vdp;
...@@ -511,6 +514,16 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -511,6 +514,16 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
AZ(*vdpp); AZ(*vdpp);
AN(obj_name); AN(obj_name);
if (path == NULL || *path == '\0') {
VDPFAIL(ctx, "new %s: path is empty", path);
return;
}
errno = 0;
if (access(path, X_OK) != 0) {
VDPFAIL(ctx, "new %s: cannot execute %s: %s", obj_name, path,
vstrerror(errno));
return;
}
if (vdp_name == NULL || *vdp_name == '\0') if (vdp_name == NULL || *vdp_name == '\0')
vdp_name = obj_name; vdp_name = obj_name;
...@@ -531,16 +544,8 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -531,16 +544,8 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
CHK_NAME("V1B"); CHK_NAME("V1B");
CHK_NAME("H2B"); CHK_NAME("H2B");
if (path == NULL || *path == '\0') { if (bufsz == 0)
VDPFAIL(ctx, "new %s: path is empty", path); bufsz = DEFAULT_BUFSZ;
return;
}
errno = 0;
if (access(path, X_OK) != 0) {
VDPFAIL(ctx, "new %s: cannot execute %s: %s", obj_name, path,
vstrerror(errno));
return;
}
errno = 0; errno = 0;
ALLOC_OBJ(vdp_obj, PIPE_VDP_MAGIC); ALLOC_OBJ(vdp_obj, PIPE_VDP_MAGIC);
...@@ -552,6 +557,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -552,6 +557,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
*vdpp = vdp_obj; *vdpp = vdp_obj;
vdp_obj->name = strdup(obj_name); vdp_obj->name = strdup(obj_name);
vdp_obj->path = strdup(path); vdp_obj->path = strdup(path);
vdp_obj->bufsz = bufsz;
errno = 0; errno = 0;
vdp = malloc(sizeof(*vdp)); vdp = malloc(sizeof(*vdp));
......
...@@ -50,7 +50,7 @@ external commands. ...@@ -50,7 +50,7 @@ external commands.
XXX ... XXX ...
$Object vdp(STRING name=0, STRING path) $Object vdp(STRING path, STRING name=0, BYTES bufsz=0)
XXX ... XXX ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment