The stdin filedescriptor needs to be non-blocking

Any real-world object will exceed the pipe buffer in size. Unless the
filter program which we invoke implemented an infinite buffer (and
requiring something like this would miss the point of stream
processing), we can only write to the program as much data as it
accepts for its input buffering (plus the pipe buffer size), before we
need to read its output.

Thus, we need to ensure that write(fds[STDIN_FILENO].fd) does not
block.
parent dcc7f1be
......@@ -6,7 +6,8 @@ AM_LDFLAGS = $(VARNISHAPI_LIBS) -ldl -lrt
vmod_LTLIBRARIES = libvmod_pipe.la
libvmod_pipe_la_SOURCES = \
vdfp_pipe.c
vdfp_pipe.c \
from_varnish/vfil.c
nodist_libvmod_pipe_la_SOURCES = \
vcc_if.c \
......
This directory contains code taken from varnish-cache which is not
(yet) part of its APIs.
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Dag-Erling Smørgrav <des@des.no>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#include <unistd.h>
#include <fcntl.h>
#include "vdef.h"
#include "vas.h"
#include "vfil.h"
int
VFIL_nonblocking(int fd)
{
int i;
i = fcntl(fd, F_GETFL);
assert(i != -1);
i |= O_NONBLOCK;
i = fcntl(fd, F_SETFL, i);
assert(i != -1);
return (i);
}
int VFIL_nonblocking(int);
......@@ -46,6 +46,8 @@
#include "vcl.h"
#include "vtree.h"
#include "from_varnish/vfil.h"
#include "vcc_if.h"
extern char **environ;
......@@ -306,6 +308,7 @@ vdp_init(struct vdp_ctx *ctx, void **priv, struct objcore *objcore)
closefd(&in[0]);
closefd(&out[1]);
closefd(&err[1]);
(void) VFIL_nonblocking(in[1]);
state->fds[STDIN_FILENO].fd = in[1];
state->fds[STDOUT_FILENO].fd = out[0];
state->fds[STDERR_FILENO].fd = err[0];
......
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