Index: include/compat/err.h =================================================================== --- include/compat/err.h (revision 0) +++ include/compat/err.h (revision 0) @@ -0,0 +1,50 @@ +/* $NetBSD: err.h,v 1.13 2003/08/07 09:44:10 agc Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS 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. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef COMPAT_ERR_H_INCLUDED +#define COMPAT_ERR_H_INCLUDED + +#ifndef HAVE_ERR +#include +void err (int, const char *, ...); +void verr (int, const char *, va_list); +void errx (int, const char *, ...); +void verrx (int, const char *, va_list); +void warn (const char *, ...); +void vwarn (const char *, va_list); +void warnx (const char *, ...); +void vwarnx (const char *, va_list); +#endif + +#endif /* !_ERR_H_ */ + Index: include/Makefile.am =================================================================== --- include/Makefile.am (revision 3071) +++ include/Makefile.am (working copy) @@ -14,6 +14,7 @@ cli_priv.h \ compat/asprintf.h \ compat/daemon.h \ + compat/err.h \ compat/setproctitle.h \ compat/srandomdev.h \ compat/strlcat.h \ Index: configure.ac =================================================================== --- configure.ac (revision 3071) +++ configure.ac (working copy) @@ -22,6 +22,9 @@ AC_CHECK_PROGS(XSLTPROC, [xsltproc]) # Checks for libraries. + +AC_CHECK_LIB(umem, malloc) + save_LIBS="${LIBS}" LIBS="" AC_CHECK_LIB(rt, clock_gettime) @@ -59,6 +62,7 @@ LIBS="" AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, getaddrinfo) +AC_CHECK_LIB(sendfile, sendfile) NET_LIBS="${LIBS}" LIBS="${save_LIBS}" AC_SUBST(NET_LIBS) @@ -74,12 +78,15 @@ AC_CHECK_HEADERS([sys/mount.h]) AC_CHECK_HEADERS([sys/statvfs.h]) AC_CHECK_HEADERS([sys/vfs.h]) +AC_CHECK_HEADERS([sys/filio.h]) +AC_CHECK_HEADERS([err.h]) AC_CHECK_HEADERS([netinet/in.h]) AC_CHECK_HEADERS([pthread_np.h]) AC_CHECK_HEADERS([stddef.h]) AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([unistd.h]) AC_CHECK_HEADERS([vis.h]) +AC_CHECK_HEADERS([umem.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -128,6 +135,15 @@ AC_DEFINE([SENDFILE_WORKS], [1], [Define if SENDFILE works]) fi ;; +*-*-solaris*) + if test "$ac_cv_lib_sendfile_sendfile" = yes; then + save_LIBS="${LIBS}" + LIBS="${NET_LIBS}" + AC_CHECK_FUNCS([sendfile]) + AC_CHECK_FUNCS([sendfilev]) + LIBS="${save_LIBS}" + fi + ;; *) AC_MSG_WARN([won't look for sendfile() on $host]) ;; @@ -136,12 +152,16 @@ # These functions are provided by libcompat on platforms where they # are not available AC_CHECK_FUNCS([asprintf vasprintf]) +AC_CHECK_FUNCS([getprogname getexecname]) AC_CHECK_FUNCS([setproctitle]) AC_CHECK_FUNCS([srandomdev]) AC_CHECK_FUNCS([strlcat strlcpy]) AC_CHECK_FUNCS([strndup]) AC_CHECK_FUNCS([vis strvis strvisx]) AC_CHECK_FUNCS([daemon]) +AC_CHECK_FUNCS([err]) +AC_CHECK_FUNCS([flock]) +AC_CHECK_FUNCS([mktime timegm]) AC_SYS_LARGEFILE save_LIBS="${LIBS}" @@ -203,9 +223,23 @@ ac_cv_func_poll=no fi +# --enable-ports +AC_ARG_ENABLE(ports, + AS_HELP_STRING([--enable-ports], + [use ports if available (default is YES)]), + , + [enable_ports=yes]) + +if test "$enable_ports" = yes; then + AC_CHECK_FUNCS([port_create]) +else + ac_cv_func_port_create=no +fi + if test "$ac_cv_func_kqueue" != yes && test "$ac_cv_func_epoll_ctl" != yes && - test "$ac_cv_func_poll" != yes; then + test "$ac_cv_func_poll" != yes && + test "$ac_cv_func_port_create" != yes; then AC_MSG_ERROR([no usable acceptor mechanism]) fi @@ -305,6 +339,23 @@ AS_HELP_STRING([--enable-werror],[use -Werror (default is NO)]), CFLAGS="${CFLAGS} -Werror") +# Command line for compiling VCL code. I wish there were a simple way +# to figure this out dynamically without introducing a run-time +# dependency on libtool. +case $host in +*-*-solaris*) + VCC_CC="cc -Kpic ${CFLAGS} -G -o %o %s" + ;; +*-*-darwin*) + VCC_CC="cc ${CFLAGS} -dynamiclib -Wl,-flat_namespace,-undefined,suppress -o %o %s" + ;; +*) + VCC_CC="cc ${CFLAGS} -fpic -shared -o %o %s" + ;; +esac + +AC_DEFINE_UNQUOTED([VCC_CC],"$VCC_CC",[C compiler command line for VCL code]) + # Generate output AC_CONFIG_FILES([ Makefile Index: lib/libvarnish/time.c =================================================================== --- lib/libvarnish/time.c (revision 3071) +++ lib/libvarnish/time.c (working copy) @@ -54,6 +54,7 @@ #include #include +#include "config.h" #include "libvarnish.h" double @@ -117,7 +118,13 @@ for (r = fmts; *r != NULL; r++) { memset(&tm, 0, sizeof tm); if (strptime(p, *r, &tm) != NULL) - return (mktime(&tm)); +#if defined(HAVE_TIMEGM) + return(timegm(&tm)); +#elif defined(HAVE_MKTIME) + return(mktime(&tm)); +#else +#error "No functions for struct tm -> time_t conversion" +#endif } return (0); } Index: lib/libvarnish/argv.c =================================================================== --- lib/libvarnish/argv.c (revision 3071) +++ lib/libvarnish/argv.c (working copy) @@ -45,6 +45,7 @@ #include #include +#include "config.h" #include "libvarnish.h" static int Index: lib/libvarnish/assert.c =================================================================== --- lib/libvarnish/assert.c (revision 3071) +++ lib/libvarnish/assert.c (working copy) @@ -37,6 +37,7 @@ #include #include +#include "config.h" #include "libvarnish.h" static void Index: lib/libvarnish/vss.c =================================================================== --- lib/libvarnish/vss.c (revision 3071) +++ lib/libvarnish/vss.c (working copy) @@ -44,6 +44,7 @@ #include #include +#include "config.h" #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif Index: lib/libvarnish/cli_common.c =================================================================== --- lib/libvarnish/cli_common.c (revision 3071) +++ lib/libvarnish/cli_common.c (working copy) @@ -46,6 +46,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "libvarnish.h" Index: lib/libvarnish/binary_heap.c =================================================================== --- lib/libvarnish/binary_heap.c (revision 3071) +++ lib/libvarnish/binary_heap.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include "config.h" #include "binary_heap.h" #include "libvarnish.h" Index: lib/libvarnish/flopen.c =================================================================== --- lib/libvarnish/flopen.c (revision 3071) +++ lib/libvarnish/flopen.c (working copy) @@ -39,6 +39,7 @@ #include #include +#include "config.h" #include "flopen.h" int @@ -46,8 +47,10 @@ { int fd, operation, serrno, trunc; struct stat sb, fsb; + mode_t mode; +#ifndef HAVE_FLOCK struct flock lock; - mode_t mode; +#endif #ifdef O_EXLOCK flags &= ~O_EXLOCK; @@ -62,11 +65,17 @@ va_end(ap); } +#ifndef HAVE_FLOCK lock.l_type = ((flags & O_ACCMODE) == O_RDONLY) ? F_RDLCK : F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; +#else + operation = LOCK_EX; + if (flags & O_NONBLOCK) + operation |= LOCK_NB; +#endif trunc = (flags & O_TRUNC); flags &= ~O_TRUNC; @@ -75,7 +84,11 @@ if ((fd = open(path, flags, mode)) == -1) /* non-existent or no access */ return (-1); +#ifdef F_SETLK if (fcntl(fd, operation, &lock) == -1) { +#else + if (flock(fd, operation) == -1) { +#endif /* unsupported or interrupted */ serrno = errno; (void)close(fd); Index: lib/libvarnish/version.c =================================================================== --- lib/libvarnish/version.c (revision 3071) +++ lib/libvarnish/version.c (working copy) @@ -35,6 +35,7 @@ #include +#include "config.h" #include "libvarnish.h" void Index: lib/libvarnish/vtmpfile.c =================================================================== --- lib/libvarnish/vtmpfile.c (revision 3071) +++ lib/libvarnish/vtmpfile.c (working copy) @@ -36,6 +36,7 @@ #include #include +#include "config.h" #include "libvarnish.h" int Index: lib/libvarnish/vpf.c =================================================================== --- lib/libvarnish/vpf.c (revision 3071) +++ lib/libvarnish/vpf.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include "config.h" #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif @@ -229,13 +230,15 @@ static int _vpf_remove(struct pidfh *pfh, int freeit) { + int error; +#ifndef HAVE_FLOCK struct flock lock; - int error; lock.l_type = F_UNLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; +#endif error = vpf_verify(pfh); if (error != 0) { @@ -245,7 +248,11 @@ if (unlink(pfh->pf_path) == -1) error = errno; +#ifndef HAVE_FLOCK if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { +#else + if (flock(pfh->pf_fd, LOCK_UN) == -1) { +#endif if (error == 0) error = errno; } Index: lib/libvarnishcompat/Makefile.am =================================================================== --- lib/libvarnishcompat/Makefile.am (revision 3071) +++ lib/libvarnishcompat/Makefile.am (working copy) @@ -7,6 +7,7 @@ libvarnishcompat_la_SOURCES = \ asprintf.c \ daemon.c \ + err.c \ vasprintf.c \ setproctitle.c \ srandomdev.c \ @@ -14,3 +15,4 @@ strlcpy.c \ strndup.c \ vis.c + Index: lib/libvarnishcompat/err.c =================================================================== --- lib/libvarnishcompat/err.c (revision 0) +++ lib/libvarnishcompat/err.c (revision 0) @@ -0,0 +1,109 @@ +/* $NetBSD: err.c,v 1.3 2007/08/07 02:06:58 lukem Exp $ */ + +/* + * Copyright 1997-2000 Luke Mewburn . + * All rights reserved. + * + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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 +#include +#include +#include +#include + +static const char *__getprogname() { + return +#ifdef HAVE_GETPROGNAME + getprogname() +#elif HAVE_GETEXECNAME + getexecname() +#else +#error "No progname available" +#endif + ; +} +void +err(int eval, const char *fmt, ...) +{ + va_list ap; + int sverrno; + + sverrno = errno; + (void)fprintf(stderr, "%s: ", __getprogname()); + va_start(ap, fmt); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + va_end(ap); + (void)fprintf(stderr, "%s\n", strerror(sverrno)); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + + (void)fprintf(stderr, "%s: ", __getprogname()); + va_start(ap, fmt); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); + exit(eval); +} + +void +warn(const char *fmt, ...) +{ + va_list ap; + int sverrno; + + sverrno = errno; + (void)fprintf(stderr, "%s: ", __getprogname()); + va_start(ap, fmt); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + va_end(ap); + (void)fprintf(stderr, "%s\n", strerror(sverrno)); +} + +void +warnx(const char *fmt, ...) +{ + va_list ap; + + (void)fprintf(stderr, "%s: ", __getprogname()); + va_start(ap, fmt); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); +} + Index: lib/libvarnishapi/base64.c =================================================================== --- lib/libvarnishapi/base64.c (revision 3071) +++ lib/libvarnishapi/base64.c (working copy) @@ -10,6 +10,7 @@ #include #include +#include "config.h" #include "varnishapi.h" static const char *b64 = Index: lib/libvarnishapi/instance.c =================================================================== --- lib/libvarnishapi/instance.c (revision 3071) +++ lib/libvarnishapi/instance.c (working copy) @@ -34,6 +34,7 @@ #include #include +#include "config.h" #include "varnishapi.h" int Index: lib/libvarnishapi/shmlog.c =================================================================== --- lib/libvarnishapi/shmlog.c (revision 3071) +++ lib/libvarnishapi/shmlog.c (working copy) @@ -45,6 +45,7 @@ #include #include +#include "config.h" #include "shmlog.h" #include "miniobj.h" #include "varnishapi.h" Index: lib/libvcl/vcc_xref.c =================================================================== --- lib/libvcl/vcc_xref.c (revision 3071) +++ lib/libvcl/vcc_xref.c (working copy) @@ -43,6 +43,7 @@ #include +#include "config.h" #include "vsb.h" #include "libvarnish.h" Index: lib/libvcl/vcc_string.c =================================================================== --- lib/libvcl/vcc_string.c (revision 3071) +++ lib/libvcl/vcc_string.c (working copy) @@ -34,6 +34,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "vcc_priv.h" Index: lib/libvcl/vcc_parse.c =================================================================== --- lib/libvcl/vcc_parse.c (revision 3071) +++ lib/libvcl/vcc_parse.c (working copy) @@ -34,6 +34,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "vcc_priv.h" Index: lib/libvcl/vcc_obj.c =================================================================== --- lib/libvcl/vcc_obj.c (revision 3071) +++ lib/libvcl/vcc_obj.c (working copy) @@ -8,6 +8,7 @@ #include "config.h" #include +#include "config.h" #include "vcc_compile.h" struct var vcc_vars[] = { Index: lib/libvcl/vcc_action.c =================================================================== --- lib/libvcl/vcc_action.c (revision 3071) +++ lib/libvcl/vcc_action.c (working copy) @@ -33,6 +33,7 @@ #include +#include "config.h" #include "vsb.h" #include "vcc_priv.h" Index: lib/libvcl/vcc_token.c =================================================================== --- lib/libvcl/vcc_token.c (revision 3071) +++ lib/libvcl/vcc_token.c (working copy) @@ -36,6 +36,7 @@ #include #include +#include "config.h" #include "vqueue.h" #include "vsb.h" Index: lib/libvcl/vcc_backend.c =================================================================== --- lib/libvcl/vcc_backend.c (revision 3071) +++ lib/libvcl/vcc_backend.c (working copy) @@ -60,6 +60,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "vcc_priv.h" Index: lib/libvcl/vcc_var.c =================================================================== --- lib/libvcl/vcc_var.c (revision 3071) +++ lib/libvcl/vcc_var.c (working copy) @@ -34,6 +34,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "vcc_priv.h" Index: lib/libvcl/vcc_compile.c =================================================================== --- lib/libvcl/vcc_compile.c (revision 3071) +++ lib/libvcl/vcc_compile.c (working copy) @@ -73,6 +73,7 @@ #include #include +#include "config.h" #include "vqueue.h" #include "vsb.h" Index: lib/libvcl/Makefile.am =================================================================== --- lib/libvcl/Makefile.am (revision 3071) +++ lib/libvcl/Makefile.am (working copy) @@ -22,3 +22,4 @@ vcc_token.c \ vcc_var.c \ vcc_xref.c + Index: lib/libvcl/vcc_fixed_token.c =================================================================== --- lib/libvcl/vcc_fixed_token.c (revision 3071) +++ lib/libvcl/vcc_fixed_token.c (working copy) @@ -9,6 +9,7 @@ #include "config.h" #include #include +#include "config.h" #include "vcc_priv.h" #include "vsb.h" Index: lib/libvcl/vcc_acl.c =================================================================== --- lib/libvcl/vcc_acl.c (revision 3071) +++ lib/libvcl/vcc_acl.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include "config.h" #include "vsb.h" #include "vrt.h" Index: bin/varnishncsa/varnishncsa.c =================================================================== --- bin/varnishncsa/varnishncsa.c (revision 3071) +++ bin/varnishncsa/varnishncsa.c (working copy) @@ -71,6 +71,7 @@ #include #include +#include "config.h" #ifndef HAVE_DAEMON #include "compat/daemon.h" #endif Index: bin/varnishhist/varnishhist.c =================================================================== --- bin/varnishhist/varnishhist.c (revision 3071) +++ bin/varnishhist/varnishhist.c (working copy) @@ -46,6 +46,7 @@ #include #include +#include "config.h" #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" Index: bin/varnishstat/varnishstat.c =================================================================== --- bin/varnishstat/varnishstat.c (revision 3071) +++ bin/varnishstat/varnishstat.c (working copy) @@ -46,6 +46,7 @@ #include #include +#include "config.h" #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" Index: bin/varnishreplay/varnishreplay.c =================================================================== --- bin/varnishreplay/varnishreplay.c (revision 3071) +++ bin/varnishreplay/varnishreplay.c (working copy) @@ -43,6 +43,7 @@ #include #include +#include "config.h" #include "vqueue.h" #include "libvarnish.h" Index: bin/varnishtest/vtc.c =================================================================== --- bin/varnishtest/vtc.c (revision 3071) +++ bin/varnishtest/vtc.c (working copy) @@ -32,7 +32,10 @@ #include #include #include +#ifdef HAVE_ERR_H #include +#endif +#include "compat/err.h" #include "libvarnish.h" #include "vsb.h" Index: bin/varnishtest/vtc_log.c =================================================================== --- bin/varnishtest/vtc_log.c (revision 3071) +++ bin/varnishtest/vtc_log.c (working copy) @@ -32,7 +32,10 @@ #include #include #include +#ifdef HAVE_ERR_H #include +#endif +#include "compat/err.h" #include #include Index: bin/varnishadm/varnishadm.c =================================================================== --- bin/varnishadm/varnishadm.c (revision 3071) +++ bin/varnishadm/varnishadm.c (working copy) @@ -36,6 +36,7 @@ #include #include +#include "config.h" #include "libvarnish.h" #include "vss.h" Index: bin/varnishlog/varnishlog.c =================================================================== --- bin/varnishlog/varnishlog.c (revision 3071) +++ bin/varnishlog/varnishlog.c (working copy) @@ -43,6 +43,7 @@ #include #include +#include "config.h" #ifndef HAVE_DAEMON #include "compat/daemon.h" #endif Index: bin/varnishtop/varnishtop.c =================================================================== --- bin/varnishtop/varnishtop.c (revision 3071) +++ bin/varnishtop/varnishtop.c (working copy) @@ -45,6 +45,7 @@ #include #include +#include "config.h" #include "vqueue.h" #include "vsb.h" Index: bin/varnishd/storage_file.c =================================================================== --- bin/varnishd/storage_file.c (revision 3071) +++ bin/varnishd/storage_file.c (working copy) @@ -38,6 +38,7 @@ #include #include +#include "config.h" #ifdef HAVE_SYS_MOUNT_H #include #endif @@ -50,6 +51,11 @@ #include #endif +#ifdef HAVE_SYS_STATVFS_H +#include +#include +#endif + #include #include #include Index: bin/varnishd/mgt_param.c =================================================================== --- bin/varnishd/mgt_param.c (revision 3071) +++ bin/varnishd/mgt_param.c (working copy) @@ -43,6 +43,7 @@ #include #include +#include "config.h" #include "cli.h" #include "cli_priv.h" #include "cli_common.h" @@ -704,13 +705,7 @@ "the string will be replaced with the source file name, " "and %o will be replaced with the output file name.", MUST_RELOAD, -#ifdef __APPLE__ - "exec cc -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s" -#elif defined(__SOLARIS__) - "exec cc -shared -fpic -c %o %s" -#else /* default: GCC on Linux & FreeBSD */ - "exec cc -fpic -shared -Wl,-x -o %o %s" -#endif + VCC_CC , NULL }, { "max_restarts", tweak_uint, &master.max_restarts, 0, UINT_MAX, "Upper limit on how many times a request can restart." Index: bin/varnishd/mgt_vcc.c =================================================================== --- bin/varnishd/mgt_vcc.c (revision 3071) +++ bin/varnishd/mgt_vcc.c (working copy) @@ -43,6 +43,7 @@ #include #include +#include "config.h" #ifndef HAVE_ASPRINTF #include "compat/asprintf.h" #endif @@ -166,10 +167,12 @@ AZ(close(sfd)); /* Name the output shared library by overwriting the final 'c' */ - of = strdup(sf); + of = malloc(strlen(sf)+2); /* hold .so and \0 */ + strlcpy(of, sf, strlen(sf)+1); XXXAN(of); - assert(of[sizeof sf - 2] == 'c'); - of[sizeof sf - 2] = 'o'; + of[sizeof sf - 2] = 's'; + of[sizeof sf - 1] = 'o'; + of[sizeof sf] = '\0'; AN(vsb_new(&cmdsb, cmdline, sizeof cmdline, 0)); mgt_make_cc_cmd(&cmdsb, sf, of); vsb_finish(&cmdsb); @@ -220,7 +223,7 @@ return (NULL); } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - vsb_printf(sb, "%s(): Compiler failed", __func__); + vsb_printf(sb, "%s(): Compiler '%s' failed", __func__, cmdline); if (WIFEXITED(status)) vsb_printf(sb, ", exit %d", WEXITSTATUS(status)); if (WIFSIGNALED(status)) Index: bin/varnishd/cache_panic.c =================================================================== --- bin/varnishd/cache_panic.c (revision 3071) +++ bin/varnishd/cache_panic.c (working copy) @@ -37,6 +37,7 @@ #include #include +#include "config.h" #include "cache.h" #include "cache_backend.h" #include "vcl.h" Index: bin/varnishd/tcp.c =================================================================== --- bin/varnishd/tcp.c (revision 3071) +++ bin/varnishd/tcp.c (working copy) @@ -36,8 +36,12 @@ #include +#include #include #include +#ifdef HAVE_SYS_FILIO_H +#include +#endif #include #include #include @@ -45,6 +49,7 @@ #include #include +#include "config.h" #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif Index: bin/varnishd/cache_http.c =================================================================== --- bin/varnishd/cache_http.c (revision 3071) +++ bin/varnishd/cache_http.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include "config.h" #include "shmlog.h" #include "vct.h" #include "cache.h" Index: bin/varnishd/cache_center.c =================================================================== --- bin/varnishd/cache_center.c (revision 3071) +++ bin/varnishd/cache_center.c (working copy) @@ -67,6 +67,7 @@ #include #include +#include "config.h" #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif Index: bin/varnishd/cache_acceptor_ports.c =================================================================== --- bin/varnishd/cache_acceptor_ports.c (revision 0) +++ bin/varnishd/cache_acceptor_ports.c (revision 0) @@ -0,0 +1,159 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * Copyright (c) 2007 OmniTI Computer Consulting, Inc. + * Copyright (c) 2007 Theo Schlossnagle + * All rights reserved. + * + * 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 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. + * + * $Id$ + * + * XXX: We need to pass sessions back into the event engine when they are + * reused. Not sure what the most efficient way is for that. For now + * write the session pointer to a pipe which the event engine monitors. + */ + +#include "config.h" +#if defined(HAVE_PORT_CREATE) + +#include +#include +#include +#include +#include + +#include + +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + +#include "shmlog.h" +#include "cache.h" +#include "cache_acceptor.h" + +#define MAX_EVENTS 256 +static pthread_t vca_ports_thread; +int solaris_dport = -1; + +static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); + +static void +vca_add(int fd, void *data) +{ + AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, POLLIN | POLLERR | POLLPRI, data)); +} + +static void +vca_del(int fd) +{ + port_dissociate(solaris_dport, PORT_SOURCE_FD, fd); +} + +static void +vca_port_ev(port_event_t *ev) { + struct sess *sp; + if(ev->portev_source == PORT_SOURCE_USER) { + sp = ev->portev_user; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + assert(sp->fd >= 0); + AZ(sp->obj); + VTAILQ_INSERT_TAIL(&sesshead, sp, list); + vca_add(sp->fd, sp); + } else { + int i; + CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC); + if(ev->portev_events & POLLERR) { + VTAILQ_REMOVE(&sesshead, sp, list); + vca_close_session(sp, "EOF"); + SES_Delete(sp); + return; + } + i = HTC_Rx(sp->htc); + if (i == 0) + return; + if (i > 0) { + VTAILQ_REMOVE(&sesshead, sp, list); + if (sp->fd != -1) + vca_del(sp->fd); + vca_handover(sp, i); + } + } + return; +} + +static void * +vca_main(void *arg) +{ + struct sess *sp; + + (void)arg; + + solaris_dport = port_create(); + assert(solaris_dport >= 0); + + while (1) { + port_event_t ev[MAX_EVENTS]; + int nevents, ei; + double deadline; + struct timespec ts; + ts.tv_sec = 0L; + ts.tv_nsec = 50L /*ms*/ * 1000L /*us*/ * 1000L /*ns*/; + nevents = 1; + if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts) == 0) { + for (ei=0; eisess_timeout; + for (;;) { + sp = VTAILQ_FIRST(&sesshead); + if (sp == NULL) + break; + if (sp->t_open > deadline) + break; + VTAILQ_REMOVE(&sesshead, sp, list); + if(sp->fd != -1) + vca_del(sp->fd); + vca_close_session(sp, "timeout"); + SES_Delete(sp); + } + } +} + +/*--------------------------------------------------------------------*/ + +static void +vca_ports_init(void) +{ + + AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL)); +} + +struct acceptor acceptor_ports = { + .name = "ports", + .init = vca_ports_init +}; + +#endif /* defined(HAVE_PORT_CREATE) */ Index: bin/varnishd/varnishd.c =================================================================== --- bin/varnishd/varnishd.c (revision 3071) +++ bin/varnishd/varnishd.c (working copy) @@ -113,10 +113,16 @@ /*--------------------------------------------------------------------*/ extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; +#ifdef HAVE_LIBUMEM +extern struct stevedore smu_stevedore; +#endif static struct choice stv_choice[] = { { "file", &smf_stevedore }, { "malloc", &sma_stevedore }, +#ifdef HAVE_LIBUMEM + { "umem", &smu_stevedore }, +#endif { NULL, NULL } }; @@ -214,6 +220,9 @@ fprintf(stderr, FMT, "-s kind[,storageoptions]", "Backend storage specification"); fprintf(stderr, FMT, "", " -s malloc"); +#ifdef HAVE_LIBUMEM + fprintf(stderr, FMT, "", " -s umem"); +#endif fprintf(stderr, FMT, "", " -s file [default: use /tmp]"); fprintf(stderr, FMT, "", " -s file,"); fprintf(stderr, FMT, "", " -s file,,"); Index: bin/varnishd/storage_umem.c =================================================================== --- bin/varnishd/storage_umem.c (revision 2328) +++ bin/varnishd/storage_umem.c (working copy) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS + * Copyright (c) 2006-2008 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -28,75 +28,145 @@ * * $Id$ * - * Storage method based on malloc(3) + * Storage method based on umem_alloc(3MALLOC) */ +#include "config.h" + #include +#include #include +#include +#ifdef HAVE_UMEM_H +#include + +#include "config.h" #include "shmlog.h" #include "cache.h" #include "stevedore.h" -struct sma { +static size_t smu_max = SIZE_MAX; +static MTX smu_mtx; + +struct smu { struct storage s; + size_t sz; }; static struct storage * -sma_alloc(struct stevedore *st, size_t size) +smu_alloc(struct stevedore *st, size_t size) { - struct sma *sma; + struct smu *smu; - VSL_stats->sm_nreq++; - sma = calloc(sizeof *sma, 1); - if (sma == NULL) + LOCK(&smu_mtx); + VSL_stats->sma_nreq++; + if (VSL_stats->sma_nbytes + size > smu_max) + size = 0; + else { + VSL_stats->sma_nobj++; + VSL_stats->sma_nbytes += size; + VSL_stats->sma_balloc += size; + } + UNLOCK(&smu_mtx); + + if (size == 0) return (NULL); - sma->s.priv = sma; - sma->s.ptr = malloc(size); - XXXAN(sma->s.ptr); - sma->s.len = 0; - sma->s.space = size; - sma->s.fd = -1; - sma->s.stevedore = st; - sma->s.magic = STORAGE_MAGIC; - VSL_stats->sm_nobj++; - VSL_stats->sm_balloc += sma->s.space; - return (&sma->s); + + smu = umem_zalloc(sizeof *smu, UMEM_DEFAULT); + if (smu == NULL) + return (NULL); + smu->sz = size; + smu->s.priv = smu; + smu->s.ptr = umem_alloc(size, UMEM_DEFAULT); + XXXAN(smu->s.ptr); + smu->s.len = 0; + smu->s.space = size; + smu->s.fd = -1; + smu->s.stevedore = st; + smu->s.magic = STORAGE_MAGIC; + return (&smu->s); } +/*lint -e{818} not const-able */ static void -sma_free(const struct storage *s) +smu_free(struct storage *s) { - struct sma *sma; + struct smu *smu; CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); - sma = s->priv; - VSL_stats->sm_nobj--; - VSL_stats->sm_balloc -= sma->s.space; - free(sma->s.ptr); - free(sma); + smu = s->priv; + assert(smu->sz == smu->s.space); + LOCK(&smu_mtx); + VSL_stats->sma_nobj--; + VSL_stats->sma_nbytes -= smu->sz; + VSL_stats->sma_bfree += smu->sz; + UNLOCK(&smu_mtx); + umem_free(smu->s.ptr, smu->s.space); + umem_free(smu, sizeof *smu); } static void -sma_trim(const struct storage *s, size_t size) +smu_trim(const struct storage *s, size_t size) { - struct sma *sma; + struct smu *smu; void *p; CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); - sma = s->priv; - if ((p = realloc(sma->s.ptr, size)) != NULL) { - VSL_stats->sm_balloc -= sma->s.space; - sma->s.ptr = p; - sma->s.space = size; - VSL_stats->sm_balloc += sma->s.space; + smu = s->priv; + assert(smu->sz == smu->s.space); + if ((p = umem_alloc(size, UMEM_DEFAULT)) != NULL) { + memcpy(p, smu->s.ptr, size); + umem_free(smu->s.ptr, smu->s.space); + LOCK(&smu_mtx); + VSL_stats->sma_nbytes -= (smu->sz - size); + VSL_stats->sma_bfree += smu->sz - size; + smu->sz = size; + UNLOCK(&smu_mtx); + smu->s.ptr = p; + smu->s.space = size; } } -struct stevedore sma_stevedore = { - .name = "malloc", - .alloc = sma_alloc, - .free = sma_free, - .trim = sma_trim, +static void +smu_init(struct stevedore *parent, int ac, char * const *av) +{ + const char *e; + uintmax_t u; + + (void)parent; + + AZ(av[ac]); + if (ac > 1) + ARGV_ERR("(-sumem) too many arguments\n"); + + if (ac == 0 || *av[0] == '\0') + return; + + e = str2bytes(av[0], &u, 0); + if (e != NULL) + ARGV_ERR("(-sumem) size \"%s\": %s\n", av[0], e); + if ((u != (uintmax_t)(size_t)u)) + ARGV_ERR("(-sumem) size \"%s\": too big\n", av[0]); + smu_max = u; +} + +static void +smu_open(const struct stevedore *st) +{ + (void)st; + AZ(pthread_mutex_init(&smu_mtx, NULL)); +} + +struct stevedore smu_stevedore = { + .magic = STEVEDORE_MAGIC, + .name = "umem", + .init = smu_init, + .open = smu_open, + .alloc = smu_alloc, + .free = smu_free, + .trim = smu_trim, }; + +#endif Index: bin/varnishd/cache_pool.c =================================================================== --- bin/varnishd/cache_pool.c (revision 3071) +++ bin/varnishd/cache_pool.c (working copy) @@ -52,6 +52,8 @@ #include #elif defined(__linux__) #include +#elif defined(__sun) +#include #else #error Unknown sendfile() implementation #endif @@ -191,7 +193,38 @@ sendfile(*w->wfd, fd, &off, len) != len) w->werr++; } while (0); +#elif defined(__sun) +#ifdef HAVE_SENDFILEV + do { + sendfilevec_t svvec[HTTP_HDR_MAX * 2 + 1]; + size_t xferred = 0, expected = 0; + int i; + for (i = 0; i < w->niov; i++) { + svvec[i].sfv_fd = SFV_FD_SELF; + svvec[i].sfv_flag = 0; + svvec[i].sfv_off = (off_t) w->iov[i].iov_base; + svvec[i].sfv_len = w->iov[i].iov_len; + expected += svvec[i].sfv_len; + } + svvec[i].sfv_fd = fd; + svvec[i].sfv_flag = 0; + svvec[i].sfv_off = off; + svvec[i].sfv_len = len; + expected += svvec[i].sfv_len; + if (sendfilev(*w->wfd, svvec, i, &xferred) == -1 || + xferred != expected) + w->werr++; + w->liov = 0; + w->niov = 0; + } while (0); #else + do { + if (WRK_Flush(w) == 0 && + sendfile(*w->wfd, fd, &off, len) != len) + w->werr++; + } while (0); +#endif +#else #error Unknown sendfile() implementation #endif } Index: bin/varnishd/cache.h =================================================================== --- bin/varnishd/cache.h (revision 3071) +++ bin/varnishd/cache.h (working copy) @@ -29,6 +29,7 @@ * $Id$ */ +#include #include #include #include @@ -73,6 +74,14 @@ # define MAX_IOVS (HTTP_HDR_MAX_VAL * 2) #endif +#ifndef NAN +#include +#define NAN FP_QNAN +#endif + +/* Amount of per-worker logspace */ +#define WLOGSPACE 8192 + struct cli; struct vsb; struct sess; @@ -658,6 +667,11 @@ #define ALOCKED(mutex) AN(pthread_mutex_isowned_np((mutex))) #elif defined(DIAGNOSTICS) #define ALOCKED(mutex) AN(pthread_mutex_trylock((mutex))) +#define SEM sem_t +#define SEM_INIT(foo,i) sem_init(foo,0,i) +#define SEM_WAIT(foo) sem_wait(foo) +#define SEM_POST(foo) sem_post(foo) +#define SEM_DESTROY(foo) sem_destroy(foo) #else #define ALOCKED(mutex) (void)(mutex) #endif Index: bin/varnishd/mgt_cli.c =================================================================== --- bin/varnishd/mgt_cli.c (revision 3071) +++ bin/varnishd/mgt_cli.c (working copy) @@ -45,6 +45,7 @@ #include #include +#include "config.h" #ifndef HAVE_VASPRINTF #include "compat/vasprintf.h" #endif Index: bin/varnishd/cache_acceptor.c =================================================================== --- bin/varnishd/cache_acceptor.c (revision 3071) +++ bin/varnishd/cache_acceptor.c (working copy) @@ -46,6 +46,10 @@ #include #include +#include "config.h" +#ifndef HAVE_SRANDOMDEV +#include "compat/srandomdev.h" +#endif #include "cli.h" #include "cli_priv.h" #include "shmlog.h" @@ -59,6 +63,9 @@ #if defined(HAVE_EPOLL_CTL) &acceptor_epoll, #endif +#if defined(HAVE_PORT_CREATE) + &acceptor_ports, +#endif #if defined(HAVE_POLL) &acceptor_poll, #endif @@ -288,6 +295,11 @@ AZ(sp->obj); AZ(sp->vcl); assert(sp->fd >= 0); +#ifdef HAVE_PORT_CREATE + extern int solaris_dport; + port_send(solaris_dport, 0, sp); +#else + assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp)); /* * Set nonblocking in the worker-thread, before passing to the * acceptor thread, to reduce syscall density of the latter. @@ -297,6 +309,7 @@ assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp)); else vca_act->pass(sp); +#endif } Index: bin/varnishd/Makefile.am =================================================================== --- bin/varnishd/Makefile.am (revision 3071) +++ bin/varnishd/Makefile.am (working copy) @@ -11,6 +11,7 @@ cache_acceptor_epoll.c \ cache_acceptor_poll.c \ cache_acceptor_kqueue.c \ + cache_acceptor_ports.c \ cache_backend.c \ cache_backend_cfg.c \ cache_backend_poll.c \ @@ -49,6 +50,7 @@ shmlog.c \ stevedore.c \ storage_file.c \ + storage_umem.c \ storage_malloc.c \ storage_synth.c \ tcp.c \ Index: bin/varnishd/cache_acceptor.h =================================================================== --- bin/varnishd/cache_acceptor.h (revision 3071) +++ bin/varnishd/cache_acceptor.h (working copy) @@ -48,6 +48,10 @@ extern struct acceptor acceptor_kqueue; #endif +#if defined(HAVE_PORT_CREATE) +extern struct acceptor acceptor_ports; +#endif + #if defined(HAVE_POLL) extern struct acceptor acceptor_poll; #endif Index: bin/varnishd/mgt_child.c =================================================================== --- bin/varnishd/mgt_child.c (revision 3071) +++ bin/varnishd/mgt_child.c (working copy) @@ -45,6 +45,7 @@ #include #include +#include "config.h" #ifndef HAVE_SETPROCTITLE #include "compat/setproctitle.h" #endif @@ -230,9 +231,10 @@ { pid_t pid; unsigned u; + int i = -1; char *p; struct vev *e; - int i, cp[2]; + int cp[2]; if (child_state != CH_STOPPED && child_state != CH_DIED) return;