Update vsub.c from varnish-cache

parent b9205c4e
......@@ -5,6 +5,7 @@ AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/vdfp_pipe.vcc)
AC_CONFIG_HEADERS([config.h])
AC_CANONICAL_TARGET
AC_GNU_SOURCE
AC_LANG(C)
AM_INIT_AUTOMAKE([1.12 -Wall -Werror foreign parallel-tests])
......@@ -77,6 +78,29 @@ AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
LIBS="${save_LIBS}"
AC_CHECK_FUNCS([close_range])
# Check for working close_range()
if test "$ac_cv_func_close_range" = yes; then
AC_CACHE_CHECK([if close_range is working],
[ac_cv_have_working_close_range],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[
#include <unistd.h>
]],[[
return (close_range(0, 2, 0));
]])],
[ac_cv_have_working_close_range=yes],
[ac_cv_have_working_close_range=no])
])
fi
if test "x$ac_cv_have_working_close_range" = xyes; then
AC_DEFINE([HAVE_WORKING_CLOSE_RANGE], [1],
[Define if OS has working close_range()])
fi
# --enable-stack-protector
AC_ARG_ENABLE(stack-protector,
AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is YES)]),
......
......@@ -33,27 +33,43 @@
#include "config.h"
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef HAVE_CLOSEFROM
#include <stdint.h>
#include <stdlib.h> // Solaris closefrom(3c)
#include <string.h>
#include <unistd.h> // BSD/Linux close_range(2)
#ifdef HAVE_WORKING_CLOSE_RANGE
#elif HAVE_CLOSEFROM
#else
# include <dirent.h>
#endif
#include "vdef.h"
#include "vas.h"
#include "vapi/vsig.h"
#include "vas.h"
#include "vfil.h"
#include "vsb.h"
#include "vsub.h"
struct vsub_priv {
const char *name;
struct vsb *sb;
int lines;
int maxlines;
};
void
VSUB_closefrom(int fd)
{
assert(fd >= 0);
#ifdef HAVE_CLOSEFROM
#ifdef HAVE_WORKING_CLOSE_RANGE
AZ(close_range(fd, ~0U, 0));
return;
#elif HAVE_CLOSEFROM
closefrom(fd);
return;
#else
......@@ -86,3 +102,4 @@ VSUB_closefrom(int fd)
(void)close(maxfd);
#endif
}
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