Commit bdd2e1cb authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Merged revisions 1394,1400-1418 via svnmerge from

svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r1394 | phk | 2007-05-09 12:55:33 +0200 (Wed, 09 May 2007) | 8 lines
  
  After compilation of a VCL program, do a test-load into the management
  process to catch any implementation-discrepancies between symbols used
  by the compiler and those implemented in the runtime.
  
  The situation will happen from time to time and there is no need to
  issue a panic when we can test sensibly for it.
........
  r1403 | ingvar | 2007-05-11 09:51:11 +0200 (Fri, 11 May 2007) | 5 lines
  
  * Fri May 11 2007 Ingvar Hagelund <ingvar@linpro.no> - 1.0.svn-20070511
  - Threw latest changes into svn trunk
  - Removed the conversion of manpages into utf8. They are all utf8 in trunk
........
  r1404 | ingvar | 2007-05-11 10:13:03 +0200 (Fri, 11 May 2007) | 1 line
........
  r1406 | des | 2007-05-11 13:06:03 +0200 (Fri, 11 May 2007) | 2 lines
  
  Comment out comparisons which are always true (unsigned >= 0)
........
  r1407 | des | 2007-05-11 13:06:38 +0200 (Fri, 11 May 2007) | 2 lines
  
  Tweak DEVELOPER_CFLAGS.
........
  r1408 | des | 2007-05-11 13:14:32 +0200 (Fri, 11 May 2007) | 2 lines
  
  Pull flopen() and pidfile_*() (renamed to vpf_*()) from FreeBSD.
........
  r1409 | des | 2007-05-11 13:15:46 +0200 (Fri, 11 May 2007) | 2 lines
  
  Expand tags.
........
  r1410 | des | 2007-05-11 13:17:09 +0200 (Fri, 11 May 2007) | 2 lines
  
  No use expanding tags unless there *are* tags...
........
  r1411 | des | 2007-05-11 13:34:42 +0200 (Fri, 11 May 2007) | 2 lines
  
  Add -D (daemonize) and -P (pid file) options.
........
  r1412 | des | 2007-05-11 13:35:59 +0200 (Fri, 11 May 2007) | 2 lines
  
  Remove unused header.
........
  r1413 | des | 2007-05-11 14:01:47 +0200 (Fri, 11 May 2007) | 2 lines
  
  Avoid gcc4-specific compiler options.
........
  r1414 | des | 2007-05-11 14:05:02 +0200 (Fri, 11 May 2007) | 2 lines
  
  Forgotten commit: check for <vis.h> and daemon(3) availability.
........
  r1415 | des | 2007-05-11 14:17:26 +0200 (Fri, 11 May 2007) | 2 lines
  
  Add -P (pid file) option.
........
  r1416 | des | 2007-05-11 14:19:48 +0200 (Fri, 11 May 2007) | 2 lines
  
  Minor style issues.
........
  r1417 | phk | 2007-05-11 15:15:16 +0200 (Fri, 11 May 2007) | 7 lines
  
  Make the sendfile threshold inifinity for now, we have evidence of
  sendfile not doing it's job in a number of operating system (-versions ?)
  
  This change is unlikely to cause a performance hit anywhere, because
  writev() is pretty effective in the first place.
........
  r1418 | des | 2007-05-14 11:02:23 +0200 (Mon, 14 May 2007) | 2 lines
  
  Document the inadvisability of enabling sendfile.
........


git-svn-id: http://www.varnish-cache.org/svn/branches/1.0@1419 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent a20b97dc
......@@ -81,8 +81,8 @@ http2shmlog(struct http *hp, enum httptag t)
{
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
assert(hp->logtag >= HTTP_Rx && hp->logtag <= HTTP_Obj);
assert(t >= HTTP_T_Request && t <= HTTP_T_LostHeader);
assert(/* hp->logtag >= HTTP_Rx && */hp->logtag <= HTTP_Obj);
assert(/* t >= HTTP_T_Request && */t <= HTTP_T_LostHeader);
return (logmtx[hp->logtag][t]);
}
......
......@@ -529,7 +529,7 @@ static struct parspec parspec[] = {
"may make sense to set this to \"unlimited\".\n"
#endif
EXPERIMENTAL,
"8192", "bytes" },
"-1", "bytes" },
#endif /* HAVE_SENDFILE */
{ "vcl_trace", tweak_vcl_trace,
"Trace VCL execution in the shmlog.\n"
......
......@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -59,7 +60,6 @@ struct vclprog {
int active;
};
static TAILQ_HEAD(, vclprog) vclhead = TAILQ_HEAD_INITIALIZER(vclhead);
/*--------------------------------------------------------------------*/
......@@ -129,6 +129,7 @@ mgt_CallCc(const char *source, struct vsb *sb)
FILE *fo, *fs;
char *of, *sf, buf[BUFSIZ];
int i, j, sfd;
void *p;
/* Create temporary C source file */
sf = strdup("/tmp/vcl.XXXXXXXX");
......@@ -201,6 +202,17 @@ mgt_CallCc(const char *source, struct vsb *sb)
of = NULL;
}
/* Next, try to load the object into the management process */
p = dlopen(of, RTLD_NOW | RTLD_LOCAL);
if (p == NULL) {
vsb_printf(sb, "Problem loading compiled VCL program:\n\t%s\n",
dlerror());
unlink(of);
free(of);
of = NULL;
} else
AZ(dlclose(p));
/* clean up and return */
unlink(sf);
free(sf);
......
......@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
.Dd May 1, 2007
.Dd May 14, 2007
.Dt VARNISHD 1
.Os
.Sh NAME
......@@ -41,6 +41,7 @@
.Op Fl d
.Op Fl f Ar config
.Op Fl h Ar type Ns Op , Ns Ar options
.Op Fl P Ar file
.Op Fl p Ar param Ns = Ns Ar value
.Op Fl s Ar type Ns Op , Ns Ar options
.Op Fl T Ar address Ns Op : Ns Ar port
......@@ -111,6 +112,9 @@ Specifies the hash algorithm.
See
.Sx Hash Algorithms
for a list of supported algorithms.
.It Fl P Ar file
Write the process's PID to the specified
.Ar file .
.It Fl p Ar param Ns = Ns Ar value
Set the parameter specified by
.Ar param
......@@ -368,7 +372,10 @@ instead of
This is not likely to have any effect unless the working set is too
large to fit in physical memory.
.Pp
The default is 8192 bytes, which is probably too low.
Note that several operating systems have known bugs which make it
inadvisable to use this.
.Pp
The default is -1, which disables the use of sendfile altogether.
.It Va send_timeout
The time to wait before dropping the connection to a client which is
not accepting data sent to it.
......
......@@ -45,7 +45,12 @@
#include <time.h>
#include <unistd.h>
#ifndef HAVE_DAEMON
#include "compat/daemon.h"
#endif
#include "vsb.h"
#include "vpf.h"
#include "cli.h"
#include "cli_priv.h"
......@@ -163,7 +168,7 @@ usage(void)
fprintf(stderr, " %-28s # %s\n", "",
" -b '<hostname_or_IP>:<port_or_service>'");
fprintf(stderr, " %-28s # %s\n", "-d", "debug");
fprintf(stderr, " %-28s # %s\n", "-f file", "VCL_file");
fprintf(stderr, " %-28s # %s\n", "-f file", "VCL script");
fprintf(stderr, " %-28s # %s\n",
"-h kind[,hashoptions]", "Hash specification");
fprintf(stderr, " %-28s # %s\n", "",
......@@ -172,6 +177,7 @@ usage(void)
" -h classic [default]");
fprintf(stderr, " %-28s # %s\n", "",
" -h classic,<buckets>");
fprintf(stderr, " %-28s # %s\n", "-P file", "PID file");
fprintf(stderr, " %-28s # %s\n", "-p param=value",
"set parameter");
fprintf(stderr, " %-28s # %s\n",
......@@ -396,12 +402,14 @@ main(int argc, char *argv[])
const char *b_arg = NULL;
const char *f_arg = NULL;
const char *h_flag = "classic";
const char *P_arg = NULL;
const char *s_arg = "file";
const char *T_arg = NULL;
unsigned C_flag = 0;
char *p;
struct params param;
struct cli cli[1];
struct pidfh *pfh = NULL;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
......@@ -420,8 +428,8 @@ main(int argc, char *argv[])
* XXX: block in shared memory. It would give us the advantage
* XXX: of having the CLI thread be able to take action on the
* XXX: change.
* XXX: For now live with the harmless flexelint warning this causes:
* XXX: varnishd.c 393 Info 789: Assigning address of auto variable
* XXX: For now live with the harmless flexelint warning this causes:
* XXX: varnishd.c 393 Info 789: Assigning address of auto variable
* XXX: 'param' to static
*/
......@@ -433,7 +441,7 @@ main(int argc, char *argv[])
MCF_ParamInit(cli);
cli_check(cli);
while ((o = getopt(argc, argv, "a:b:Cdf:h:p:s:T:t:Vw:")) != -1)
while ((o = getopt(argc, argv, "a:b:Cdf:h:P:p:s:T:t:Vw:")) != -1)
switch (o) {
case 'a':
MCF_ParamSet(cli, "listen_address", optarg);
......@@ -454,6 +462,9 @@ main(int argc, char *argv[])
case 'h':
h_flag = optarg;
break;
case 'P':
P_arg = optarg;
break;
case 'p':
p = strchr(optarg, '=');
if (p == NULL)
......@@ -499,6 +510,11 @@ main(int argc, char *argv[])
usage();
}
if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
perror(P_arg);
exit(1);
}
if (mgt_vcc_default(b_arg, f_arg, C_flag))
exit (2);
if (C_flag)
......@@ -516,9 +532,14 @@ main(int argc, char *argv[])
if (d_flag == 1)
printf("%d\n", getpid());
if (pfh != NULL)
vpf_write(pfh);
mgt_cli_init();
mgt_run(d_flag, T_arg);
if (pfh != NULL)
vpf_remove(pfh);
exit(0);
}
......@@ -41,8 +41,6 @@
#include <string.h>
#include <unistd.h>
#include "compat/vis.h"
#include "libvarnish.h"
#include "shmlog.h"
#include "varnishapi.h"
......@@ -226,5 +224,5 @@ main(int argc, char **argv)
break;
}
return (0);
exit(0);
}
......@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
.Dd April 21, 2007
.Dd May 11, 2007
.Dt VARNISHLOG 1
.Os
.Sh NAME
......@@ -40,10 +40,12 @@
.Op Fl b
.Op Fl C
.Op Fl c
.Op Fl D
.Op Fl d
.Op Fl I Ar regex
.Op Fl i Ar tag
.Op Fl o
.Op Fl P Ar file
.Op Fl r Ar file
.Op Fl V
.Op Fl w Ar file
......@@ -82,6 +84,8 @@ nor
is specified,
.Nm
acts as if they both were.
.It Fl D
Daemonize.
.It Fl d
Process old log entries on startup.
Normally,
......@@ -107,6 +111,9 @@ Group log entries by request ID.
This has no effect when writing to a file using the
.Fl w
option.
.It Fl P Ar file
Write the process's PID to the specified
.Ar file .
.It Fl r Ar file
Read log entries from
.Ar file
......
......@@ -40,15 +40,24 @@
#include <string.h>
#include <unistd.h>
#ifndef HAVE_DAEMON
#include "compat/daemon.h"
#endif
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "compat/vis.h"
#endif
#include "vsb.h"
#include "vpf.h"
#include "libvarnish.h"
#include "shmlog.h"
#include "varnishapi.h"
static int bflag, cflag;
static int b_flag, c_flag;
/* -------------------------------------------------------------------*/
......@@ -100,7 +109,7 @@ h_order(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec
(void)priv;
if (!(spec & (VSL_S_CLIENT|VSL_S_BACKEND))) {
if (!bflag && !cflag)
if (!b_flag && !c_flag)
VSL_H_Print(stdout, tag, fd, len, spec, ptr);
return (0);
}
......@@ -179,12 +188,12 @@ do_order(struct VSL_data *vd, int argc, char **argv)
exit (2);
}
}
if (!bflag) {
if (!b_flag) {
VSL_Select(vd, SLT_SessionOpen);
VSL_Select(vd, SLT_SessionClose);
VSL_Select(vd, SLT_ReqEnd);
}
if (!cflag) {
if (!c_flag) {
VSL_Select(vd, SLT_BackendOpen);
VSL_Select(vd, SLT_BackendClose);
VSL_Select(vd, SLT_BackendReuse);
......@@ -214,29 +223,29 @@ sighup(int sig)
}
static int
open_log(const char *w_opt, int a_flag)
open_log(const char *w_arg, int a_flag)
{
int fd, flags;
flags = (a_flag ? O_APPEND : O_TRUNC) | O_WRONLY | O_CREAT;
if (!strcmp(w_opt, "-"))
if (!strcmp(w_arg, "-"))
fd = STDOUT_FILENO;
else
fd = open(w_opt, flags, 0644);
fd = open(w_arg, flags, 0644);
if (fd < 0) {
perror(w_opt);
perror(w_arg);
exit (1);
}
return (fd);
}
static void
do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
do_write(struct VSL_data *vd, const char *w_arg, int a_flag)
{
int fd, i;
unsigned char *p;
fd = open_log(w_opt, a_flag);
fd = open_log(w_arg, a_flag);
signal(SIGHUP, sighup);
while (1) {
i = VSL_NextLog(vd, &p);
......@@ -245,13 +254,13 @@ do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
if (i > 0) {
i = write(fd, p, 5 + p[1]);
if (i < 0) {
perror(w_opt);
perror(w_arg);
exit(1);
}
}
if (reopen) {
close(fd);
fd = open_log(w_opt, a_flag);
fd = open_log(w_arg, a_flag);
reopen = 0;
}
}
......@@ -264,7 +273,7 @@ static void
usage(void)
{
fprintf(stderr,
"usage: varnishlog %s [-aoV] [-w file]\n", VSL_USAGE);
"usage: varnishlog %s [-aDoV] [-P file] [-w file]\n", VSL_USAGE);
exit(1);
}
......@@ -272,33 +281,41 @@ int
main(int argc, char **argv)
{
int i, c;
int a_flag = 0, o_flag = 0;
char *w_opt = NULL;
int a_flag = 0, D_flag = 0, o_flag = 0;
const char *P_arg = NULL;
const char *w_arg = NULL;
struct pidfh *pfh = NULL;
struct VSL_data *vd;
vd = VSL_New();
while ((c = getopt(argc, argv, VSL_ARGS "aoVw:")) != -1) {
while ((c = getopt(argc, argv, VSL_ARGS "aDoP:Vw:")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
break;
case 'D':
D_flag = 1;
break;
case 'o':
o_flag = 1;
break;
case 'P':
P_arg = optarg;
break;
case 'V':
varnish_version("varnishlog");
exit(0);
case 'w':
w_opt = optarg;
w_arg = optarg;
break;
case 'c':
cflag = 1;
c_flag = 1;
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
case 'b':
bflag = 1;
b_flag = 1;
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
......@@ -309,14 +326,29 @@ main(int argc, char **argv)
}
}
if (o_flag && w_opt != NULL)
if (o_flag && w_arg != NULL)
usage();
if (VSL_OpenLog(vd))
exit (1);
exit(1);
if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
perror(P_arg);
exit(1);
}
if (D_flag && daemon(0, 0) == -1) {
perror("daemon()");
if (pfh != NULL)
vpf_remove(pfh);
exit(1);
}
if (w_opt != NULL)
do_write(vd, w_opt, a_flag);
if (pfh != NULL)
vpf_write(pfh);
if (w_arg != NULL)
do_write(vd, w_arg, a_flag);
if (o_flag)
do_order(vd, argc - optind, argv + optind);
......@@ -329,5 +361,7 @@ main(int argc, char **argv)
break;
}
return (0);
if (pfh != NULL)
vpf_remove(pfh);
exit(0);
}
......@@ -169,6 +169,5 @@ main(int argc, char **argv)
#undef MAC_STAT
}
exit (0);
exit(0);
}
......@@ -39,8 +39,6 @@
#include <string.h>
#include <unistd.h>
#include "compat/vis.h"
#include "vsb.h"
#include "libvarnish.h"
......
......@@ -60,6 +60,7 @@ AC_CHECK_HEADERS([netinet/in.h])
AC_CHECK_HEADERS([stddef.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([vis.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
......@@ -88,6 +89,7 @@ AC_CHECK_FUNCS([srandomdev])
AC_CHECK_FUNCS([strlcat strlcpy])
AC_CHECK_FUNCS([strndup])
AC_CHECK_FUNCS([vis strvis strvisx])
AC_CHECK_FUNCS([daemon])
save_LIBS="${LIBS}"
LIBS="${LIBS} ${RT_LIBS}"
......@@ -101,7 +103,13 @@ AC_CHECK_FUNCS([poll])
# Now that we're done using the compiler to look for functions and
# libraries, set CFLAGS to what we want them to be for our own code
DEVELOPER_CFLAGS="-Wall -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wformat"
# This corresponds to FreeBSD's WARNS level 6
DEVELOPER_CFLAGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wformat"
# Turn off warnings for two issues which occur frequently in our code
#DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -Wextra -Wno-missing-field-initializers -Wno-sign-compare"
AC_ARG_ENABLE(developer-warnings,
AS_HELP_STRING([--enable-developer-warnings],[enable strict warnings (default is NO)]),
CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}")
......
......@@ -14,11 +14,13 @@ noinst_HEADERS = \
compat/strndup.h \
compat/vasprintf.h \
compat/vis.h \
flopen.h \
http_headers.h \
libvarnish.h \
libvcl.h \
miniobj.h \
queue.h \
vpf.h \
vsb.h \
shmlog.h \
shmlog_tags.h \
......
/*-
* Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
* 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
* in this position and unchanged.
* 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 THE 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$
* Derived from:
* $FreeBSD: src/lib/libutil/libutil.h,v 1.44 2007/05/10 15:01:42 des Exp $
*/
#ifndef FLOPEN_H_INCLUDED
#define FLOPEN_H_INCLUDED
int flopen(const char *, int, ...);
#endif
/*-
* Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* 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 THE AUTHORS 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 AUTHORS 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$
* Derived from:
* $FreeBSD: src/lib/libutil/libutil.h,v 1.41 2005/08/24 17:21:38 pjd Exp $
*/
#ifndef VPF_H_INCLUDED
#define VPF_H_INCLUDED
struct pidfh;
struct pidfh *vpf_open(const char *path, mode_t mode, pid_t *pidptr);
int vpf_write(struct pidfh *pfh);
int vpf_close(struct pidfh *pfh);
int vpf_remove(struct pidfh *pfh);
#endif
......@@ -11,8 +11,10 @@ libvarnish_la_SOURCES = \
cli.c \
cli_common.c \
crc32.c \
flopen.c \
time.c \
version.c \
vpf.c \
vsb.c
libvarnish_la_CFLAGS = -include config.h
/*-
* Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
* 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
* in this position and unchanged.
* 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 THE 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$
* Derived from:
* $FreeBSD: src/lib/libutil/flopen.c,v 1.4 2007/05/10 15:01:42 des Exp $
*/
#include <sys/file.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
#include "flopen.h"
int
flopen(const char *path, int flags, ...)
{
int fd, operation, serrno;
struct stat sb, fsb;
mode_t mode;
#ifdef O_EXLOCK
flags &= ~O_EXLOCK;
#endif
mode = 0;
if (flags & O_CREAT) {
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, int); /* mode_t promoted to int */
va_end(ap);
}
operation = LOCK_EX;
if (flags & O_NONBLOCK)
operation |= LOCK_NB;
for (;;) {
if ((fd = open(path, flags, mode)) == -1)
/* non-existent or no access */
return (-1);
if (flock(fd, operation) == -1) {
/* unsupported or interrupted */
serrno = errno;
close(fd);
errno = serrno;
return (-1);
}
if (stat(path, &sb) == -1) {
/* disappeared from under our feet */
close(fd);
continue;
}
if (fstat(fd, &fsb) == -1) {
/* can't happen [tm] */
serrno = errno;
close(fd);
errno = serrno;
return (-1);
}
if (sb.st_dev != fsb.st_dev ||
sb.st_ino != fsb.st_ino) {
/* changed under our feet */
close(fd);
continue;
}
return (fd);
}
}
/*-
* Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* 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 THE AUTHORS 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 AUTHORS 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$
* Derived from:
* $FreeBSD: src/lib/libutil/pidfile.c,v 1.5 2007/05/11 11:10:05 des Exp $
*/
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#ifndef HAVE_STRLCPY
#include "compat/strlcpy.h"
#endif
#include "flopen.h"
#include "vpf.h"
struct pidfh {
int pf_fd;
char pf_path[MAXPATHLEN + 1];
__dev_t pf_dev;
ino_t pf_ino;
};
static int _vpf_remove(struct pidfh *pfh, int freeit);
static int
vpf_verify(struct pidfh *pfh)
{
struct stat sb;
if (pfh == NULL || pfh->pf_fd == -1)
return (EINVAL);
/*
* Check remembered descriptor.
*/
if (fstat(pfh->pf_fd, &sb) == -1)
return (errno);
if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino)
return (EINVAL);
return (0);
}
static int
vpf_read(const char *path, pid_t *pidptr)
{
char buf[16], *endptr;
int error, fd, i;
fd = open(path, O_RDONLY);
if (fd == -1)
return (errno);
i = read(fd, buf, sizeof(buf) - 1);
error = errno; /* Remember errno in case close() wants to change it. */
close(fd);
if (i == -1)
return (error);
buf[i] = '\0';
*pidptr = strtol(buf, &endptr, 10);
if (endptr != &buf[i])
return (EINVAL);
return (0);
}
struct pidfh *
vpf_open(const char *path, mode_t mode, pid_t *pidptr)
{
struct pidfh *pfh;
struct stat sb;
int error, fd, len;
pfh = malloc(sizeof(*pfh));
if (pfh == NULL)
return (NULL);
#if 0
if (path == NULL)
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
"/var/run/%s.pid", getprogname());
else
#endif
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
"%s", path);
if (len >= (int)sizeof(pfh->pf_path)) {
free(pfh);
errno = ENAMETOOLONG;
return (NULL);
}
/*
* Open the PID file and obtain exclusive lock.
* We truncate PID file here only to remove old PID immediatelly,
* PID file will be truncated again in vpf_write(), so
* vpf_write() can be called multiple times.
*/
fd = flopen(pfh->pf_path,
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
if (fd == -1) {
if (errno == EWOULDBLOCK && pidptr != NULL) {
errno = vpf_read(pfh->pf_path, pidptr);
if (errno == 0)
errno = EEXIST;
}
free(pfh);
return (NULL);
}
/*
* Remember file information, so in vpf_write() we are sure we write
* to the proper descriptor.
*/
if (fstat(fd, &sb) == -1) {
error = errno;
unlink(pfh->pf_path);
close(fd);
free(pfh);
errno = error;
return (NULL);
}
pfh->pf_fd = fd;
pfh->pf_dev = sb.st_dev;
pfh->pf_ino = sb.st_ino;
return (pfh);
}
int
vpf_write(struct pidfh *pfh)
{
char pidstr[16];
int error, fd;
/*
* Check remembered descriptor, so we don't overwrite some other
* file if pidfile was closed and descriptor reused.
*/
errno = vpf_verify(pfh);
if (errno != 0) {
/*
* Don't close descriptor, because we are not sure if it's ours.
*/
return (-1);
}
fd = pfh->pf_fd;
/*
* Truncate PID file, so multiple calls of vpf_write() are allowed.
*/
if (ftruncate(fd, 0) == -1) {
error = errno;
_vpf_remove(pfh, 0);
errno = error;
return (-1);
}
snprintf(pidstr, sizeof(pidstr), "%u", getpid());
if (pwrite(fd, pidstr, strlen(pidstr), 0) != (ssize_t)strlen(pidstr)) {
error = errno;
_vpf_remove(pfh, 0);
errno = error;
return (-1);
}
return (0);
}
int
vpf_close(struct pidfh *pfh)
{
int error;
error = vpf_verify(pfh);
if (error != 0) {
errno = error;
return (-1);
}
if (close(pfh->pf_fd) == -1)
error = errno;
free(pfh);
if (error != 0) {
errno = error;
return (-1);
}
return (0);
}
static int
_vpf_remove(struct pidfh *pfh, int freeit)
{
int error;
error = vpf_verify(pfh);
if (error != 0) {
errno = error;
return (-1);
}
if (unlink(pfh->pf_path) == -1)
error = errno;
if (flock(pfh->pf_fd, LOCK_UN) == -1) {
if (error == 0)
error = errno;
}
if (close(pfh->pf_fd) == -1) {
if (error == 0)
error = errno;
}
if (freeit)
free(pfh);
else
pfh->pf_fd = -1;
if (error != 0) {
errno = error;
return (-1);
}
return (0);
}
int
vpf_remove(struct pidfh *pfh)
{
return (_vpf_remove(pfh, 1));
}
Summary: Varnish is a high-performance HTTP accelerator
Name: varnish
Version: 1.0.3
Release: 7%{?dist}
Release: 8%{?dist}
License: BSD-like
Group: System Environment/Daemons
URL: http://www.varnish-cache.org/
Source0: http://downloads.sourceforge.net/varnish/varnish-%{version}.tar.gz
Patch0: varnish-1.0.3.redhat.patch0
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: ncurses-devel
Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release}
......@@ -47,14 +46,6 @@ Varnish is a high-performance HTTP accelerator.
%prep
%setup -q
%patch0 -p0
# Convert man pages to UTF-8
for i in bin/*/*.1 man/*.7
do
iconv -f iso-8859-1 -t utf-8 $i > $i.1.utf8
rm -f $i && mv $i.1.utf8 $i
done
%build
......@@ -67,8 +58,7 @@ done
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
#%{__make} %{?_smp_mflags}
%{__make}
%{__make} %{?_smp_mflags}
sed -e ' s/8080/80/g ' etc/vcl.conf > redhat/vcl.conf
......@@ -124,6 +114,7 @@ rm -rf %{buildroot}
%post
/sbin/chkconfig --add varnish
/sbin/chkconfig --add varnishlog
%preun
if [ $1 -lt 1 ]; then
......@@ -144,6 +135,10 @@ fi
%postun libs -p /sbin/ldconfig
%changelog
* Fri May 11 2007 Ingvar Hagelund <ingvar@linpro.no> - 1.0.svn-20070511
- Threw latest changes into svn trunk
- Removed the conversion of manpages into utf8. They are all utf8 in trunk
* Wed May 09 2007 Ingvar Hagelund <ingvar@linpro.no> - 1.0.3-7
- Simplified the references to the subpackage names
- Added init and logrotate scripts for varnishlog
......
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