From ssm at projects.linpro.no Fri Jun 1 07:34:09 2007 From: ssm at projects.linpro.no (ssm at projects.linpro.no) Date: Fri, 1 Jun 2007 09:34:09 +0200 (CEST) Subject: r1483 - trunk/varnish-cache/debian Message-ID: <20070601073409.CA67A1EC22E@projects.linpro.no> Author: ssm Date: 2007-06-01 09:34:09 +0200 (Fri, 01 Jun 2007) New Revision: 1483 Added: trunk/varnish-cache/debian/watch Log: Add a watch file to help people who build packages themselves look for a new release of varnish Added: trunk/varnish-cache/debian/watch =================================================================== --- trunk/varnish-cache/debian/watch (rev 0) +++ trunk/varnish-cache/debian/watch 2007-06-01 07:34:09 UTC (rev 1483) @@ -0,0 +1,4 @@ +version=3 + +# New versions of Varnish are available at SourceForge +http://sf.net/varnish/varnish-(.*)\.tar\.gz From des at projects.linpro.no Fri Jun 1 22:18:56 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 2 Jun 2007 00:18:56 +0200 (CEST) Subject: r1484 - trunk/varnish-cache/bin/varnishd Message-ID: <20070601221856.40E801EC22E@projects.linpro.no> Author: des Date: 2007-06-02 00:18:55 +0200 (Sat, 02 Jun 2007) New Revision: 1484 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Keep a master copy of the parameter block, to which all changes are applied, and which is copied to the shared parameter block every time a parameter changes as well as immediately before forking off a child. This prevents a hypothetical compromised child from changing the parent's idea of run-time parameters (which would, for example, allow it to trick the the parent into starting a new, hypothetically exploitable child with the attacker's choice of uid / gid). While I'm here, correct the use of the "volatile" qualifier - it is the parmeter block itself which can change unpredictably, not the pointer. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-01 07:34:09 UTC (rev 1483) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-01 22:18:55 UTC (rev 1484) @@ -121,7 +121,7 @@ unsigned ping_interval; }; -extern volatile struct params *params; +extern struct params * volatile params; extern struct heritage heritage; void child_main(void); Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-01 07:34:09 UTC (rev 1483) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-01 22:18:55 UTC (rev 1484) @@ -52,6 +52,7 @@ int mgt_cli_telnet(const char *T_arg); /* mgt_param.c */ +void MCF_ParamSync(void); void MCF_ParamInit(struct cli *); void MCF_ParamSet(struct cli *, const char *param, const char *val); Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-01 07:34:09 UTC (rev 1483) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-01 22:18:55 UTC (rev 1484) @@ -173,6 +173,7 @@ AZ(pipe(&heritage.fds[0])); AZ(pipe(&heritage.fds[2])); AZ(pipe(child_fds)); + MCF_ParamSync(); i = fork(); if (i < 0) errx(1, "Could not fork child"); Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-01 07:34:09 UTC (rev 1483) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-01 22:18:55 UTC (rev 1484) @@ -59,6 +59,8 @@ const char *units; }; +static struct params master; + /*--------------------------------------------------------------------*/ static void @@ -150,26 +152,26 @@ cli_result(cli, CLIS_PARAM); return; } - if (params->user) - free(params->user); - params->user = strdup(pw->pw_name); - AN(params->user); - params->uid = pw->pw_uid; + if (master.user) + free(master.user); + master.user = strdup(pw->pw_name); + AN(master.user); + master.uid = pw->pw_uid; /* set group to user's primary group */ - if (params->group) - free(params->group); + if (master.group) + free(master.group); if ((gr = getgrgid(pw->pw_gid)) != NULL && (gr = getgrnam(gr->gr_name)) != NULL && gr->gr_gid == pw->pw_gid) { - params->group = strdup(gr->gr_name); - AN(params->group); + master.group = strdup(gr->gr_name); + AN(master.group); } - params->gid = pw->pw_gid; - } else if (params->user) { - cli_out(cli, "%s (%d)", params->user, (int)params->uid); + master.gid = pw->pw_gid; + } else if (master.user) { + cli_out(cli, "%s (%d)", master.user, (int)master.uid); } else { - cli_out(cli, "%d", (int)params->uid); + cli_out(cli, "%d", (int)master.uid); } } @@ -187,15 +189,15 @@ cli_result(cli, CLIS_PARAM); return; } - if (params->group) - free(params->group); - params->group = strdup(gr->gr_name); - AN(params->group); - params->gid = gr->gr_gid; - } else if (params->group) { - cli_out(cli, "%s (%d)", params->group, (int)params->gid); + if (master.group) + free(master.group); + master.group = strdup(gr->gr_name); + AN(master.group); + master.gid = gr->gr_gid; + } else if (master.group) { + cli_out(cli, "%s (%d)", master.group, (int)master.gid); } else { - cli_out(cli, "%d", (int)params->gid); + cli_out(cli, "%d", (int)master.gid); } } @@ -206,7 +208,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->default_ttl, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.default_ttl, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -216,7 +218,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->wthread_pools, arg, + tweak_generic_uint(cli, &master.wthread_pools, arg, 1, UINT_MAX); } @@ -228,8 +230,8 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->wthread_min, arg, - 0, params->wthread_max); + tweak_generic_uint(cli, &master.wthread_min, arg, + 0, master.wthread_max); } /*--------------------------------------------------------------------*/ @@ -239,8 +241,8 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->wthread_max, arg, - params->wthread_min, UINT_MAX); + tweak_generic_uint(cli, &master.wthread_max, arg, + master.wthread_min, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -250,7 +252,7 @@ { (void)par; - tweak_generic_timeout(cli, ¶ms->wthread_timeout, arg); + tweak_generic_timeout(cli, &master.wthread_timeout, arg); } /*--------------------------------------------------------------------*/ @@ -260,7 +262,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->overflow_max, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.overflow_max, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -270,7 +272,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->mem_workspace, arg, + tweak_generic_uint(cli, &master.mem_workspace, arg, 1024, UINT_MAX); } @@ -280,7 +282,7 @@ tweak_sess_timeout(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_timeout(cli, ¶ms->sess_timeout, arg); + tweak_generic_timeout(cli, &master.sess_timeout, arg); } /*--------------------------------------------------------------------*/ @@ -289,7 +291,7 @@ tweak_pipe_timeout(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_timeout(cli, ¶ms->pipe_timeout, arg); + tweak_generic_timeout(cli, &master.pipe_timeout, arg); } /*--------------------------------------------------------------------*/ @@ -298,7 +300,7 @@ tweak_send_timeout(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_timeout(cli, ¶ms->send_timeout, arg); + tweak_generic_timeout(cli, &master.send_timeout, arg); } /*--------------------------------------------------------------------*/ @@ -308,7 +310,7 @@ { (void)par; - tweak_generic_bool(cli, ¶ms->auto_restart, arg); + tweak_generic_bool(cli, &master.auto_restart, arg); } /*--------------------------------------------------------------------*/ @@ -318,7 +320,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->fetch_chunksize, arg, + tweak_generic_uint(cli, &master.fetch_chunksize, arg, 4, UINT_MAX / 1024); } @@ -330,7 +332,7 @@ { (void)par; - tweak_generic_uint(cli, ¶ms->sendfile_threshold, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.sendfile_threshold, arg, 0, UINT_MAX); } #endif /* HAVE_SENDFILE */ @@ -340,7 +342,7 @@ tweak_vcl_trace(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_bool(cli, ¶ms->vcl_trace, arg); + tweak_generic_bool(cli, &master.vcl_trace, arg); } /*--------------------------------------------------------------------*/ @@ -369,9 +371,9 @@ if (arg == NULL) { /* Quote the string if we have more than one socket */ if (heritage.nsocks > 1) - cli_out(cli, "\"%s\"", params->listen_address); + cli_out(cli, "\"%s\"", master.listen_address); else - cli_out(cli, "%s", params->listen_address); + cli_out(cli, "%s", master.listen_address); return; } @@ -422,9 +424,9 @@ return; } - free(params->listen_address); - params->listen_address = strdup(arg); - AN(params->listen_address); + free(master.listen_address); + master.listen_address = strdup(arg); + AN(master.listen_address); clean_listen_sock_head(&heritage.socks); heritage.nsocks = 0; @@ -443,7 +445,7 @@ tweak_listen_depth(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_uint(cli, ¶ms->listen_depth, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.listen_depth, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -452,7 +454,7 @@ tweak_srcaddr_hash(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_uint(cli, ¶ms->srcaddr_hash, arg, 63, UINT_MAX); + tweak_generic_uint(cli, &master.srcaddr_hash, arg, 63, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -461,7 +463,7 @@ tweak_srcaddr_ttl(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_uint(cli, ¶ms->srcaddr_ttl, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.srcaddr_ttl, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -470,7 +472,7 @@ tweak_backend_http11(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_bool(cli, ¶ms->backend_http11, arg); + tweak_generic_bool(cli, &master.backend_http11, arg); } /*--------------------------------------------------------------------*/ @@ -479,7 +481,7 @@ tweak_client_http11(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_bool(cli, ¶ms->client_http11, arg); + tweak_generic_bool(cli, &master.client_http11, arg); } /*--------------------------------------------------------------------*/ @@ -488,7 +490,7 @@ tweak_ping_interval(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - tweak_generic_uint(cli, ¶ms->ping_interval, arg, 0, UINT_MAX); + tweak_generic_uint(cli, &master.ping_interval, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -733,6 +735,15 @@ /*--------------------------------------------------------------------*/ void +MCF_ParamSync(void) +{ + if (params != &master) + *params = master; +} + +/*--------------------------------------------------------------------*/ + +void MCF_ParamSet(struct cli *cli, const char *param, const char *val) { struct parspec *pp; @@ -745,6 +756,7 @@ } cli_result(cli, CLIS_PARAM); cli_out(cli, "Unknown paramter \"%s\".", param); + MCF_ParamSync(); } @@ -771,4 +783,5 @@ if (cli->result != CLIS_OK) return; } + params = &master; } Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-01 07:34:09 UTC (rev 1483) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-01 22:18:55 UTC (rev 1484) @@ -66,7 +66,7 @@ #endif struct heritage heritage; -volatile struct params *params; +struct params * volatile params; /*--------------------------------------------------------------------*/ @@ -407,7 +407,6 @@ const char *T_arg = NULL; unsigned C_flag = 0; char *p; - struct params param; struct cli cli[1]; struct pidfh *pfh = NULL; @@ -419,23 +418,7 @@ XXXAN(cli[0].sb); cli[0].result = CLIS_OK; - /* - * Set up a temporary param block until VSL_MgtInit() can - * replace with shmem backed structure version. - * - * XXX: I wonder if it would be smarter to inform the child process - * XXX: about param changes via CLI rather than keeping the param - * 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: 'param' to static - */ - TAILQ_INIT(&heritage.socks); - memset(¶m, 0, sizeof param); - params = ¶m; mgt_vcc_init(); MCF_ParamInit(cli); From des at projects.linpro.no Fri Jun 1 22:43:03 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 2 Jun 2007 00:43:03 +0200 (CEST) Subject: r1485 - in trunk/varnish-cache: bin/varnishd bin/varnishncsa lib/libvcl Message-ID: <20070601224303.9A0341EC87C@projects.linpro.no> Author: des Date: 2007-06-02 00:43:03 +0200 (Sat, 02 Jun 2007) New Revision: 1485 Modified: trunk/varnish-cache/bin/varnishd/flint.sh trunk/varnish-cache/bin/varnishd/vclflint.sh trunk/varnish-cache/bin/varnishncsa/flint.sh trunk/varnish-cache/lib/libvcl/flint.sh Log: Make these scripts executable. Property changes on: trunk/varnish-cache/bin/varnishd/flint.sh ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/varnish-cache/bin/varnishd/vclflint.sh ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/varnish-cache/bin/varnishncsa/flint.sh ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/varnish-cache/lib/libvcl/flint.sh ___________________________________________________________________ Name: svn:executable + * From des at projects.linpro.no Mon Jun 4 08:44:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 10:44:44 +0200 (CEST) Subject: r1486 - in trunk: . varnish-logo Message-ID: <20070604084444.98F7E1EC855@projects.linpro.no> Author: des Date: 2007-06-04 10:44:44 +0200 (Mon, 04 Jun 2007) New Revision: 1486 Added: trunk/varnish-logo/ trunk/varnish-logo/VarnishLogo2007.eps Log: Original logo sheet from VG Added: trunk/varnish-logo/VarnishLogo2007.eps =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/VarnishLogo2007.eps ___________________________________________________________________ Name: svn:mime-type + image/eps From des at projects.linpro.no Mon Jun 4 08:45:23 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 10:45:23 +0200 (CEST) Subject: r1487 - in trunk/varnish-logo: . icon Message-ID: <20070604084523.0C30B1EC855@projects.linpro.no> Author: des Date: 2007-06-04 10:45:22 +0200 (Mon, 04 Jun 2007) New Revision: 1487 Added: trunk/varnish-logo/icon/ trunk/varnish-logo/icon/varnish-icon.xcf Log: Icon version of the logo, with either red or green background. Added: trunk/varnish-logo/icon/varnish-icon.xcf =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-icon.xcf ___________________________________________________________________ Name: svn:mime-type + image/x-xcf From des at projects.linpro.no Mon Jun 4 08:46:40 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 10:46:40 +0200 (CEST) Subject: r1488 - trunk/varnish-logo/icon Message-ID: <20070604084640.01BDC1EC525@projects.linpro.no> Author: des Date: 2007-06-04 10:46:39 +0200 (Mon, 04 Jun 2007) New Revision: 1488 Added: trunk/varnish-logo/icon/varnish-green-16.gif trunk/varnish-logo/icon/varnish-green-24.gif trunk/varnish-logo/icon/varnish-green-32.gif trunk/varnish-logo/icon/varnish-green-48.gif trunk/varnish-logo/icon/varnish-green-64.gif trunk/varnish-logo/icon/varnish-red-16.gif trunk/varnish-logo/icon/varnish-red-24.gif trunk/varnish-logo/icon/varnish-red-32.gif trunk/varnish-logo/icon/varnish-red-48.gif trunk/varnish-logo/icon/varnish-red-64.gif Log: Prerendered icons in red or green in various sizes. Stored in GIF format to preserve transparency - MSIE can't handle PNG transparency. Added: trunk/varnish-logo/icon/varnish-green-16.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-green-16.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-green-24.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-green-24.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-green-32.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-green-32.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-green-48.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-green-48.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-green-64.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-green-64.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-red-16.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-red-16.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-red-24.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-red-24.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-red-32.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-red-32.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-red-48.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-red-48.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/icon/varnish-red-64.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/icon/varnish-red-64.gif ___________________________________________________________________ Name: svn:mime-type + image/gif From des at projects.linpro.no Mon Jun 4 14:42:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 16:42:55 +0200 (CEST) Subject: r1489 - trunk/varnish-cache Message-ID: <20070604144255.A29C11EC855@projects.linpro.no> Author: des Date: 2007-06-04 16:42:55 +0200 (Mon, 04 Jun 2007) New Revision: 1489 Modified: trunk/varnish-cache/autogen.des trunk/varnish-cache/configure.ac Log: Add configure options for extra-strict warnings + stack protection (both require gcc 4), tune autogen.des accordingly. Modified: trunk/varnish-cache/autogen.des =================================================================== --- trunk/varnish-cache/autogen.des 2007-06-04 08:46:39 UTC (rev 1488) +++ trunk/varnish-cache/autogen.des 2007-06-04 14:42:55 UTC (rev 1489) @@ -5,12 +5,16 @@ set -ex -./autogen.sh +. ./autogen.sh -CONFIG_SHELL=/bin/sh \ +# autoconf prior to 2.62 has issues with zsh 4.2 and newer +export CONFIG_SHELL=/bin/sh + ./configure \ --enable-developer-warnings \ --enable-debugging-symbols \ --enable-dependency-tracking \ + --enable-extra-developer-warnings \ + --enable-stack-protector \ --enable-werror \ --prefix=/opt/varnish Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-04 08:46:39 UTC (rev 1488) +++ trunk/varnish-cache/configure.ac 2007-06-04 14:42:55 UTC (rev 1489) @@ -108,8 +108,8 @@ # 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" +# Additional flags for GCC 4 +EXTRA_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)]), @@ -117,6 +117,12 @@ AC_ARG_ENABLE(debugging-symbols, AS_HELP_STRING([--enable-debugging-symbols],[enable debugging symbols (default is NO)]), CFLAGS="${CFLAGS} -O0 -g -fno-inline") +AC_ARG_ENABLE(extra-developer-warnings, + AS_HELP_STRING([--enable-extra-developer-warnings],[enable even stricter warnings (default is NO)]), + CFLAGS="${CFLAGS} ${EXTRA_DEVELOPER_CFLAGS}") +AC_ARG_ENABLE(stack-protector, + AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is NO)]), + CFLAGS="${CFLAGS} -fstack-protector-all") AC_ARG_ENABLE(werror, AS_HELP_STRING([--enable-werror],[use -Werror (default is NO)]), CFLAGS="${CFLAGS} -Werror") From des at projects.linpro.no Mon Jun 4 15:04:15 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:04:15 +0200 (CEST) Subject: r1490 - trunk Message-ID: <20070604150415.158DD1EC525@projects.linpro.no> Author: des Date: 2007-06-04 17:04:14 +0200 (Mon, 04 Jun 2007) New Revision: 1490 Removed: trunk/varnish-proto/ Log: GC unused files. From phk at phk.freebsd.dk Mon Jun 4 15:16:27 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 04 Jun 2007 15:16:27 +0000 Subject: r1489 - trunk/varnish-cache In-Reply-To: Your message of "Mon, 04 Jun 2007 16:42:55 +0200." <20070604144255.A29C11EC855@projects.linpro.no> Message-ID: <55179.1180970187@critter.freebsd.dk> In message <20070604144255.A29C11EC855 at projects.linpro.no>, des at projects.linpro .no writes: >Author: des >Date: 2007-06-04 16:42:55 +0200 (Mon, 04 Jun 2007) >New Revision: 1489 > >Modified: > trunk/varnish-cache/autogen.des > trunk/varnish-cache/configure.ac >Log: >Add configure options for extra-strict warnings + stack protection (both >require gcc 4), tune autogen.des accordingly. Good move. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at projects.linpro.no Mon Jun 4 15:27:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:27:08 +0200 (CEST) Subject: r1491 - trunk/varnish-logo/icon Message-ID: <20070604152708.E0EAD1EC855@projects.linpro.no> Author: des Date: 2007-06-04 17:27:08 +0200 (Mon, 04 Jun 2007) New Revision: 1491 Modified: trunk/varnish-logo/icon/varnish-green-16.gif trunk/varnish-logo/icon/varnish-green-24.gif trunk/varnish-logo/icon/varnish-green-32.gif trunk/varnish-logo/icon/varnish-green-48.gif trunk/varnish-logo/icon/varnish-green-64.gif trunk/varnish-logo/icon/varnish-icon.xcf trunk/varnish-logo/icon/varnish-red-16.gif trunk/varnish-logo/icon/varnish-red-24.gif trunk/varnish-logo/icon/varnish-red-32.gif trunk/varnish-logo/icon/varnish-red-48.gif trunk/varnish-logo/icon/varnish-red-64.gif Log: Correct the red / green color to 60% instead of 75%. Modified: trunk/varnish-logo/icon/varnish-green-16.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-green-24.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-green-32.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-green-48.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-green-64.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-icon.xcf =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-red-16.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-red-24.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-red-32.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-red-48.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/icon/varnish-red-64.gif =================================================================== (Binary files differ) From des at projects.linpro.no Mon Jun 4 15:42:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:42:37 +0200 (CEST) Subject: r1492 - trunk/varnish-logo/icon Message-ID: <20070604154237.6C67E1EC855@projects.linpro.no> Author: des Date: 2007-06-04 17:42:37 +0200 (Mon, 04 Jun 2007) New Revision: 1492 Added: trunk/varnish-logo/icon/varnish-icon-green-16.gif trunk/varnish-logo/icon/varnish-icon-green-24.gif trunk/varnish-logo/icon/varnish-icon-green-32.gif trunk/varnish-logo/icon/varnish-icon-green-48.gif trunk/varnish-logo/icon/varnish-icon-green-64.gif trunk/varnish-logo/icon/varnish-icon-red-16.gif trunk/varnish-logo/icon/varnish-icon-red-24.gif trunk/varnish-logo/icon/varnish-icon-red-32.gif trunk/varnish-logo/icon/varnish-icon-red-48.gif trunk/varnish-logo/icon/varnish-icon-red-64.gif Removed: trunk/varnish-logo/icon/varnish-green-16.gif trunk/varnish-logo/icon/varnish-green-24.gif trunk/varnish-logo/icon/varnish-green-32.gif trunk/varnish-logo/icon/varnish-green-48.gif trunk/varnish-logo/icon/varnish-green-64.gif trunk/varnish-logo/icon/varnish-red-16.gif trunk/varnish-logo/icon/varnish-red-24.gif trunk/varnish-logo/icon/varnish-red-32.gif trunk/varnish-logo/icon/varnish-red-48.gif trunk/varnish-logo/icon/varnish-red-64.gif Log: Rename to include "icon" in file name. Deleted: trunk/varnish-logo/icon/varnish-green-16.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-green-24.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-green-32.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-green-48.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-green-64.gif =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-green-16.gif (from rev 1491, trunk/varnish-logo/icon/varnish-green-16.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-green-24.gif (from rev 1491, trunk/varnish-logo/icon/varnish-green-24.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-green-32.gif (from rev 1491, trunk/varnish-logo/icon/varnish-green-32.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-green-48.gif (from rev 1491, trunk/varnish-logo/icon/varnish-green-48.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-green-64.gif (from rev 1491, trunk/varnish-logo/icon/varnish-green-64.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-red-16.gif (from rev 1491, trunk/varnish-logo/icon/varnish-red-16.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-red-24.gif (from rev 1491, trunk/varnish-logo/icon/varnish-red-24.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-red-32.gif (from rev 1491, trunk/varnish-logo/icon/varnish-red-32.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-red-48.gif (from rev 1491, trunk/varnish-logo/icon/varnish-red-48.gif) =================================================================== (Binary files differ) Copied: trunk/varnish-logo/icon/varnish-icon-red-64.gif (from rev 1491, trunk/varnish-logo/icon/varnish-red-64.gif) =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-red-16.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-red-24.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-red-32.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-red-48.gif =================================================================== (Binary files differ) Deleted: trunk/varnish-logo/icon/varnish-red-64.gif =================================================================== (Binary files differ) From des at projects.linpro.no Mon Jun 4 15:46:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:46:57 +0200 (CEST) Subject: r1493 - in trunk/varnish-logo: . logo Message-ID: <20070604154657.20DEA1EC855@projects.linpro.no> Author: des Date: 2007-06-04 17:46:56 +0200 (Mon, 04 Jun 2007) New Revision: 1493 Added: trunk/varnish-logo/logo/ trunk/varnish-logo/logo/varnish-logo.xcf Log: Full logo with both red and green background Added: trunk/varnish-logo/logo/varnish-logo.xcf =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo.xcf ___________________________________________________________________ Name: svn:mime-type + image/x-xcf From des at projects.linpro.no Mon Jun 4 15:47:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:47:12 +0200 (CEST) Subject: r1494 - trunk/varnish-logo/logo Message-ID: <20070604154712.8D1601ED41D@projects.linpro.no> Author: des Date: 2007-06-04 17:47:12 +0200 (Mon, 04 Jun 2007) New Revision: 1494 Added: trunk/varnish-logo/logo/varnish-logo-green-128.gif trunk/varnish-logo/logo/varnish-logo-green-32.gif trunk/varnish-logo/logo/varnish-logo-green-64.gif trunk/varnish-logo/logo/varnish-logo-red-128.gif trunk/varnish-logo/logo/varnish-logo-red-32.gif trunk/varnish-logo/logo/varnish-logo-red-64.gif Log: Pre-rendered versions of the full logo in various sizes. Added: trunk/varnish-logo/logo/varnish-logo-green-128.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-green-128.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/logo/varnish-logo-green-32.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-green-32.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/logo/varnish-logo-green-64.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-green-64.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/logo/varnish-logo-red-128.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-red-128.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/logo/varnish-logo-red-32.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-red-32.gif ___________________________________________________________________ Name: svn:mime-type + image/gif Added: trunk/varnish-logo/logo/varnish-logo-red-64.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-logo/logo/varnish-logo-red-64.gif ___________________________________________________________________ Name: svn:mime-type + image/gif From des at projects.linpro.no Mon Jun 4 15:54:34 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:54:34 +0200 (CEST) Subject: r1495 - trunk/varnish-logo/logo Message-ID: <20070604155434.91A971EC411@projects.linpro.no> Author: des Date: 2007-06-04 17:54:34 +0200 (Mon, 04 Jun 2007) New Revision: 1495 Modified: trunk/varnish-logo/logo/varnish-logo.xcf Log: Add about as much space on each side as there was in the old logo. Modified: trunk/varnish-logo/logo/varnish-logo.xcf =================================================================== (Binary files differ) From des at projects.linpro.no Mon Jun 4 15:56:56 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 4 Jun 2007 17:56:56 +0200 (CEST) Subject: r1496 - trunk/varnish-logo/logo Message-ID: <20070604155656.EB19C1EC411@projects.linpro.no> Author: des Date: 2007-06-04 17:56:56 +0200 (Mon, 04 Jun 2007) New Revision: 1496 Modified: trunk/varnish-logo/logo/varnish-logo-green-128.gif trunk/varnish-logo/logo/varnish-logo-green-32.gif trunk/varnish-logo/logo/varnish-logo-green-64.gif trunk/varnish-logo/logo/varnish-logo-red-128.gif trunk/varnish-logo/logo/varnish-logo-red-32.gif trunk/varnish-logo/logo/varnish-logo-red-64.gif Log: Regenerate. Modified: trunk/varnish-logo/logo/varnish-logo-green-128.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/logo/varnish-logo-green-32.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/logo/varnish-logo-green-64.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/logo/varnish-logo-red-128.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/logo/varnish-logo-red-32.gif =================================================================== (Binary files differ) Modified: trunk/varnish-logo/logo/varnish-logo-red-64.gif =================================================================== (Binary files differ) From phk at projects.linpro.no Mon Jun 4 19:08:31 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 4 Jun 2007 21:08:31 +0200 (CEST) Subject: r1497 - trunk/varnish-cache/bin/varnishd Message-ID: <20070604190831.515511EC041@projects.linpro.no> Author: phk Date: 2007-06-04 21:08:30 +0200 (Mon, 04 Jun 2007) New Revision: 1497 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c Log: Fold long lines. Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-04 15:56:56 UTC (rev 1496) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-04 19:08:30 UTC (rev 1497) @@ -162,14 +162,16 @@ tv_sndtimeo.tv_sec = params->send_timeout; TAILQ_FOREACH(ls, &heritage.socks, list) AZ(setsockopt(ls->sock, SOL_SOCKET, - SO_SNDTIMEO, &tv_sndtimeo, sizeof tv_sndtimeo)); + SO_SNDTIMEO, + &tv_sndtimeo, sizeof tv_sndtimeo)); } if (params->sess_timeout != tv_rcvtimeo.tv_sec) { need_test = 1; tv_rcvtimeo.tv_sec = params->sess_timeout; TAILQ_FOREACH(ls, &heritage.socks, list) AZ(setsockopt(ls->sock, SOL_SOCKET, - SO_RCVTIMEO, &tv_rcvtimeo, sizeof tv_rcvtimeo)); + SO_RCVTIMEO, + &tv_rcvtimeo, sizeof tv_rcvtimeo)); } i = poll(pfd, heritage.nsocks, 1000); for (j = 0; j < heritage.nsocks; j++) { From phk at projects.linpro.no Mon Jun 4 19:10:17 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 4 Jun 2007 21:10:17 +0200 (CEST) Subject: r1498 - trunk/varnish-cache/bin/varnishd Message-ID: <20070604191017.1C9501EC044@projects.linpro.no> Author: phk Date: 2007-06-04 21:10:16 +0200 (Mon, 04 Jun 2007) New Revision: 1498 Added: trunk/varnish-cache/bin/varnishd/cache_ws.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Wrap the management of the session workspace in functions, to prevent pointer gymnastics getting out of hand. In addition to the obvious alloc/return primitives there are also reserve/release primitives for when we don't know the length yet. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-04 19:10:16 UTC (rev 1498) @@ -29,6 +29,7 @@ cache_vrt.c \ cache_vrt_acl.c \ cache_vrt_re.c \ + cache_ws.c \ hash_simple_list.c \ hash_classic.c \ mgt_child.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-04 19:10:16 UTC (rev 1498) @@ -77,8 +77,29 @@ }; /*-------------------------------------------------------------------- + * Workspace structure for quick memory allocation. + */ + +struct ws { + char *s; /* (S)tart of buffer */ + char *e; /* (E)nd of buffer */ + char *f; /* (F)ree pointer */ + char *r; /* (R)eserved length */ +}; + +void WS_Init(struct ws *ws, void *space, unsigned len); +unsigned WS_Reserve(struct ws *ws, unsigned bytes); +void WS_Release(struct ws *ws, unsigned bytes); +void WS_ReleaseP(struct ws *ws, char *ptr); +void WS_Assert(struct ws *ws); +void WS_Reset(struct ws *ws); +char *WS_Alloc(struct ws *ws, unsigned bytes); +void WS_Return(struct ws *ws, char *b, char *e); + + + +/*-------------------------------------------------------------------- * HTTP Request/Response/Header handling structure. - * RSN: struct worker and struct session will have one of these embedded. */ struct http_hdr { @@ -90,11 +111,9 @@ unsigned magic; #define HTTP_MAGIC 0x6428b5c9 - char *s; /* (S)tart of buffer */ - char *t; /* start of (T)railing data */ - char *v; /* end of (V)alid bytes */ - char *f; /* first (F)ree byte */ - char *e; /* (E)nd of buffer */ + struct ws ws[1]; + char *rx_s, *rx_e; /* Received Request */ + char *pl_s, *pl_e; /* Pipelined bytes */ unsigned char conds; /* If-* headers present */ enum httpwhence { Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -214,7 +214,7 @@ sp->step = STP_RECV; return (0); } - if (sp->http->t < sp->http->v) { + if (sp->http->pl_s < sp->http->pl_e) { VSL_stats->sess_readahead++; sp->step = STP_AGAIN; return (0); @@ -426,13 +426,12 @@ { struct object *o; - assert(sp->http->f > sp->http->s); - assert(sp->http->f >= sp->http->t); if (sp->obj == NULL) { - sp->hash_b = sp->http->f; + WS_Reserve(sp->http->ws, 0); + sp->hash_b = sp->http->ws->f; sp->hash_e = sp->hash_b; VCL_hash_method(sp); /* XXX: no-op for now */ - + WS_ReleaseP(sp->http->ws, sp->hash_e); /* XXX check error */ } @@ -449,12 +448,7 @@ return (1); } - xxxassert (sp->hash_e == sp->http->f); - if (sp->hash_e == sp->http->f) { - /* Nobody alloc'ed after us, free again */ - sp->http->f = sp->hash_b; - } - + WS_Return(sp->http->ws, sp->hash_b, sp->hash_e); sp->hash_b = sp->hash_e = NULL; sp->obj = o; Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -251,8 +251,8 @@ if (r != 0) return; - if (o->http.s != NULL) - free(o->http.s); + if (o->http.ws->s != NULL) + free(o->http.ws->s); HSH_Freestore(o); free(o); Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -164,16 +164,11 @@ void http_Setup(struct http *hp, void *space, unsigned len) { - char *sp = space; assert(len > 0); memset(hp, 0, sizeof *hp); hp->magic = HTTP_MAGIC; - hp->s = sp; - hp->t = sp; - hp->v = sp; - hp->f = sp; - hp->e = sp + len; + WS_Init(hp->ws, space, len); hp->nhd = HTTP_HDR_FIRST; } @@ -329,20 +324,20 @@ http_GetTail(struct http *hp, unsigned len, char **b, char **e) { - if (hp->t >= hp->v) + if (hp->pl_s >= hp->pl_e) return (0); if (len == 0) - len = hp->v - hp->t; + len = hp->pl_e - hp->pl_e; - if (hp->t + len > hp->v) - len = hp->v - hp->t; + if (hp->pl_s + len > hp->pl_e) + len = hp->pl_e - hp->pl_s; if (len == 0) return (0); - *b = hp->t; - *e = hp->t + len; - hp->t += len; - assert(hp->t <= hp->v); + *b = hp->pl_s; + *e = hp->pl_s + len; + hp->pl_s += len; + assert(hp->pl_s <= hp->pl_e); return (1); } @@ -357,15 +352,16 @@ char *b = p; u = 0; - if (hp->t < hp->v) { - u = hp->v - hp->t; + if (hp->pl_s < hp->pl_e) { + u = hp->pl_e - hp->pl_s; if (u > len) u = len; - memcpy(b, hp->t, u); - hp->t += u; + memcpy(b, hp->pl_s, u); + hp->pl_s += u; b += u; len -= u; } + hp->pl_s = hp->pl_e = NULL; if (len > 0) { i = read(fd, b, len); if (i < 0) @@ -417,8 +413,8 @@ hp->nhd = HTTP_HDR_FIRST; hp->conds = 0; r = NULL; /* For FlexeLint */ - assert(p < hp->v); /* http_header_complete() guarantees this */ - for (; p < hp->v; p = r) { + assert(p < hp->rx_e); /* http_header_complete() guarantees this */ + for (; p < hp->rx_e; p = r) { /* XXX: handle continuation lines */ q = strchr(p, '\n'); assert(q != NULL); @@ -445,8 +441,6 @@ WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, p, q); } } - assert(hp->t <= hp->v); - assert(hp->t == r); return (0); } @@ -458,12 +452,11 @@ char *p; CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - AN(hp->t); - assert(hp->s < hp->t); - assert(hp->t <= hp->v); + /* Assert a NUL at rx_e */ + assert(hp->rx_s < hp->rx_e); hp->logtag = HTTP_Rx; - for (p = hp->s ; isspace(*p); p++) + for (p = hp->rx_s ; isspace(*p); p++) continue; /* First, the request type (GET/HEAD etc) */ @@ -478,7 +471,7 @@ while (isspace(*p) && *p != '\n') p++; if (*p == '\n') { - WSLR(w, SLT_HttpGarbage, fd, hp->s, hp->v); + WSLR(w, SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); return (400); } hp->hd[HTTP_HDR_URL].b = p; @@ -487,7 +480,7 @@ hp->hd[HTTP_HDR_URL].e = p; WSLH(w, HTTP_T_URL, fd, hp, HTTP_HDR_URL); if (*p == '\n') { - WSLR(w, SLT_HttpGarbage, fd, hp->s, hp->v); + WSLR(w, SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); return (400); } *p++ = '\0'; @@ -496,7 +489,7 @@ while (isspace(*p) && *p != '\n') p++; if (*p == '\n') { - WSLR(w, SLT_HttpGarbage, fd, hp->s, hp->v); + WSLR(w, SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); return (400); } hp->hd[HTTP_HDR_PROTO].b = p; @@ -509,7 +502,7 @@ while (isspace(*p) && *p != '\n') p++; if (*p != '\n') { - WSLR(w, SLT_HttpGarbage, fd, hp->s, hp->v); + WSLR(w, SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); return (400); } *p++ = '\0'; @@ -525,16 +518,15 @@ char *p, *q; CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - AN(hp->t); - assert(hp->s < hp->t); - assert(hp->t <= hp->v); + /* Assert a NUL at rx_e */ + assert(hp->rx_s < hp->rx_e); hp->logtag = HTTP_Rx; - for (p = hp->s ; isspace(*p); p++) + for (p = hp->rx_s ; isspace(*p); p++) continue; if (memcmp(p, "HTTP/1.", 7)) { - WSLR(w, SLT_HttpGarbage, fd, hp->s, hp->v); + WSLR(w, SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); return (400); } /* First, protocol */ @@ -572,7 +564,9 @@ return (http_dissect_hdrs(w, hp, fd, p)); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Return nonzero if we have a complete HTTP request. + */ static int http_header_complete(struct http *hp) @@ -580,33 +574,33 @@ char *p; CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - assert(hp->v <= hp->e); - assert(*hp->v == '\0'); + assert(*hp->rx_e == '\0'); /* Skip any leading white space */ - for (p = hp->s ; p < hp->v && isspace(*p); p++) + for (p = hp->rx_s ; p < hp->rx_e && isspace(*p); p++) continue; - if (p >= hp->v) { - hp->v = hp->s; + if (p >= hp->rx_e) { + hp->rx_e = hp->rx_s; return (0); } while (1) { /* XXX: we could save location of all linebreaks for later */ p = strchr(p, '\n'); if (p == NULL) - return (0); + return (0); /* XXX: Could cache p */ p++; if (*p == '\r') p++; - if (*p != '\n') - continue; - break; + if (*p == '\n') + break; } - if (++p > hp->v) - return (0); - hp->t = p; - assert(hp->t > hp->s); - assert(hp->t <= hp->v); - hp->f = hp->v; + p++; + WS_ReleaseP(hp->ws, hp->rx_e); + if (p != hp->rx_e) { + hp->pl_s = p; + hp->pl_e = hp->rx_e; + hp->rx_e = p; + } + /* XXX: Check this stuff... */ return (1); } @@ -618,25 +612,26 @@ unsigned l; CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - assert(hp->v <= hp->e); - assert(hp->t <= hp->v); - if (hp->t > hp->s && hp->t < hp->v) { - l = hp->v - hp->t; - memmove(hp->s, hp->t, l); - hp->v = hp->s + l; - hp->t = hp->s; - *hp->v = '\0'; - } else { - hp->v = hp->s; - hp->t = hp->s; + WS_Assert(hp->ws); + WS_Reset(hp->ws); + WS_Reserve(hp->ws, 0); + hp->rx_s = hp->ws->f; + hp->rx_e = hp->rx_s; + if (hp->pl_s != NULL) { + assert(hp->pl_s < hp->pl_e); + l = hp->pl_e - hp->pl_s; + memmove(hp->rx_s, hp->pl_s, l); + hp->rx_e = hp->rx_s + l; + hp->pl_s = hp->pl_e = NULL; } + *hp->rx_e = '\0'; } int http_RecvPrepAgain(struct http *hp) { http_RecvPrep(hp); - if (hp->v == hp->s) + if (hp->rx_s == hp->rx_e) return (0); return (http_header_complete(hp)); } @@ -649,38 +644,35 @@ unsigned l; int i; - l = (hp->e - hp->s) / 2; - if (l < hp->v - hp->s) - l = 0; - else - l -= hp->v - hp->s; + l = (hp->ws->e - hp->rx_e) - 1; if (l <= 1) { VSL(SLT_HttpError, fd, "Received too much"); - VSLR(SLT_HttpGarbage, fd, hp->s, hp->v); - hp->t = NULL; + VSLR(SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); + hp->rx_s = hp->rx_e = NULL; + WS_Release(hp->ws, 0); return (1); } errno = 0; - i = read(fd, hp->v, l - 1); + i = read(fd, hp->rx_e, l - 1); if (i > 0) { - hp->v += i; - *hp->v = '\0'; + hp->rx_e += i; + *hp->rx_e = '\0'; if (http_header_complete(hp)) return(0); return (-1); } - if (hp->v != hp->s) { + if (hp->rx_e != hp->rx_s) { VSL(SLT_HttpError, fd, "Received (only) %d bytes, errno %d", - hp->v - hp->s, errno); - VSLR(SLT_Debug, fd, hp->s, hp->v); + hp->rx_e - hp->rx_s, errno); + VSLR(SLT_Debug, fd, hp->rx_s, hp->rx_e); } else if (errno == 0) VSL(SLT_HttpError, fd, "Received nothing"); else - VSL(SLT_HttpError, fd, - "Received errno %d", errno); - hp->t = NULL; + VSL(SLT_HttpError, fd, "Received errno %d", errno); + hp->rx_s = hp->rx_e = NULL; + WS_Release(hp->ws, 0); return(2); } @@ -707,6 +699,7 @@ http_CopyHttp(struct http *to, struct http *fm) { unsigned u, l; + char *p; CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); @@ -717,10 +710,10 @@ AN(fm->hd[u].e); l += (fm->hd[u].e - fm->hd[u].b) + 1; } - to->s = malloc(l); - XXXAN(to->s); - to->e = to->s + l; - to->f = to->s; + p = malloc(l); + XXXAN(p); + WS_Init(to->ws, p, l); + WS_Reserve(to->ws, 0); for (u = 0; u < fm->nhd; u++) { if (fm->hd[u].b == NULL) continue; @@ -728,12 +721,13 @@ assert(*fm->hd[u].e == '\0'); l = fm->hd[u].e - fm->hd[u].b; assert(l == strlen(fm->hd[u].b)); - memcpy(to->f, fm->hd[u].b, l); - to->hd[u].b = to->f; - to->hd[u].e = to->f + l; + memcpy(p, fm->hd[u].b, l); + to->hd[u].b = p; + to->hd[u].e = p + l; *to->hd[u].e = '\0'; - to->f += l + 1; + p += l + 1; } + /* XXX: Leave to->ws reserved for now */ to->nhd = fm->nhd; } @@ -860,7 +854,7 @@ { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - to->f = to->v; + /* XXX ??? to->f = to->v; Not sure this is valid */ to->nhd = HTTP_HDR_FIRST; memset(to->hd, 0, sizeof to->hd); } @@ -882,46 +876,45 @@ /*--------------------------------------------------------------------*/ -void -http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) +static void +http_PutField(struct http *to, int field, const char *string) { + char *e, *p; int l; CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - l = strlcpy(to->f, protocol, to->e - to->f); - xxxassert(to->f + l < to->e); - to->hd[HTTP_HDR_PROTO].b = to->f; - to->hd[HTTP_HDR_PROTO].e = to->f + l; - to->f += l + 1; + e = strchr(string, '\0'); + l = (e - string); + p = WS_Alloc(to->ws, l + 1); + memcpy(p, string, l + 1); + to->hd[field].b = p; + to->hd[field].e = p + l; +} + +void +http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) +{ + + http_PutField(to, HTTP_HDR_PROTO, protocol); WSLH(w, HTTP_T_Protocol, fd, to, HTTP_HDR_PROTO); } void http_PutStatus(struct worker *w, int fd, struct http *to, int status) { - int l; + char stat[4]; - CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - assert(status >= 100 && status <= 999); - l = snprintf(to->f, to->e - to->f, "%d", status); - xxxassert(to->f + l < to->e); - to->hd[HTTP_HDR_STATUS].b = to->f; - to->hd[HTTP_HDR_STATUS].e = to->f + l; - to->f += l + 1; + assert(status >= 0 && status <= 999); + sprintf(stat, "%d", status); + http_PutField(to, HTTP_HDR_STATUS, stat); WSLH(w, HTTP_T_Status, fd, to, HTTP_HDR_STATUS); } void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response) { - int l; - CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - l = strlcpy(to->f, response, to->e - to->f); - xxxassert(to->f + l < to->e); - to->hd[HTTP_HDR_RESPONSE].b = to->f; - to->hd[HTTP_HDR_RESPONSE].e = to->f + l; - to->f += l + 1; + http_PutField(to, HTTP_HDR_RESPONSE, response); WSLH(w, HTTP_T_Response, fd, to, HTTP_HDR_RESPONSE); } @@ -932,18 +925,18 @@ unsigned l, n; CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - l = to->e - to->f; + l = WS_Reserve(to->ws, 0); va_start(ap, fmt); - n = vsnprintf(to->f, l, fmt, ap); + n = vsnprintf(to->ws->f, l, fmt, ap); va_end(ap); - if (n >= l || to->nhd >= HTTP_HDR_MAX) { + if (n + 1 >= l || to->nhd >= HTTP_HDR_MAX) { VSL_stats->losthdr++; - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", to->f); + WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", to->ws->f); + WS_Release(to->ws, 0); } else { - assert(to->f < to->e); - to->hd[to->nhd].b = to->f; - to->hd[to->nhd].e = to->f + n; - to->f += n + 1; + to->hd[to->nhd].b = to->ws->f; + to->hd[to->nhd].e = to->ws->f + n; + WS_Release(to->ws, n + 1); WSLH(w, HTTP_T_Header, fd, to, to->nhd); to->nhd++; } Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -57,7 +57,6 @@ const char *msg; char date[40]; time_t now; - size_t len; int fd; assert(status >= 100 && status <= 999); @@ -122,11 +121,9 @@ vsb_delete(&vsb); /* allocate space for header */ - /* XXX what if the object already has a header? */ - h->v = h->s = calloc(len = 1024, 1); - XXXAN(h->s); - h->e = h->s + len; + WS_Init(h->ws, malloc(1024), 1024); + /* generate header */ http_ClrHeader(h); http_PutProtocol(w, fd, h, "HTTP/1.0"); /* XXX */ Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-04 19:08:30 UTC (rev 1497) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -284,10 +284,8 @@ if (str == NULL) str = ""; l = strlen(str); - xxxassert (sp->hash_e == sp->http->f); - xxxassert (sp->hash_e + l + 1 <= sp->http->e); + xxxassert (sp->hash_e + l + 1 <= sp->http->ws->e); memcpy(sp->hash_e, str, l); sp->hash_e[l] = '#'; sp->hash_e += l + 1; - sp->http->f += l + 1; } Added: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-06-04 19:10:16 UTC (rev 1498) @@ -0,0 +1,138 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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$ + * + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include "heritage.h" +#include "shmlog.h" +#include "vcl.h" +#include "cli_priv.h" +#include "cache.h" + +void +WS_Assert(struct ws *ws) +{ + + assert(ws != NULL); + assert(ws->s != NULL); + assert(ws->e != NULL); + assert(ws->s < ws->e); + assert(ws->f >= ws->s); + assert(ws->f <= ws->e); + if (ws->r) { + assert(ws->r > ws->s); + assert(ws->r <= ws->e); + } +} + +void +WS_Init(struct ws *ws, void *space, unsigned len) +{ + + assert(space != NULL); + memset(ws, 0, sizeof *ws); + ws->s = space; + ws->e = ws->s + len; + ws->f = ws->s; + WS_Assert(ws); +} + +void +WS_Reset(struct ws *ws) +{ + + WS_Assert(ws); + assert(ws->r == NULL); + ws->f = ws->s; +} + +char * +WS_Alloc(struct ws *ws, unsigned bytes) +{ + char *r; + + WS_Assert(ws); + assert(ws->r == NULL); + xxxassert(ws->f + bytes <= ws->e); + r = ws->f; + ws->f += bytes; + return (r); +} + +unsigned +WS_Reserve(struct ws *ws, unsigned bytes) +{ + WS_Assert(ws); + assert(ws->r == NULL); + if (bytes == 0) + bytes = ws->e - ws->f; + xxxassert(ws->f + bytes <= ws->e); + ws->r = ws->f + bytes; + return (ws->r - ws->f); +} + +void +WS_Release(struct ws *ws, unsigned bytes) +{ + WS_Assert(ws); + assert(ws->r != NULL); + assert(ws->f + bytes <= ws->r); + ws->f += bytes; + ws->r = NULL; +} + +void +WS_ReleaseP(struct ws *ws, char *ptr) +{ + WS_Assert(ws); + assert(ws->r != NULL); + assert(ptr >= ws->f); + assert(ptr <= ws->r); + ws->f = ptr; + ws->r = NULL; +} + +void +WS_Return(struct ws *ws, char *s, char *e) +{ + + WS_Assert(ws); + if (e == ws->f) + ws->f = s; +} From des at linpro.no Tue Jun 5 07:55:22 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Tue, 05 Jun 2007 09:55:22 +0200 Subject: r1498 - trunk/varnish-cache/bin/varnishd In-Reply-To: <20070604191017.1C9501EC044@projects.linpro.no> (phk@projects.linpro.no's message of "Mon\, 4 Jun 2007 21\:10\:17 +0200 \(CEST\)") References: <20070604191017.1C9501EC044@projects.linpro.no> Message-ID: <87odjuomxh.fsf@des.linpro.no> phk at projects.linpro.no writes: > Log: > Wrap the management of the session workspace in functions, to prevent > pointer gymnastics getting out of hand. Thanks, that's a relief :) DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From ssm at projects.linpro.no Tue Jun 5 15:46:08 2007 From: ssm at projects.linpro.no (ssm at projects.linpro.no) Date: Tue, 5 Jun 2007 17:46:08 +0200 (CEST) Subject: r1499 - trunk/varnish-cache/etc Message-ID: <20070605154608.0DA5F1EC525@projects.linpro.no> Author: ssm Date: 2007-06-05 17:46:07 +0200 (Tue, 05 Jun 2007) New Revision: 1499 Modified: trunk/varnish-cache/etc/zope-plone.vcl Log: * Move PURGE to a place where it does some good * Make http auth work Modified: trunk/varnish-cache/etc/zope-plone.vcl =================================================================== --- trunk/varnish-cache/etc/zope-plone.vcl 2007-06-04 19:10:16 UTC (rev 1498) +++ trunk/varnish-cache/etc/zope-plone.vcl 2007-06-05 15:46:07 UTC (rev 1499) @@ -20,25 +20,25 @@ sub vcl_recv { if (req.request != "GET" && req.request != "HEAD") { + # PURGE request if zope asks nicely + if (req.request == "PURGE") { + if (!client.ip ~ purge) { + error 405 "Not allowed."; + } + lookup; + } pipe; } if (req.http.Expect) { pipe; } - if (req.http.Authenticate) { + if (req.http.Authenticate || req.http.Authorization) { pass; } # We only care about the "__ac.*" cookies, used for authentication if (req.http.Cookie && req.http.Cookie ~ "__ac(|_(name|password|persistent))=") { pass; } - # PURGE request if zope asks nicely - if (req.request == "PURGE") { - if (!client.ip ~ purge) { - error 405 "Not allowed."; - } - lookup; - } lookup; } From des at projects.linpro.no Wed Jun 6 11:24:06 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 6 Jun 2007 13:24:06 +0200 (CEST) Subject: r1500 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish Message-ID: <20070606112406.C1B691EC041@projects.linpro.no> Author: des Date: 2007-06-06 13:24:06 +0200 (Wed, 06 Jun 2007) New Revision: 1500 Added: trunk/varnish-cache/include/vss.h trunk/varnish-cache/lib/libvarnish/vss.c Modified: trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/tcp.c trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/lib/libvarnish/Makefile.am Log: Move parts of tcp.c out into libvarnish. Rename the API from "TCP" to "VSS" (Varnish Stream Sockets) as I intend to eventually add support for AF_UNIX sockets. This also moves the accept filter code out from VSS_listen() (previously TCP_open()) and into a separate function in tcp.c Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/common.h 2007-06-06 11:24:06 UTC (rev 1500) @@ -45,6 +45,4 @@ void TCP_name(struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen); void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen); -int TCP_parse(const char *str, char **addr, char **port); -int TCP_resolve(const char *addr, const char *port, struct tcp_addr ***ta); -int TCP_open(const struct tcp_addr *addr, int http); +int TCP_filter_http(int sock); Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-06 11:24:06 UTC (rev 1500) @@ -36,7 +36,7 @@ struct listen_sock { TAILQ_ENTRY(listen_sock) list; int sock; - struct tcp_addr *addr; + struct vss_addr *addr; }; TAILQ_HEAD(listen_sock_head, listen_sock); Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -54,6 +54,7 @@ #include "cli_priv.h" #include "mgt_cli.h" #include "mgt_event.h" +#include "vss.h" pid_t mgt_pid; pid_t child_pid = -1; @@ -130,7 +131,8 @@ TAILQ_FOREACH(ls, &heritage.socks, list) { if (ls->sock >= 0) continue; - ls->sock = TCP_open(ls->addr, 1); + ls->sock = VSS_listen(ls->addr, params->listen_depth); + TCP_filter_http(ls->sock); if (ls->sock < 0) return (1); } Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -54,6 +54,8 @@ #include "mgt_event.h" #include "shmlog.h" +#include "vss.h" + static int cli_i = -1, cli_o = -1; /*--------------------------------------------------------------------*/ @@ -389,12 +391,12 @@ int mgt_cli_telnet(const char *T_arg) { - struct tcp_addr **ta; + struct vss_addr **ta; char *addr, *port; int i, n; - XXXAZ(TCP_parse(T_arg, &addr, &port)); - XXXAN(n = TCP_resolve(addr, port, &ta)); + XXXAZ(VSS_parse(T_arg, &addr, &port)); + XXXAN(n = VSS_resolve(addr, port, &ta)); free(addr); free(port); if (n == 0) { @@ -402,7 +404,7 @@ exit(2); } for (i = 0; i < n; ++i) { - int sock = TCP_open(ta[i], 0); + int sock = VSS_listen(ta[i], 1); struct ev *ev = ev_new(); XXXAN(ev); ev->fd = sock; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -47,6 +47,8 @@ #include "heritage.h" +#include "vss.h" + struct parspec; typedef void tweak_t(struct cli *, struct parspec *, const char *arg); @@ -392,16 +394,16 @@ } TAILQ_INIT(&lsh); for (i = 1; av[i] != NULL; i++) { - struct tcp_addr **ta; + struct vss_addr **ta; char *host, *port; int j, n; - if (TCP_parse(av[i], &host, &port) != 0) { + if (VSS_parse(av[i], &host, &port) != 0) { cli_out(cli, "Invalid listen address \"%s\"", av[i]); cli_result(cli, CLIS_PARAM); break; } - n = TCP_resolve(host, port ? port : "http", &ta); + n = VSS_resolve(host, port ? port : "http", &ta); free(host); free(port); if (n == 0) { Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -53,6 +53,8 @@ #include "mgt.h" #include "mgt_cli.h" +#include "vss.h" + struct vclprog { TAILQ_ENTRY(vclprog) list; char *name; @@ -320,7 +322,7 @@ * XXX: a bug for a backend to not reply at that time, so then * XXX: again: we should check it here in the "trivial" case. */ - if (TCP_parse(b_arg, &addr, &port) != 0 || addr == NULL) { + if (VSS_parse(b_arg, &addr, &port) != 0 || addr == NULL) { fprintf(stderr, "invalid backend address\n"); return (1); } Modified: trunk/varnish-cache/bin/varnishd/tcp.c =================================================================== --- trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -53,15 +53,6 @@ #include "cli.h" #include "cli_priv.h" -/* lightweight addrinfo */ -struct tcp_addr { - int ta_family; - int ta_socktype; - int ta_protocol; - socklen_t ta_addrlen; - struct sockaddr_storage ta_addr; -}; - /*--------------------------------------------------------------------*/ void @@ -100,166 +91,25 @@ /*--------------------------------------------------------------------*/ -#ifdef HAVE_ACCEPT_FILTERS -static void -accept_filter(int fd) +int +TCP_filter_http(int sock) { +#ifdef HAVE_ACCEPT_FILTERS struct accept_filter_arg afa; int i; bzero(&afa, sizeof(afa)); strcpy(afa.af_name, "httpready"); errno = 0; - i = setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, + i = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)); + /* XXX ugly */ if (i) printf("Acceptfilter(%d, httpready): %d %s\n", - fd, i, strerror(errno)); -} -#endif - -/* - * Take a string provided by the user and break it up into address and - * port parts. Examples of acceptable input include: - * - * "localhost" - "localhost:80" - * "127.0.0.1" - "127.0.0.1:80" - * "0.0.0.0" - "0.0.0.0:80" - * "[::1]" - "[::1]:80" - * "[::]" - "[::]:80" - */ -int -TCP_parse(const char *str, char **addr, char **port) -{ - const char *p; - - *addr = *port = NULL; - - if (str[0] == '[') { - /* IPv6 address of the form [::1]:80 */ - if ((p = strchr(str, ']')) == NULL || - p == str + 1 || - (p[1] != '\0' && p[1] != ':')) - return (-1); - *addr = strndup(str + 1, p - (str + 1)); - XXXAN(*addr); - if (p[1] == ':') { - *port = strdup(p + 2); - XXXAN(*port); - } - } else { - /* IPv4 address of the form 127.0.0.1:80, or non-numeric */ - p = strchr(str, ':'); - if (p == NULL) { - *addr = strdup(str); - XXXAN(*addr); - } else { - if (p > str) { - *addr = strndup(str, p - str); - XXXAN(*addr); - } - *port = strdup(p + 1); - XXXAN(*port); - } - } - return (0); -} - -/* - * For a given host and port, return a list of struct tcp_addr, which - * contains all the information necessary to open and bind a socket. One - * tcp_addr is returned for each distinct address returned by - * getaddrinfo(). - * - * The value pointed to by the tap parameter receives a pointer to an - * array of pointers to struct tcp_addr. The caller is responsible for - * freeing each individual struct tcp_addr as well as the array. - * - * The return value is the number of addresses resoved, or zero. - */ -int -TCP_resolve(const char *addr, const char *port, struct tcp_addr ***tap) -{ - struct addrinfo hints, *res0, *res; - struct tcp_addr **ta; - int i, ret; - - memset(&hints, 0, sizeof hints); - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - ret = getaddrinfo(addr, port, &hints, &res0); - if (ret != 0) { - fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(ret)); - return (0); - } - for (res = res0, i = 0; res != NULL; res = res->ai_next) - ++i; - ta = calloc(i, sizeof *ta); - XXXAN(ta); - *tap = ta; - for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { - ta[i] = calloc(1, sizeof *ta[i]); - XXXAN(ta[i]); - ta[i]->ta_family = res->ai_family; - ta[i]->ta_socktype = res->ai_socktype; - ta[i]->ta_protocol = res->ai_protocol; - ta[i]->ta_addrlen = res->ai_addrlen; - xxxassert(ta[i]->ta_addrlen <= sizeof ta[i]->ta_addr); - memcpy(&ta[i]->ta_addr, res->ai_addr, ta[i]->ta_addrlen); - } - freeaddrinfo(res0); + sock, i, strerror(errno)); return (i); -} - -/* - * Given a struct tcp_addr, open a socket of the appropriate type, bind it - * to the requested address, and start listening. - * - * If the address is an IPv6 address, the IPV6_V6ONLY option is set to - * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. - * - * If the http parameter is non-zero and accept filters are available, - * install an HTTP accept filter on the socket. - */ -int -TCP_open(const struct tcp_addr *ta, int http) -{ - int sd, val; - - sd = socket(ta->ta_family, ta->ta_socktype, ta->ta_protocol); - if (sd < 0) { - perror("socket()"); - return (-1); - } - val = 1; - if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val) != 0) { - perror("setsockopt(SO_REUSEADDR, 1)"); - close(sd); - return (-1); - } -#ifdef IPV6_V6ONLY - /* forcibly use separate sockets for IPv4 and IPv6 */ - val = 1; - if (ta->ta_family == AF_INET6 && - setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof val) != 0) { - perror("setsockopt(IPV6_V6ONLY, 1)"); - close(sd); - return (-1); - } +#else + (void)sock; + return (0); #endif - if (bind(sd, (const struct sockaddr *)&ta->ta_addr, ta->ta_addrlen) != 0) { - perror("bind()"); - close(sd); - return (-1); - } - if (listen(sd, http ? params->listen_depth : 16) != 0) { - perror("listen()"); - close(sd); - return (-1); - } -#ifdef HAVE_ACCEPT_FILTERS - if (http) - accept_filter(sd); -#endif - return (sd); } Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/include/Makefile.am 2007-06-06 11:24:06 UTC (rev 1500) @@ -30,5 +30,5 @@ vcl.h \ vcl_returns.h \ vrt.h \ - vrt_obj.h - + vrt_obj.h \ + vss.h Added: trunk/varnish-cache/include/vss.h =================================================================== --- trunk/varnish-cache/include/vss.h (rev 0) +++ trunk/varnish-cache/include/vss.h 2007-06-06 11:24:06 UTC (rev 1500) @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * 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 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$ + */ + +/* vss.c */ +struct vss_addr; + +int VSS_parse(const char *str, char **addr, char **port); +int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); +int VSS_listen(const struct vss_addr *addr, int depth); +int VSS_connect(const struct vss_addr *addr); Property changes on: trunk/varnish-cache/include/vss.h ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvarnish/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnish/Makefile.am 2007-06-05 15:46:07 UTC (rev 1499) +++ trunk/varnish-cache/lib/libvarnish/Makefile.am 2007-06-06 11:24:06 UTC (rev 1500) @@ -15,6 +15,7 @@ time.c \ version.c \ vpf.c \ - vsb.c + vsb.c \ + vss.c libvarnish_la_CFLAGS = -include config.h Added: trunk/varnish-cache/lib/libvarnish/vss.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vss.c (rev 0) +++ trunk/varnish-cache/lib/libvarnish/vss.c 2007-06-06 11:24:06 UTC (rev 1500) @@ -0,0 +1,223 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Sm?rgrav + * Author: Cecilie Fritzvold + * + * 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. + * + * $Id$ + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#ifndef HAVE_STRLCPY +#include "compat/strlcpy.h" +#endif +#ifndef HAVE_STRNDUP +#include "compat/strndup.h" +#endif + +#include "libvarnish.h" +#include "vss.h" + +/* lightweight addrinfo */ +struct vss_addr { + int va_family; + int va_socktype; + int va_protocol; + socklen_t va_addrlen; + struct sockaddr_storage va_addr; +}; + +/* + * Take a string provided by the user and break it up into address and + * port parts. Examples of acceptable input include: + * + * "localhost" - "localhost:80" + * "127.0.0.1" - "127.0.0.1:80" + * "0.0.0.0" - "0.0.0.0:80" + * "[::1]" - "[::1]:80" + * "[::]" - "[::]:80" + */ +int +VSS_parse(const char *str, char **addr, char **port) +{ + const char *p; + + *addr = *port = NULL; + + if (str[0] == '[') { + /* IPv6 address of the form [::1]:80 */ + if ((p = strchr(str, ']')) == NULL || + p == str + 1 || + (p[1] != '\0' && p[1] != ':')) + return (-1); + *addr = strndup(str + 1, p - (str + 1)); + XXXAN(*addr); + if (p[1] == ':') { + *port = strdup(p + 2); + XXXAN(*port); + } + } else { + /* IPv4 address of the form 127.0.0.1:80, or non-numeric */ + p = strchr(str, ':'); + if (p == NULL) { + *addr = strdup(str); + XXXAN(*addr); + } else { + if (p > str) { + *addr = strndup(str, p - str); + XXXAN(*addr); + } + *port = strdup(p + 1); + XXXAN(*port); + } + } + return (0); +} + +/* + * For a given host and port, return a list of struct vss_addr, which + * contains all the information necessary to open and bind a socket. One + * vss_addr is returned for each distinct address returned by + * getaddrinfo(). + * + * The value pointed to by the tap parameter receives a pointer to an + * array of pointers to struct vss_addr. The caller is responsible for + * freeing each individual struct vss_addr as well as the array. + * + * The return value is the number of addresses resoved, or zero. + */ +int +VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) +{ + struct addrinfo hints, *res0, *res; + struct vss_addr **va; + int i, ret; + + memset(&hints, 0, sizeof hints); + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + ret = getaddrinfo(addr, port, &hints, &res0); + if (ret != 0) { + fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(ret)); + return (0); + } + for (res = res0, i = 0; res != NULL; res = res->ai_next) + ++i; + va = calloc(i, sizeof *va); + XXXAN(va); + *vap = va; + for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { + va[i] = calloc(1, sizeof *va[i]); + XXXAN(va[i]); + va[i]->va_family = res->ai_family; + va[i]->va_socktype = res->ai_socktype; + va[i]->va_protocol = res->ai_protocol; + va[i]->va_addrlen = res->ai_addrlen; + xxxassert(va[i]->va_addrlen <= sizeof va[i]->va_addr); + memcpy(&va[i]->va_addr, res->ai_addr, va[i]->va_addrlen); + } + freeaddrinfo(res0); + return (i); +} + +/* + * Given a struct vss_addr, open a socket of the appropriate type, bind it + * to the requested address, and start listening. + * + * If the address is an IPv6 address, the IPV6_V6ONLY option is set to + * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. + */ +int +VSS_listen(const struct vss_addr *va, int depth) +{ + int sd, val; + + sd = socket(va->va_family, va->va_socktype, va->va_protocol); + if (sd < 0) { + perror("socket()"); + return (-1); + } + val = 1; + if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val) != 0) { + perror("setsockopt(SO_REUSEADDR, 1)"); + close(sd); + return (-1); + } +#ifdef IPV6_V6ONLY + /* forcibly use separate sockets for IPv4 and IPv6 */ + val = 1; + if (va->va_family == AF_INET6 && + setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof val) != 0) { + perror("setsockopt(IPV6_V6ONLY, 1)"); + close(sd); + return (-1); + } +#endif + if (bind(sd, (const struct sockaddr *)&va->va_addr, va->va_addrlen) != 0) { + perror("bind()"); + close(sd); + return (-1); + } + if (listen(sd, depth) != 0) { + perror("listen()"); + close(sd); + return (-1); + } + return (sd); +} + +/* + * Connect to the socket specified by the address info in va. + * Return the socket. + */ +int +VSS_connect(const struct vss_addr *va) +{ + int sd; + + sd = socket(va->va_family, va->va_socktype, va->va_protocol); + if (sd < 0) { + perror("socket()"); + return (-1); + } + if (connect(sd, (const struct sockaddr *)&va->va_addr, va->va_addrlen) != 0) { + perror("connect()"); + close(sd); + return (-1); + } + return (sd); +} Property changes on: trunk/varnish-cache/lib/libvarnish/vss.c ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Wed Jun 6 15:25:54 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 6 Jun 2007 17:25:54 +0200 (CEST) Subject: r1501 - trunk/varnish-cache/bin/varnishd Message-ID: <20070606152554.D60701EC864@projects.linpro.no> Author: des Date: 2007-06-06 17:25:54 +0200 (Wed, 06 Jun 2007) New Revision: 1501 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/varnishd.c Log: Revert part of r1484, I got it exactly backwards. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-06 11:24:06 UTC (rev 1500) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-06 15:25:54 UTC (rev 1501) @@ -121,7 +121,7 @@ unsigned ping_interval; }; -extern struct params * volatile params; +extern volatile struct params *params; extern struct heritage heritage; void child_main(void); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-06 11:24:06 UTC (rev 1500) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-06 15:25:54 UTC (rev 1501) @@ -66,7 +66,7 @@ #endif struct heritage heritage; -struct params * volatile params; +volatile struct params *params; /*--------------------------------------------------------------------*/ From cecilihf at projects.linpro.no Thu Jun 7 09:00:57 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Thu, 7 Jun 2007 11:00:57 +0200 (CEST) Subject: r1502 - in trunk/varnish-cache/bin: . varnishadm Message-ID: <20070607090057.659D91ED4C0@projects.linpro.no> Author: cecilihf Date: 2007-06-07 11:00:56 +0200 (Thu, 07 Jun 2007) New Revision: 1502 Added: trunk/varnish-cache/bin/varnishadm/ trunk/varnish-cache/bin/varnishadm/Makefile.am trunk/varnish-cache/bin/varnishadm/varnishadm.1 trunk/varnish-cache/bin/varnishadm/varnishadm.c Log: Added a utility for sending a single command to varnishd via telnet, and printing the result. Property changes on: trunk/varnish-cache/bin/varnishadm ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile Makefile.in varnishadm Added: trunk/varnish-cache/bin/varnishadm/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishadm/Makefile.am (rev 0) +++ trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-06-07 09:00:56 UTC (rev 1502) @@ -0,0 +1,17 @@ +# $Id$ + +INCLUDES = -I$(top_srcdir)/include + +bin_PROGRAMS = varnishadm + +dist_man_MANS = varnishadm.1 + +varnishadm_SOURCES = \ + varnishadm.c + +varnishadm_CFLAGS = -include config.h + +varnishadm_LDADD = \ + $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnish/libvarnish.la + Property changes on: trunk/varnish-cache/bin/varnishadm/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-cache/bin/varnishadm/varnishadm.1 =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.1 (rev 0) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.1 2007-06-07 09:00:56 UTC (rev 1502) @@ -0,0 +1,72 @@ +.\"- +.\" Copyright (c) 2006 Verdens Gang AS +.\" Copyright (c) 2006 Linpro AS +.\" All rights reserved. +.\" +.\" Author: Cecilie Fritzvold +.\" +.\" 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. +.\" +.\" $Id$ +.\" +.Dd June 06, 2007 +.Dt VARNISHADM 1 +.Os +.Sh NAME +.Nm varnishadm +.Sh SYNOPSIS +.Nm +.Fl T Ar address:port +.Sh DESCRIPTION +The +.Nm +utility sends the given command to the +.Xr varnishd 1 +instance at address:port and prints the results. 0 is returned on success, 1 +on failure. +.Pp +The following options are available: +.Bl -tag -width Fl +.It Fl T Ar address:port +Connect via telnet to this address and port. +.Sh EXAMPLES +The following command lists all available commands provided by the +management interface of +.Ed +.Xr varnishd 1 +.Bd -literal -offset 4n +$ varnishadm -T 127.0.0.1:23 help +.Ed +.Sh SEE ALSO +.Xr varnishd 1 , +.Xr varnishhist 1 , +.Xr varnishncsa 1 , +.Xr varnishstat 1 , +.Xr varnishtop 1 +.Sh HISTORY +The +.Nm +utility was developed by +.An Cecilie Fritzvold Aq cecilihf at linpro.no . + +This manual page was written by +.An Cecilie Fritzvold Aq cecilihf at linpro.no . Added: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c (rev 0) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-06-07 09:00:56 UTC (rev 1502) @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * All rights reserved. + * + * Author: Cecilie Fritzvold + * + * 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$ + */ + +#include +#include +#include +#include + +#include "libvarnish.h" +#include "vss.h" + +#define STATUS_OK 200 + +/* + * This function establishes a connection to the specified ip and port and + * sends a command to varnishd. If varnishd returns an OK status, the result + * is printed and 0 returned. Else, an error message is printed and 1 is + * returned + */ +static void +telnet_mgt(const char* T_arg, int argc, char* argv[]) +{ + struct vss_addr **ta; + char *addr, *port; + int i, n; + long status, bytes; + char *answer = NULL; + char buf[13]; + char *p, *pp; + + XXXAZ(VSS_parse(T_arg, &addr, &port)); + XXXAN(n = VSS_resolve(addr, port, &ta)); + free(addr); + free(port); + if (n == 0) { + fprintf(stderr, "Could not open TELNET port\n"); + exit(2); + } + + int sock = VSS_connect(ta[0]); + + for (i = 0; i < n; ++i) { + free(ta[i]); + ta[i] = NULL; + } + free(ta); + + for (i=0; i 0) + write(sock, " ", 1); + write(sock, argv[i], strlen(argv[i])); + } + write(sock, "\n", 1); + + n = read(sock, buf, 13); + if (n != 13) { + fprintf(stderr, "An error occured in receiving status.\n"); + exit(1); + } + if (!(p = strchr(buf, ' '))) { + fprintf(stderr, "An error occured in parsing of status code.\n"); + exit(1); + } + *p = '\0'; + status = strtol(buf, &p, 10); + pp = p+1; + if (!(p = strchr(pp, '\n'))) { + fprintf(stderr, "An error occured in parsing of number of bytes returned.\n"); + exit(1); + } + *p = '\0'; + bytes = strtol(pp, &p, 10); + + answer = malloc(bytes+1); + n = read(sock, answer, bytes); + if (n != bytes) { + fprintf(stderr, "An error occured in receiving answer.\n"); + exit(1); + } + answer[bytes] = '\0'; + close(sock); + + if (status == STATUS_OK) { + printf("%s\n", answer); + exit(0); + } + fprintf(stderr, "Command failed with error code %ld\n", status); + exit(1); + +} + +static void +usage(void) +{ + fprintf(stderr, "usage: varnishadm -T address:port \n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + int c; + const char *address = NULL; + int T_arg = 0; + + if (argc < 2) + usage(); + + while ((c = getopt(argc, argv, "T:")) != -1) { + switch (c) { + case 'T': + T_arg = 1; + address = optarg; + break; + default: + usage(); + } + } + + if (T_arg) { + if (optind == argc) + usage(); + telnet_mgt(address, argc - optind, &argv[optind]); + } + + exit(0); +} From des at projects.linpro.no Thu Jun 7 09:40:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 7 Jun 2007 11:40:21 +0200 (CEST) Subject: r1503 - in trunk/varnish-cache: . bin/varnishadm bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishstat bin/varnishtop include include/compat lib/libcompat lib/libvarnish lib/libvarnishapi lib/libvcl man Message-ID: <20070607094021.133271EC83F@projects.linpro.no> Author: des Date: 2007-06-07 11:40:20 +0200 (Thu, 07 Jun 2007) New Revision: 1503 Modified: trunk/varnish-cache/LICENSE trunk/varnish-cache/bin/varnishadm/varnishadm.1 trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_acceptor.h trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_pipe.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_vcl.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c trunk/varnish-cache/bin/varnishd/cache_vrt_re.c trunk/varnish-cache/bin/varnishd/cache_ws.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_simple_list.c trunk/varnish-cache/bin/varnishd/hash_slinger.h trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_cli.h trunk/varnish-cache/bin/varnishd/mgt_event.c trunk/varnish-cache/bin/varnishd/mgt_event.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/rfc2616.c trunk/varnish-cache/bin/varnishd/shmlog.c trunk/varnish-cache/bin/varnishd/steps.h trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/tcp.c trunk/varnish-cache/bin/varnishd/varnishd.1 trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishhist/varnishhist.1 trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.1 trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishstat/varnishstat.1 trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtop/varnishtop.1 trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/configure.ac trunk/varnish-cache/include/binary_heap.h trunk/varnish-cache/include/cli.h trunk/varnish-cache/include/cli_common.h trunk/varnish-cache/include/cli_priv.h trunk/varnish-cache/include/compat/asprintf.h trunk/varnish-cache/include/compat/clock_gettime.h trunk/varnish-cache/include/compat/setproctitle.h trunk/varnish-cache/include/compat/srandomdev.h trunk/varnish-cache/include/compat/strlcat.h trunk/varnish-cache/include/compat/strlcpy.h trunk/varnish-cache/include/compat/strndup.h trunk/varnish-cache/include/compat/vasprintf.h trunk/varnish-cache/include/http_headers.h trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/include/libvcl.h trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/shmlog_tags.h trunk/varnish-cache/include/stat_field.h trunk/varnish-cache/include/stats.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/include/vrt.h trunk/varnish-cache/include/vss.h trunk/varnish-cache/lib/libcompat/asprintf.c trunk/varnish-cache/lib/libcompat/clock_gettime.c trunk/varnish-cache/lib/libcompat/setproctitle.c trunk/varnish-cache/lib/libcompat/srandomdev.c trunk/varnish-cache/lib/libcompat/strndup.c trunk/varnish-cache/lib/libcompat/vasprintf.c trunk/varnish-cache/lib/libvarnish/argv.c trunk/varnish-cache/lib/libvarnish/assert.c trunk/varnish-cache/lib/libvarnish/binary_heap.c trunk/varnish-cache/lib/libvarnish/cli.c trunk/varnish-cache/lib/libvarnish/cli_common.c trunk/varnish-cache/lib/libvarnish/crc32.c trunk/varnish-cache/lib/libvarnish/time.c trunk/varnish-cache/lib/libvarnish/version.c trunk/varnish-cache/lib/libvarnish/vss.c trunk/varnish-cache/lib/libvarnishapi/shmlog.c trunk/varnish-cache/lib/libvcl/vcc_acl.c trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_priv.h trunk/varnish-cache/lib/libvcl/vcc_token.c trunk/varnish-cache/lib/libvcl/vcc_xref.c trunk/varnish-cache/man/vcl.7 Log: Update the Linpro copyright. Modified: trunk/varnish-cache/LICENSE =================================================================== --- trunk/varnish-cache/LICENSE 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/LICENSE 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,5 +1,5 @@ Copyright (c) 2006 Verdens Gang AS -Copyright (c) 2006 Linpro AS +Copyright (c) 2006-2007 Linpro AS All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1 =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Cecilie Fritzvold Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Cecilie Fritzvold Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/common.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_event.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_event.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/steps.h =================================================================== --- trunk/varnish-cache/bin/varnishd/steps.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/steps.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/tcp.c =================================================================== --- trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.1 =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.1 =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Anders Berg Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.1 =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/configure.ac 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,7 +1,7 @@ # $Id$ AC_PREREQ(2.59) -AC_COPYRIGHT([Copyright (c) 2006 Linpro AS / Verdens Gang AS]) +AC_COPYRIGHT([Copyright (c) 2006-2007 Linpro AS / Verdens Gang AS]) AC_REVISION([$Id$]) AC_INIT([Varnish], [trunk], [varnish-dev at projects.linpro.no]) AC_CONFIG_SRCDIR(include/varnishapi.h) Modified: trunk/varnish-cache/include/binary_heap.h =================================================================== --- trunk/varnish-cache/include/binary_heap.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/binary_heap.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/cli.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/cli_common.h =================================================================== --- trunk/varnish-cache/include/cli_common.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/cli_common.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/cli_priv.h =================================================================== --- trunk/varnish-cache/include/cli_priv.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/cli_priv.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/compat/asprintf.h =================================================================== --- trunk/varnish-cache/include/compat/asprintf.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/asprintf.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/clock_gettime.h =================================================================== --- trunk/varnish-cache/include/compat/clock_gettime.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/clock_gettime.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/setproctitle.h =================================================================== --- trunk/varnish-cache/include/compat/setproctitle.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/setproctitle.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/srandomdev.h =================================================================== --- trunk/varnish-cache/include/compat/srandomdev.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/srandomdev.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/strlcat.h =================================================================== --- trunk/varnish-cache/include/compat/strlcat.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/strlcat.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/strlcpy.h =================================================================== --- trunk/varnish-cache/include/compat/strlcpy.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/strlcpy.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/strndup.h =================================================================== --- trunk/varnish-cache/include/compat/strndup.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/strndup.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/compat/vasprintf.h =================================================================== --- trunk/varnish-cache/include/compat/vasprintf.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/compat/vasprintf.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/include/http_headers.h =================================================================== --- trunk/varnish-cache/include/http_headers.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/http_headers.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/libvarnish.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/libvcl.h =================================================================== --- trunk/varnish-cache/include/libvcl.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/libvcl.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/shmlog.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/shmlog_tags.h =================================================================== --- trunk/varnish-cache/include/shmlog_tags.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/shmlog_tags.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/stat_field.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/stats.h =================================================================== --- trunk/varnish-cache/include/stats.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/stats.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/varnishapi.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/vrt.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/include/vss.h =================================================================== --- trunk/varnish-cache/include/vss.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/include/vss.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-cache/lib/libcompat/asprintf.c =================================================================== --- trunk/varnish-cache/lib/libcompat/asprintf.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/asprintf.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libcompat/clock_gettime.c =================================================================== --- trunk/varnish-cache/lib/libcompat/clock_gettime.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/clock_gettime.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libcompat/setproctitle.c =================================================================== --- trunk/varnish-cache/lib/libcompat/setproctitle.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/setproctitle.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libcompat/srandomdev.c =================================================================== --- trunk/varnish-cache/lib/libcompat/srandomdev.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/srandomdev.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libcompat/strndup.c =================================================================== --- trunk/varnish-cache/lib/libcompat/strndup.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/strndup.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libcompat/vasprintf.c =================================================================== --- trunk/varnish-cache/lib/libcompat/vasprintf.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libcompat/vasprintf.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libvarnish/argv.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/argv.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/argv.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/assert.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/assert.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/assert.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/binary_heap.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/binary_heap.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/binary_heap.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/cli.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/cli.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/crc32.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/crc32.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/crc32.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/time.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/time.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/time.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvarnish/version.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/version.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/version.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav @@ -40,5 +40,5 @@ { fprintf(stderr, "%s (%s-%s)\n", progname, PACKAGE_TARNAME, PACKAGE_VERSION); - fprintf(stderr, "Copyright (c) 2006 Linpro AS / Verdens Gang AS\n"); + fprintf(stderr, "Copyright (c) 2006-2007 Linpro AS / Verdens Gang AS\n"); } Modified: trunk/varnish-cache/lib/libvarnish/vss.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vss.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnish/vss.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Dag-Erling Sm?rgrav Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -353,7 +353,7 @@ vsb_cat(sb, "};\n"); vsb_cat(sb, "/*-\n"); vsb_cat(sb, " * Copyright (c) 2006 Verdens Gang AS\n"); - vsb_cat(sb, " * Copyright (c) 2006 Linpro AS\n"); + vsb_cat(sb, " * Copyright (c) 2006-2007 Linpro AS\n"); vsb_cat(sb, " * All rights reserved.\n"); vsb_cat(sb, " *\n"); vsb_cat(sb, " * Author: Poul-Henning Kamp \n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,7 +1,7 @@ #!/usr/local/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,7 +1,7 @@ #!/usr/local/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_priv.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_priv.h 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_priv.h 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS + * Copyright (c) 2006-2007 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-06-07 09:00:56 UTC (rev 1502) +++ trunk/varnish-cache/man/vcl.7 2007-06-07 09:40:20 UTC (rev 1503) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006 Linpro AS +.\" Copyright (c) 2006-2007 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav From des at linpro.no Thu Jun 7 10:43:02 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu, 07 Jun 2007 12:43:02 +0200 Subject: r1458 - in tags: . varnish-1.0.4 In-Reply-To: <20070520173816.0D7971EC2A2@projects.linpro.no> (des@projects.linpro.no's message of "Sun\, 20 May 2007 19\:38\:16 +0200 \(CEST\)") References: <20070520173816.0D7971EC2A2@projects.linpro.no> Message-ID: <87zm3ckpu1.fsf@des.linpro.no> des at projects.linpro.no writes: > Added: > tags/varnish-1.0.4/ > tags/varnish-1.0.4/debian/ > Removed: > tags/varnish-1.0.4/debian/ > Log: > Tag 1.0.4. I apparently screwed up this commit - the tarball on Sourceforge is fine, but some of the debian files are missing in the repo. I'll see what I can do to fix it next week, when I'm a little less busy... DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From phk at projects.linpro.no Sun Jun 10 07:19:21 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 10 Jun 2007 09:19:21 +0200 (CEST) Subject: r1504 - in trunk/varnish-cache/bin: varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop Message-ID: <20070610071921.B65AF1EC525@projects.linpro.no> Author: phk Date: 2007-06-10 09:19:21 +0200 (Sun, 10 Jun 2007) New Revision: 1504 Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishhist/Makefile.am trunk/varnish-cache/bin/varnishlog/Makefile.am trunk/varnish-cache/bin/varnishncsa/Makefile.am trunk/varnish-cache/bin/varnishstat/Makefile.am trunk/varnish-cache/bin/varnishtop/Makefile.am Log: libcompat must come after libvarnish because the latter now uses strndup which might come from the former. Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -12,6 +12,6 @@ varnishadm_CFLAGS = -include config.h varnishadm_LDADD = \ - $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la + $(top_builddir)/lib/libvarnish/libvarnish.la \ + $(top_builddir)/lib/libcompat/libcompat.a Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -61,7 +61,7 @@ varnishd_LDFLAGS = -export-dynamic varnishd_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvcl/libvcl.la \ ${DL_LIBS} ${RT_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -11,8 +11,8 @@ varnishhist_CFLAGS = -include config.h varnishhist_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ ${CURSES_LIBS} Modified: trunk/varnish-cache/bin/varnishlog/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishlog/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishlog/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -11,6 +11,6 @@ varnishlog_CFLAGS = -include config.h varnishlog_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: trunk/varnish-cache/bin/varnishncsa/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishncsa/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishncsa/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -11,6 +11,6 @@ varnishncsa_CFLAGS = -include config.h varnishncsa_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishstat/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishstat/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -11,7 +11,7 @@ varnishstat_CFLAGS = -include config.h varnishstat_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${RT_LIBS} Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-06-07 09:40:20 UTC (rev 1503) +++ trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-06-10 07:19:21 UTC (rev 1504) @@ -11,7 +11,7 @@ varnishtop_CFLAGS = -include config.h varnishtop_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} From phk at projects.linpro.no Sun Jun 10 07:47:51 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 10 Jun 2007 09:47:51 +0200 (CEST) Subject: r1505 - trunk/varnish-cache/bin/varnishd Message-ID: <20070610074751.105DE1EC035@projects.linpro.no> Author: phk Date: 2007-06-10 09:47:50 +0200 (Sun, 10 Jun 2007) New Revision: 1505 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Fix a bug I introduced in the workspace rewamp: Don't throw away perfectly good pipelined data. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-10 07:19:21 UTC (rev 1504) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-10 07:47:50 UTC (rev 1505) @@ -361,7 +361,8 @@ b += u; len -= u; } - hp->pl_s = hp->pl_e = NULL; + if (hp->pl_e == hp->pl_s) + hp->pl_s = hp->pl_e = NULL; if (len > 0) { i = read(fd, b, len); if (i < 0) From phk at projects.linpro.no Sun Jun 10 08:49:43 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 10 Jun 2007 10:49:43 +0200 (CEST) Subject: r1506 - trunk/varnish-cache/bin/varnishd Message-ID: <20070610084943.D8DC31EC041@projects.linpro.no> Author: phk Date: 2007-06-10 10:49:43 +0200 (Sun, 10 Jun 2007) New Revision: 1506 Added: trunk/varnish-cache/bin/varnishd/cache_vary.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Take a shot at light-weight "Vary:" processing. When we cache an object with a "Vary:" header, we generate a "vary matching string" which can be used to efficiently check for compliance when doing a cache lookup. Only very lightly tested (ie: cnn.com). For a full description of the reasoning, please see http://varnish.projects.linpro.no/wiki/ArchitectureVary Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-10 07:47:50 UTC (rev 1505) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-10 08:49:43 UTC (rev 1506) @@ -25,6 +25,7 @@ cache_response.c \ cache_session.c \ cache_synthetic.c \ + cache_vary.c \ cache_vcl.c \ cache_vrt.c \ cache_vrt_acl.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-10 07:47:50 UTC (rev 1505) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-10 08:49:43 UTC (rev 1506) @@ -225,6 +225,8 @@ unsigned xid; struct objhead *objhead; + unsigned char *vary; + unsigned heap_idx; unsigned ban_seq; @@ -463,6 +465,10 @@ /* cache_synthetic.c */ void SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl); +/* cache_vary.c */ +void VRY_Create(struct sess *sp); +int VRY_Match(struct sess *sp, unsigned char *vary); + /* cache_vcl.c */ void VCL_Init(void); void VCL_Refresh(struct VCL_conf **vcc); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-10 07:47:50 UTC (rev 1505) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-06-10 08:49:43 UTC (rev 1506) @@ -298,6 +298,7 @@ sp->obj->cacheable = 1; if (sp->obj->objhead != NULL) { + VRY_Create(sp); HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */ HSH_Unbusy(sp->obj); } Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-10 07:47:50 UTC (rev 1505) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-10 08:49:43 UTC (rev 1506) @@ -148,7 +148,6 @@ return (NULL); } were_back: - /* XXX: check Vary: */ if (!o->cacheable) { /* ignore */ } else if (o->ttl == 0) { @@ -159,7 +158,7 @@ o->ttl = 0; VSL(SLT_ExpBan, 0, "%u was banned", o->xid); EXP_TTLchange(o); - } else + } else if (VRY_Match(sp, o->vary)) break; o->refcnt--; } @@ -254,6 +253,9 @@ if (o->http.ws->s != NULL) free(o->http.ws->s); + if (o->vary != NULL) + free(o->vary); + HSH_Freestore(o); free(o); VSL_stats->n_object--; Added: trunk/varnish-cache/bin/varnishd/cache_vary.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vary.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_vary.c 2007-06-10 08:49:43 UTC (rev 1506) @@ -0,0 +1,176 @@ +/*- + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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. + * + * $Id$ + * + * Do Vary processing. + * + * When we insert an object into the cache which has a Vary: header, + * we encode a vary matching string containing the headers mentioned + * and their value. + * + * When we match an object in the cache, we check the present request + * against the vary matching string. + * + * The only kind of header-munging we do is leading & trailing space + * removal. All the potential "q=foo" gymnastics is not worth the + * effort. + * + * The vary matching string has the following format: + * + * Sequence of: { + * \ + *
\ Same format as argument to http_GetHdr() + * ':' / + * '\0' / + * \ Length of header contents. + * / + *
Only present if length != 0xffff + * } + * '\0' + */ + +#include +#include +#include + +#include "cache.h" + +void +VRY_Create(struct sess *sp) +{ + char *v, *p, *q, *h, *e; + struct vsb *sb, *sbh; + unsigned l; + + /* For vary matching string */ + sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); + AN(sb); + + /* For header matching strings */ + sbh = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); + AN(sbh); + + /* No Vary: header, no worries */ + if (!http_GetHdr(&sp->obj->http, H_Vary, &v)) + return; + + for (p = v; *p; p++) { + + /* Find next header-name */ + if (isspace(*p)) + continue; + for (q = p; *q && !isspace(*q) && *q != ','; q++) + continue; + + /* Build a header-matching string out of it */ + vsb_clear(sbh); + vsb_printf(sbh, "%c%.*s:%c", 1 + (q - p), q - p, p, 0); + vsb_finish(sbh); + + /* Append to vary matching string */ + vsb_bcat(sb, vsb_data(sbh), vsb_len(sbh)); + + if (http_GetHdr(sp->http, vsb_data(sbh), &h)) { + /* Trim leading and trailing space */ + while (isspace(*h)) + h++; + e = strchr(h, '\0'); + while (e > h && isspace(e[-1])) + e--; + /* Encode two byte length and contents */ + l = e - h; + vsb_printf(sb, "%c%c", l >> 8, l & 0xff); + vsb_bcat(sb, h, e - h); + } else { + /* Mark as "not present" */ + vsb_printf(sb, "%c%c", 0xff, 0xff); + } + + while (isspace(*q)) + q++; + if (*q == '\0') + break; + xxxassert(*q == ','); + p = q; + } + /* Terminate vary matching string */ + vsb_printf(sb, "%c", 0); + + vsb_finish(sb); + l = vsb_len(sb); + sp->obj->vary = malloc(l); + AN(sp->obj->vary); + memcpy(sp->obj->vary, vsb_data(sb), l); +} + +int +VRY_Match(struct sess *sp, unsigned char *vary) +{ + char *h, *e; + int i, l, lh; + + while (*vary) { + + /* Look for header */ + i = http_GetHdr(sp->http, (char*)vary, &h); + vary += *vary + 2; + + /* Expected length of header (or 0xffff) */ + l = vary[0] * 256 + vary[1]; + vary += 2; + + /* Fail if we have the header, but shouldn't */ + if (i && l == 0xffff) + return (0); + /* or if we don't when we should */ + if (l != 0xffff && !i) + return (0); + + /* Nothing to match */ + if (!i) + continue; + + /* Trim leading & trailing space */ + while (isspace(*h)) + h++; + e = strchr(h, '\0'); + while (e > h && isspace(e[-1])) + e--; + + /* Fail if wrong length */ + lh = e - h; + if (lh != l) + return (0); + + /* or if wrong contents */ + if (memcmp(h, vary, l)) + return (0); + vary += l; + } + return (1); +} From des at linpro.no Sun Jun 10 09:20:46 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Sun, 10 Jun 2007 11:20:46 +0200 Subject: r1504 - in trunk/varnish-cache/bin: varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop In-Reply-To: <20070610071921.B65AF1EC525@projects.linpro.no> (phk@projects.linpro.no's message of "Sun\, 10 Jun 2007 09\:19\:21 +0200 \(CEST\)") References: <20070610071921.B65AF1EC525@projects.linpro.no> Message-ID: <87ir9wxj0x.fsf@des.linpro.no> phk at projects.linpro.no writes: > Log: > libcompat must come after libvarnish because the latter now uses > strndup which might come from the former. Thanks, I had the exact same patch in my tree but forgot to commit it... DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at linpro.no Sun Jun 10 09:21:55 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Sun, 10 Jun 2007 11:21:55 +0200 Subject: r1506 - trunk/varnish-cache/bin/varnishd In-Reply-To: <20070610084943.D8DC31EC041@projects.linpro.no> (phk@projects.linpro.no's message of "Sun\, 10 Jun 2007 10\:49\:43 +0200 \(CEST\)") References: <20070610084943.D8DC31EC041@projects.linpro.no> Message-ID: <87ejkkxiz0.fsf@des.linpro.no> phk at projects.linpro.no writes: > Log: > Take a shot at light-weight "Vary:" processing. > > When we cache an object with a "Vary:" header, we generate > a "vary matching string" which can be used to efficiently > check for compliance when doing a cache lookup. > > Only very lightly tested (ie: cnn.com). > > For a full description of the reasoning, please see > http://varnish.projects.linpro.no/wiki/ArchitectureVary This is awesome! Thanks! /me runs off to test it DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Sun Jun 10 11:46:05 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 10 Jun 2007 13:46:05 +0200 (CEST) Subject: r1507 - trunk/varnish-cache/bin/varnishadm Message-ID: <20070610114605.7A87B1EC035@projects.linpro.no> Author: des Date: 2007-06-10 13:46:05 +0200 (Sun, 10 Jun 2007) New Revision: 1507 Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am Log: Give my anal retentive tendencies free rein, and remove a blank line at the end of the file. Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-06-10 08:49:43 UTC (rev 1506) +++ trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-06-10 11:46:05 UTC (rev 1507) @@ -14,4 +14,3 @@ varnishadm_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a - From cecilihf at projects.linpro.no Mon Jun 11 07:10:55 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 11 Jun 2007 09:10:55 +0200 (CEST) Subject: r1508 - in trunk/varnish-cache: . bin Message-ID: <20070611071055.D68471ECDCD@projects.linpro.no> Author: cecilihf Date: 2007-06-11 09:10:55 +0200 (Mon, 11 Jun 2007) New Revision: 1508 Modified: trunk/varnish-cache/bin/Makefile.am trunk/varnish-cache/configure.ac Log: Changes needed for varnishadm. Modified: trunk/varnish-cache/bin/Makefile.am =================================================================== --- trunk/varnish-cache/bin/Makefile.am 2007-06-10 11:46:05 UTC (rev 1507) +++ trunk/varnish-cache/bin/Makefile.am 2007-06-11 07:10:55 UTC (rev 1508) @@ -1,3 +1,3 @@ # $Id$ -SUBDIRS = varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop +SUBDIRS = varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-10 11:46:05 UTC (rev 1507) +++ trunk/varnish-cache/configure.ac 2007-06-11 07:10:55 UTC (rev 1508) @@ -131,6 +131,7 @@ AC_CONFIG_FILES([ Makefile bin/Makefile + bin/varnishadm/Makefile bin/varnishd/Makefile bin/varnishlog/Makefile bin/varnishhist/Makefile From des at projects.linpro.no Tue Jun 12 07:12:02 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 12 Jun 2007 09:12:02 +0200 (CEST) Subject: r1509 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070612071202.B6B351EC3F9@projects.linpro.no> Author: des Date: 2007-06-12 09:12:02 +0200 (Tue, 12 Jun 2007) New Revision: 1509 Modified: trunk/varnish-cache/lib/libvarnish/vpf.c Log: Fix FreeBSDism (#113). Modified: trunk/varnish-cache/lib/libvarnish/vpf.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vpf.c 2007-06-11 07:10:55 UTC (rev 1508) +++ trunk/varnish-cache/lib/libvarnish/vpf.c 2007-06-12 07:12:02 UTC (rev 1509) @@ -50,7 +50,7 @@ struct pidfh { int pf_fd; char pf_path[MAXPATHLEN + 1]; - __dev_t pf_dev; + dev_t pf_dev; ino_t pf_ino; }; From knutroy at projects.linpro.no Tue Jun 12 12:26:04 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Tue, 12 Jun 2007 14:26:04 +0200 (CEST) Subject: r1510 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test lib/Varnish/Test/Case Message-ID: <20070612122604.4B32D1EC29A@projects.linpro.no> Author: knutroy Date: 2007-06-12 14:26:03 +0200 (Tue, 12 Jun 2007) New Revision: 1510 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Removed: trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm trunk/varnish-tools/regress/lib/Varnish/Test/Expression.pm trunk/varnish-tools/regress/lib/Varnish/Test/Invocation.pm trunk/varnish-tools/regress/lib/Varnish/Test/Message.pm trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm trunk/varnish-tools/regress/lib/Varnish/Test/Parser.pm trunk/varnish-tools/regress/lib/Varnish/Test/Reference.pm trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm trunk/varnish-tools/regress/lib/Varnish/Test/Statement.pm trunk/varnish-tools/regress/test1 Modified: trunk/varnish-tools/regress/README trunk/varnish-tools/regress/TODO trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/varnish-regress.pl Log: Rewrote much of regression test framework. Test-cases for tickets #56 and #102 are included. Test-case for #102 breaks on r1506 (onwards). Modified: trunk/varnish-tools/regress/README =================================================================== --- trunk/varnish-tools/regress/README 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/README 2007-06-12 12:26:03 UTC (rev 1510) @@ -2,59 +2,3 @@ This is a regression test framework written in Perl. It is being tailored to the needs of the Varnish HTTP accelerator. - -The framework is based on interpreting a mini-language designed for -this specific purpose. The mini-language expresses test case setups -and conditions to be tested. - -The Perl-based interpreter sets up the run-time environment and -executes a "program" written in this mini-language. - -The mini-language's grammar can be found in lib/Varnish/Test/Parser.pm -which utilizes the Parse::RecDescent CPAN-module. - -The interpreter creates a run-time environment consisting of simulated -clients and servers which live in the main process. In addition, it -forks off a Varnish sub-process through which the clients and servers -send HTTP-traffic. The main process uses a global select(2)-based loop -(using IO::Multiplex) to which all the simulated clients and servers -must relate. Hence, no threading is needed, but disciplined use -sockets (to avoid blocking and other trouble) is required. - -When the mini-language is parsed, a tree of Perl-objects is created. -There are classes representing: - - * a server (Varnish::Test::Server) - * a client (Varnish::Test::Client) - * an accelerator/Varnish instance (Varnish::Test::Accelerator) - * a test-case (Varnish::Test::Case) - * a statement (Varnish::Test::Statement) - * an expression (Varnish::Test::Expression) - * a function invocation (Varnish::Test::Invocation) - -These classes share some properties which are found -Varnish::Test::Object, most notably the ability to be "executed" and -temporarily paused when the IO::Multiplex-loop needs to transfers -control to another object. - -To keep track of execution, all objects have an attribute, "finished", -which tells its parent whether execution has already terminated. In -addition an attribute "return" is used to hold any return value should -the object have a sensible return value to offer (which is the true -for statements, expressions, and function invocations). Before -"finished" is set to true, "return" has no meaning. - -The parent will execute its children sequentially, in the same order -as they are defined in the source code. - -However, some objects get control back after they are "finished". This -is the case for server objects when they serve requests, which happens -asynchronously to ordinary execution and is orchestrated by the -IO::Multiplex-loop. When the server object has handled the request, -control returns to the original point of execution. Finding that point -is done by skipping past all objects whose "finished"-attribute is -true. - -Finally, the notion of scope and variables is taken care of by -functionality provided in the super-class Varnish::Test::Context from -which Varnish::Test::Object inherits. Modified: trunk/varnish-tools/regress/TODO =================================================================== --- trunk/varnish-tools/regress/TODO 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/TODO 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,23 +1,3 @@ -* Revise class hierarchy, possibly switching around - Varnish::Test::Context and Varnish::Test::Object since we might like - to inherit the properties of Object without getting the properties - of Context, in classes like Varnish::Test::Statement, - Varnish::Test::Expression, and Varnish::Test::Invocation. - -* Actually handle HTTP by utilizing Varnish::Test::Message (and - the sub-classes Varnish::Test::Request and Varnish::Test::Response) - as variables that live inside server and client objects. - -* Extend the language (syntax and semantics), to make it more - expressive and useful. - -* POD-ify Perl-code. - -* Fix IO::Multiplex-related warnings: - - ? Use of uninitialized value in unpack at /usr/share/perl5/IO/Multiplex.pm line 351. - Use of uninitialized value in numeric eq (==) at /usr/share/perl5/IO/Multiplex.pm line 351. - - ? Use of freed value in iteration at /usr/share/perl5/IO/Multiplex.pm line 721. - - (Is this IO::Multiplex' or our fault?) +* Ticket 55. +* Completely POD-ify Perl-code. +* Detect and act upon unexpected death of Varnish grandchild process. Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,183 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Accelerator; - -use strict; -use base 'Varnish::Test::Object'; -use IO::Pipe; -use POSIX; - -sub _init($) { - my $self = shift; - - &Varnish::Test::Object::_init($self); - - # Default address / port - $self->vars->{'address'} = 'localhost'; - $self->vars->{'port'} = '8001'; -} - -use Data::Dumper; - -sub start($) { - my $self = shift; - - my $backend = $self->vars->{'backend'}; - (defined($backend) && - $backend->isa('Varnish::Test::Server')) - or die("invalid server\n"); - - my $stdin = new IO::Pipe; - my $stdout = new IO::Pipe; - my $stderr = new IO::Pipe; - my $pid = fork(); - if (!defined($pid)) { - # fail - die("fork(): $!\n"); - } elsif ($pid == 0) { - # child - $stdin->reader; - $stdout->writer; - $stderr->writer; - - POSIX::dup2($stdin->fileno, 0); - $stdin->close; - POSIX::dup2($stdout->fileno, 1); - $stdout->close; - POSIX::dup2($stderr->fileno, 2); - $stderr->close; - # XXX must be in path - $ENV{'PATH'} = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'; - exec('varnishd', - '-d', '-d', - '-a', $self->get('address') . ":" . $self->get('port'), - '-b', $backend->get('address') . ":" . $backend->get('port')); - exit(1); - } - # parent - - $stdin->writer; - $stdout->reader; - $stderr->reader; - - $self->{'pid'} = $pid; - $self->{'stdin'} = $stdin; - $self->{'stdout'} = $stdout; - $self->{'stderr'} = $stderr; - - # IO::Multiplex is going to issue some warnings here, because it - # does not handle non-socket file descriptors gently. - - my $mux = $self->get_mux; - $mux->add($stdin); - $mux->set_callback_object($self, $stdin); - $mux->add($stdout); - $mux->set_callback_object($self, $stdout); - $mux->add($stderr); - $mux->set_callback_object($self, $stderr); - - if ($self->has('vcl')) { - my $vcl = $self->get('vcl'); - $vcl =~ s/\n/ /g; - $mux->write($stdin, "vcl.inline main " . $vcl . "\n"); - } -} - -sub stop($) { - my $self = shift; - - my $mux = $self->get_mux; - - foreach my $k ('stdin', 'stdout', 'stderr') { - if (defined($self->{$k})) { - $mux->close($self->{$k}); - delete $self->{$k}; - } - } - sleep(1); - kill(15, $self->{'pid'}) - if ($self->{'pid'}); - delete($self->{'pid'}); -} - -sub run($) { - my $self = shift; - - return if $self->{'finished'} or defined($self->{'pid'}); - - &Varnish::Test::Object::run($self); - - $self->start; - $self->{'finished'} = 0; -} - -sub shutdown($) { - my $self = shift; - - $self->stop; -} - -sub mux_input($$$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; - my $data = shift; - - print STDERR $$data; - - if ($$data =~ /vcl.inline/) { - $mux->write($self->{'stdin'}, "start\n"); - } - - my $started = ($$data =~ /Child starts/); - $$data = ''; - - if ($started) { - $self->{'finished'} = 1; - $self->super_run; - } -} - -sub mux_eof($$$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; - my $data = shift; - - $mux->close($fh); - foreach my $k ('stdin', 'stdout', 'stderr') { - if (defined($self->{$k}) && $self->{$k} == $fh) { - delete $self->{$k}; - } - } -} - -1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,54 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::LoadVCL; + +use strict; +use base 'Varnish::Test::Case'; + +use Carp 'croak'; + +sub testLoadVCL($$) { + my ($self, $vcl) = @_; + + $self->{'engine'}->{'varnish'}->send_vcl('main', $vcl); + $self->run_loop; + + $self->{'engine'}->{'varnish'}->send_command('vcl.use main'); + $self->run_loop; +} + +sub ev_varnish_command_ok($) { + my ($self) = @_; + + $self->pause_loop; +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,52 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::StartChild; + +use strict; +use base 'Varnish::Test::Case'; + +use Carp 'croak'; + +sub testStartChild($$) { + my ($self, $vcl) = @_; + + $self->{'engine'}->{'varnish'}->start_child; + croak 'Inappropriate event' if $self->run_loop ne 'Started'; + return 'OK'; +} + +sub ev_varnish_child_started($) { + my ($self) = @_; + + $self->pause_loop('Started'); +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,52 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::StopChild; + +use strict; +use base 'Varnish::Test::Case'; + +use Carp 'croak'; + +sub testStopChild($$) { + my ($self, $vcl) = @_; + + $self->{'engine'}->{'varnish'}->stop_child; + croak 'Inappropriate event' if $self->run_loop ne 'Stopped'; + return 'OK'; +} + +sub ev_varnish_child_stopped($) { + my ($self) = @_; + + $self->pause_loop('Stopped'); +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,98 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::Ticket056; + +use strict; +use base 'Varnish::Test::Case'; + +use Carp 'croak'; + +sub testVersionMatch($) { + my ($self) = @_; + + my $cv = $self->{'cv'}; + my $sv = $self->{'sv'}; + + my $requests = $self->{'engine'}->{'server'}->{'requests'}; + + my $client = $self->new_client; + + my $request = HTTP::Request->new('GET', '/'); + $request->protocol($cv); + $client->send_request($request, 2); + + my $response = $self->run_loop; + + croak 'No (complete) response received' unless defined($response); + croak 'Server was not contacted by Varnish' + if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; + croak sprintf('Protocol version mismatch: got: %s expected: %s', + $response->protocol, $sv) + if $response->protocol ne $sv; + + return sprintf("Client: %s Server: %s", $cv, $sv); +} + +sub run($) { + my ($self) = @_; + + foreach my $cv ('HTTP/1.0', 'HTTP/1.1') { + foreach my $sv ('HTTP/1.0', 'HTTP/1.1') { + $self->{'cv'} = $cv; + $self->{'sv'} = $sv; + $self->SUPER::run; + } + } + + delete $self->{'cv', 'sv'}; +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + + my $response = HTTP::Response->new(404, undef, undef, + sprintf ("%s not found\n", $request->uri)); + $response->protocol($self->{'sv'}); + $connection->send_response($response); + $connection->shutdown; +} + +sub vcl($) { + my ($self) = @_; + + return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' +sub vcl_recv { + pass; +} +EOVCL +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,79 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::Ticket102; + +use strict; +use base 'Varnish::Test::Case'; + +use Carp 'croak'; + +our $body = "Hello World!\n"; + +sub testBodyInCachedPOST($) { + my ($self) = @_; + + my $client = $self->new_client; + for (my $i = 0; $i < 2; $i++) { + my $request = HTTP::Request->new('POST', '/'); + $request->protocol('HTTP/1.1'); + $client->send_request($request, 2); + my $response = $self->run_loop; + croak 'No (complete) response received' unless defined($response); + croak 'Empty body' if $response->content eq ''; + croak 'Incorrect body' if $response->content ne $body; + } +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + + my $response = HTTP::Response->new(200, undef, + [ 'Content-Length', length($body), + 'Connection', 'Keep-Alive' ], + $body); + $response->protocol('HTTP/1.1'); + $connection->send_response($response); +} + +sub vcl($) { + my ($self) = @_; + + return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' +sub vcl_recv { + if (req.request == "POST" && + (!req.http.content-length || req.http.content-length == "0")) { + lookup; + } +} +EOVCL +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -31,45 +31,85 @@ package Varnish::Test::Case; use strict; -use base 'Varnish::Test::Object'; +use Carp 'croak'; -sub _init($) { - my $self = shift; +use Varnish::Test::Logger; - &Varnish::Test::Object::_init($self); +use HTTP::Request; +use HTTP::Response; - $self->set('assert', \&assert); +sub new($$) { + my ($this, $engine) = @_; + my $class = ref($this) || $this; + + my $self = bless({ 'engine' => $engine, + 'count' => 0, + 'successful' => 0, + 'failed' => 0 }, $class); } -sub run($) { - my $self = shift; +sub log($$) { + my ($self, $str) = @_; - if (!defined($self->{'started'})) { - print "Start of CASE \"$self->{name}\"...\n"; - $self->{'started'} = 1; - } + $self->{'engine'}->log($self, 'CAS: ', $str); +} - &Varnish::Test::Object::run($self); +sub run($;@) { + my ($self, @args) = @_; - if ($self->{'finished'}) { - print "End of CASE \"$self->{name}\".\n"; + $self->{'engine'}->{'case'} = $self; + + $self->log('Starting ' . ref($self)); + + no strict 'refs'; + foreach my $method (keys %{ref($self) . '::'}) { + next unless $method =~ m/^test([A-Z]\w+)/; + eval { + $self->{'count'} += 1; + my $result = $self->$method(@args); + $self->{'successful'} += 1; + $self->log(sprintf("%d: PASS: %s: %s\n", + $self->{'count'}, $method, $result || '')); + }; + if ($@) { + $self->{'failed'} += 1; + $self->log(sprintf("%d: FAIL: %s: %s", + $self->{'count'}, $method, $@)); + } } + + delete $self->{'engine'}->{'case'}; } -sub assert($$) { - my $self = shift; - my $invocation = shift; +sub run_loop($) { + my ($self) = @_; - my $bool = $invocation->{'args'}[0]->{'return'}; + $self->{'engine'}->run_loop; +} - if (!$bool) { - print " ASSERTION DOES NOT HOLD.\n"; - } - else { - print " Assertion holds.\n"; - } +sub pause_loop($;@) { + my ($self, @args) = @_; - $invocation->{'finished'} = 1; + $self->{'engine'}->pause_loop(@args); } +sub new_client($) { + my ($self) = @_; + + return Varnish::Test::Client->new($self->{'engine'}); +} + +sub ev_client_response($$$) { + my ($self, $client, $response) = @_; + + $self->{'engine'}->pause_loop($response); +} + +sub ev_client_timeout($$) { + my ($self, $client) = @_; + + $client->shutdown(2); + $self->{'engine'}->pause_loop; +} + 1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -31,76 +31,110 @@ package Varnish::Test::Client; use strict; -use base 'Varnish::Test::Object'; -use IO::Socket; -use URI; +use Carp 'croak'; -sub _init($) { - my $self = shift; +use IO::Socket::INET; - &Varnish::Test::Object::_init($self); +sub new($$) { + my ($this, $engine, $attrs) = @_; + my $class = ref($this) || $this; - $self->set('protocol', '1.1'); - $self->set('request', \&request); + my $self = bless({ 'engine' => $engine, + 'mux' => $engine->{'mux'}, + 'requests' => 0, + 'responses' => 0 }, $class); + + return $self; } -sub request($$) { - my $self = shift; - my $invocation = shift; +sub log($$;$) { + my ($self, $str, $extra_prefix) = @_; - my $server = $invocation->{'args'}[0]->{'return'}; - my $uri = $invocation->{'args'}[1]->{'return'}; + $self->{'engine'}->log($self, 'CLI: ' . ($extra_prefix || ''), $str); +} - (defined($server) && - ($server->isa('Varnish::Test::Accelerator') || - $server->isa('Varnish::Test::Server'))) - or die("invalid server\n"); +sub send_request($$;$) { + my ($self, $request, $timeout) = @_; - $uri = new URI($uri) - or die("invalid URI\n"); + my $fh = IO::Socket::INET->new('Proto' => 'tcp', + 'PeerAddr' => 'localhost', + 'PeerPort' => '8080') + or croak "socket: $@"; - my $fh = new IO::Socket::INET(Proto => 'tcp', - PeerAddr => $server->get('address'), - PeerPort => $server->get('port')) - or die "socket: $@"; + $self->{'fh'} = $fh; + $self->{'mux'}->add($fh); + $self->{'mux'}->set_timeout($fh, $timeout) if defined($timeout); + $self->{'mux'}->set_callback_object($self, $fh); + $self->{'mux'}->write($fh, $request->as_string); + $self->{'requests'} += 1; + $self->log($request->as_string, 'Tx| '); +} - my $mux = $self->get_mux; - $mux->add($fh); - $mux->set_callback_object($self, $fh); +sub got_response($$) { + my ($self, $response) = @_; - $mux->write($fh, "GET / HTTP/" . eval($self->get('protocol')) . "\r\n\r\n"); + $self->{'responses'} += 1; + $self->log($response->as_string, 'Rx| '); + $self->{'engine'}->ev_client_response($self, $response); +} - $self->{'request'} = $invocation; +sub shutdown($) { + my ($self) = @_; + + $self->{'mux'}->shutdown($self->{'fh'}, 1); } sub mux_input($$$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; - my $data = shift; - my $response = new Varnish::Test::Context('response', $self); + my ($self, $mux, $fh, $data) = @_; - $self->{'request'}->{'return'} = $$data; - if ($$data =~ 'HTTP/1.1') { - $response->set('protocol', '1.1'); + while ($$data =~ /\n\r?\n/) { + my $response = HTTP::Response->parse($$data); + my $content_length = $response->content_length; + + if (defined($content_length)) { + my $content_ref = $response->content_ref; + my $data_length = length($$content_ref); + if ($data_length == $content_length) { + $$data = ''; + $self->got_response($response); + } + elsif ($data_length < $content_length) { + last; + } + else { + $$data = substr($$content_ref, $content_length, + $data_length - $content_length, ''); + $self->got_response($response); + } + } + else { + last; + } } - else { - $response->set('protocol', '1.0'); - } - print STDERR "Client got: $$data"; - $$data = ""; - $self->{'request'}->{'finished'} = 1; - delete $self->{'request'}; - $self->super_run; } sub mux_eof($$$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; - my $data = shift; + my ($self, $mux, $fh, $data) = @_; - $mux->close($fh); + if ($$data ne '') { + croak 'Junk or incomplete response' unless $$data =~ "\n\r?\n"; + + my $response = HTTP::Response->parse($$data); + $$data = ''; + $self->got_response($response); + } } +sub mux_timeout($$$) { + my ($self, $mux, $fh) = @_; + + $self->{'engine'}->ev_client_timeout($self); +} + +sub mux_close($$) { + my ($self, $mux, $fh) = @_; + + delete $self->{'fh'}; +} + 1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,143 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Context; - -use strict; - -# -# A Context is an object that has a name, a type, and a set of named -# variables and procedures associated with it. A context may have a -# parent, from which it inherits variables and procedures. -# - -sub new($$;$) { - my $this = shift; - my $class = ref($this) || $this; - my $name = shift; - my $parent = shift; - - my $self = { - 'name' => $name, - 'vars' => { }, - }; - bless($self, $class); - - $self->set_parent($parent); - - return $self; -} - -sub set_parent($$) { - my $self = shift; - my $parent = shift; - - if (defined($self->{'name'})) { - if (defined($self->{'parent'})) { - # Unlink from old parent. - $self->{'parent'}->unset($self->{'name'}); - } - if (defined($parent)) { - # Link to new parent. - $parent->set($self->{'name'}, $self); - } - } - - $self->{'parent'} = $parent; -} - -sub parent($) { - my $self = shift; - - return $self->{'parent'}; -} - -sub vars($) { - my $self = shift; - - return $self->{'vars'}; -} - -sub set($$$) { - my $self = shift; - my $key = shift; - my $value = shift; - - if (!exists($self->vars->{$key}) && - $self->parent && $self->parent->has($key)) { - $self->parent->set($key, $value); - } else { - $self->vars->{$key} = $value; - } - return $value; -} - -sub unset($$) { - my $self = shift; - my $key = shift; - - delete $self->vars->{$key} if exists($self->vars->{$key}); -} - -sub has($$) { - my $self = shift; - my $key = shift; - - return exists($self->{'vars'}->{$key}) || - $self->parent && $self->parent->has($key); -} - -sub get($$) { - my $self = shift; - my $key = shift; - - return exists($self->vars->{$key}) ? $self->vars->{$key} : - ($self->parent && $self->parent->get($key)); -} - -sub type($) { - my $self = shift; - - if (!defined($self->{'type'})) { - ($self->{'type'} = ref($self)) =~ s/^(\w+::)*(\w+)$/$2/; - print STDERR "$self->{'type'}\n"; - } - return $self->{'type'}; -} - -sub name($;$) { - my $self = shift; - - $self->{'name'} = shift - if (@_); - return $self->{'name'}; -} - -1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,131 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Engine; + +use strict; +use Carp 'croak'; + +use Varnish::Test::Server; +use Varnish::Test::Varnish; +use Varnish::Test::Client; +use IO::Multiplex; + +sub new($$;%) { + my ($this, $controller, %config) = @_; + my $class = ref($this) || $this; + + %config = ('server_address' => 'localhost:8081', + 'varnish_address' => 'localhost:8080', + %config); + + my $self = bless({ 'mux' => IO::Multiplex->new, + 'controller' => $controller, + 'config' => \%config }, $class); + + $self->{'server'} = Varnish::Test::Server->new($self); + $self->{'varnish'} = Varnish::Test::Varnish->new($self); + + return $self; +} + +sub log($$$) { + my ($self, $object, $prefix, $str) = @_; + + $str =~ s/^/$prefix/gm; + $str =~ s/\n?$/\n/; + + print STDERR $str; +} + +sub run_loop($) { + my ($self) = @_; + + croak 'Engine::run: Already inside select-loop. Your code is buggy.' + if exists($self->{'in_loop'}); + + $self->{'in_loop'} = 1; + $self->{'mux'}->loop; + delete $self->{'in_loop'}; + + return delete $self->{'return'} if exists $self->{'return'}; + return undef; +} + +sub pause_loop($;$) { + my ($self, $return) = @_; + + croak 'Engine::pause: Not inside select-loop. Your code is buggy.' + unless exists($self->{'in_loop'}); + + $self->{'return'} = $return if defined($return); + $self->{'mux'}->endloop; +} + +sub shutdown($) { + my ($self) = @_; + + $self->{'varnish'}->shutdown if defined $self->{'varnish'}; + $self->{'server'}->shutdown if defined $self->{'server'}; + foreach my $fh ($self->{'mux'}->handles) { + $self->{'mux'}->close($fh); + } +} + +sub ev_varnish_started($) { + my ($self) = @_; + + $self->pause_loop; +} + +sub AUTOLOAD ($;@) { + my ($self, @args) = @_; + + (my $event_handler = our $AUTOLOAD) =~ s/.*://; + + return if $event_handler eq 'DESTROY'; + + croak sprintf('received event (%s) while not running a case', $event_handler) + unless defined $self->{'case'}; + + croak sprintf('Unknown method "%s"', $event_handler) + unless $event_handler =~ /^ev_(.*)$/; + + if ($self->{'case'}->can($event_handler)) { + $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); + return $self->{'case'}->$event_handler(@args); + } + else { + $self->log($self, 'ENG: ', sprintf('EVENT "%s" IGNORED', $1)); + return undef; + } +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Expression.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Expression.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Expression.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,142 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Expression; - -use strict; -use base 'Varnish::Test::Object'; -use Varnish::Test::Invocation; - -sub new($$;$) { - my $this = shift; - my $class = ref($this) || $this; - my $terms = shift; - my $force_create = shift; - - if (@$terms == 1 && (!$force_create || ref($$terms[0]) eq $class)) { - return $$terms[0]; - } - - my $children = []; - - if (@$terms == 2 - && ref($$terms[0]) eq 'Varnish::Test::Reference' - && ref($$terms[1]) eq 'ARRAY') { - my $invocation = new Varnish::Test::Invocation($$terms[0], $$terms[1]); - push (@$children, $invocation); - undef $terms; - } - else { - foreach my $term (@$terms) { - push (@$children, $term) if ref($term) eq 'Varnish::Test::Expression'; - } - } - - my $self = new Varnish::Test::Object(undef, $children); - bless($self, $class); - $self->{'terms'} = $terms; - - return $self; -} - -sub run($) { - my $self = shift; - - return if $self->{'finished'}; - - &Varnish::Test::Object::run($self); - - my $expr = ''; - my $seen_string = 0; - my $relational = 0; - - if ($self->{'finished'} && defined($self->{'terms'})) { - - foreach my $term (@{$self->{'terms'}}) { - my $term_value; - if (ref($term) eq 'Varnish::Test::Expression') { - $term_value = $term->{'return'}; - } - elsif (ref($term) eq 'Varnish::Test::Reference') { - $term_value = $term->get_value($self); - if (!defined($term_value)) { - die '"' . $term->as_string . '"' . " not defined"; - } - } - else { - if ($term eq '==' || $term eq '!=' - || $term eq '<=' || $term eq '>=' - || $term eq '<' || $term eq '>') { - $relational = 1; - - if ($seen_string) { - if ($term eq '==') { - $term = 'eq'; - } - elsif ($term eq '!=') { - $term = 'ne'; - } - } - } - $term_value = $term; - } - - if (ref(\$term_value) eq 'REF') { - if (@{$self->{'terms'}} == 1) { - $self->{'return'} = $term_value; - return; - } - else { - $term_value = '"' . $term_value . '"'; - } - } - - if ($term_value =~ /^".*"$/s) { - $seen_string = 1; - } - - $expr .= $term_value; - } - - ($expr) = $expr =~ /(.*)/s; - - # print STDERR "Evaling: $expr\n"; - - $expr = eval $expr; - - if ($seen_string && !$relational) { - $expr = '"' . $expr . '"'; - } - - $self->{'return'} = $expr; - } -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Invocation.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Invocation.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Invocation.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,69 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Invocation; - -use strict; -use base 'Varnish::Test::Object'; - -sub new($$$) { - my $this = shift; - my $class = ref($this) || $this; - my $func_id = shift; - my $args = shift; - - my $self = new Varnish::Test::Object(undef, $args); - bless($self, $class); - - $self->{'func_id'} = $func_id; - $self->{'args'} = $args; - - return $self; -} - -sub run($) { - my $self = shift; - - return if $self->{'finished'}; - - &Varnish::Test::Object::run($self) unless $self->{'in_call'}; - - if ($self->{'finished'}) { - $self->{'finished'} = 0; - if (!$self->{'in_call'}) { - $self->{'in_call'} = 1; - my ($func_ptr, $func_context) = $self->{'func_id'}->get_function($self); - # print STDERR "Calling " . $self->{'func_id'}->as_string, "\n"; - &$func_ptr($func_context, $self); - } - } -} - -1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,55 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Logger; + +sub new($;$) { + my ($this, $prefix) = @_; + my $class = ref($this) || $this; + + my $self = bless({ 'prefix' => $prefix || '' }, $class); +} + +sub write($$;$) { + my ($self, $data, $extra_prefix) = @_; + + my $prefix = $self->{'prefix'}; + $prefix .= ': ' . $extra_prefix if defined($extra_prefix); + + if ($prefix) { + $data =~ s/^/$prefix: /gm; + } + + $data =~ s/\n?$/\n/; + + print STDERR $data; +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Message.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Message.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Message.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,36 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Message; - -use strict; -use base 'Varnish::Test::Object'; - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,98 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Object; - -use strict; -use base 'Varnish::Test::Context'; - -sub new($$$;$) { - my $this = shift; - my $class = ref($this) || $this; - my $name = shift; - my $children = shift; - my $parent = shift; - - my $self = new Varnish::Test::Context($name, $parent); - bless($self, $class); - - for my $child (@$children) { - $child->set_parent($self); - } - - $self->{'children'} = $children; - $self->{'finished'} = 0; - $self->{'return'} = undef; - $self->_init; - - return $self; -} - -sub _init($) { -} - -sub run($) { - my $self = shift; - - return if $self->{'finished'}; - - foreach my $child (@{$self->{'children'}}) { - $child->run($self) unless $child->{'finished'}; - return unless $child->{'finished'}; - $self->{'return'} = $child->{'return'}; - } - - $self->{'finished'} = 1; -} - -sub shutdown($) { - my $self = shift; - - foreach my $child (@{$self->{'children'}}) { - $child->shutdown; - } -} - -sub get_mux($) { - my $self = shift; - return $self->{'mux'} || $self->{'parent'} && $self->{'parent'}->get_mux; -} - -sub super_run($) { - my $self = shift; - if (defined($self->{'parent'})) { - $self->{'parent'}->super_run; - } - else { - $self->run; - } -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Parser.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Parser.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Parser.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,133 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2007 Linpro AS -# 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$ -# - -package Varnish::Test::Parser; - -use strict; - -use Parse::RecDescent; -use Varnish::Test::Reference; -use Varnish::Test::Expression; -use Varnish::Test::Statement; -use Varnish::Test::Client; -use Varnish::Test::Server; -use Varnish::Test::Accelerator; -use Varnish::Test::Case; - -sub new { - return new Parse::RecDescent(<<'EOG'); - -STRING_LITERAL: - { extract_delimited($text, '"') } - -IDENTIFIER: - /[a-z]\w*/i - -CONSTANT: - /[+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?/ - -reference: - - { new Varnish::Test::Reference($item[1]) } - -argument_list: - - -call: - reference '(' argument_list(?) ')' - { new Varnish::Test::Expression([$item[1], (@{$item[3]}) ? $item[3][0] : []]) } - | - -primary_expression: - call - | reference - | STRING_LITERAL - | CONSTANT - | '(' expression ')' - { $item[2] } - -mul_op: - '*' | '/' | '%' - -multiplicative_expression: - - { new Varnish::Test::Expression($item[1]) } - -add_op: - '+' | '-' | '.' - -additive_expression: - - { new Varnish::Test::Expression($item[1]) } - -rel_op: - '==' | '!=' | '<=' | '>=' | '<' | '>' - -expression: - additive_expression rel_op additive_expression - { new Varnish::Test::Expression([@item[1..$#item]], 1) } - | additive_expression - { new Varnish::Test::Expression([$item[1]], 1) } - | - -statement: - reference '=' expression - { new Varnish::Test::Statement([@item[1..3]]) } - | call - { new Varnish::Test::Statement([$item[1]]) } - -block: - '{' statement(s? /;/) (';')(?) '}' - { $item[2] } - | - -object: - 'ticket' CONSTANT ';' - { [@item[1,2]] } - | 'client' IDENTIFIER block - { new Varnish::Test::Client(@item[2,3]) } - | 'server' IDENTIFIER block - { new Varnish::Test::Server(@item[2,3]) } - | 'accelerator' IDENTIFIER block - { new Varnish::Test::Accelerator(@item[2,3]) } - | 'case' IDENTIFIER block - { new Varnish::Test::Case(@item[2,3]) } - | - -module: - 'test' STRING_LITERAL(?) '{' object(s?) '}' /^\Z/ - { { 'id' => (@{$item[2]}) ? $item[2][0] : undef, - 'body' => $item[4] } } - | - -EOG -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Reference.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Reference.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Reference.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,105 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Reference; - -use strict; - -sub new($$) { - my $this = shift; - my $class = ref($this) || $this; - my $symbols = shift; - - my $self = { - 'symbols' => $symbols, - }; - bless($self, $class); - - return $self; -} - -sub as_string($) { - my $self = shift; - return join('.', @{$self->{'symbols'}}); -} - -sub _find_context($$) { - my $self = shift; - my $context = shift; - - foreach my $symbol (@{$self->{'symbols'}}[0..$#{$self->{'symbols'}}-1]) { - $context = $context->get($symbol); - if (!(ref($context) =~ /^Varnish::Test::\w+$/ - && $context->isa('Varnish::Test::Context'))) { - return undef; - } - } - - return $context; -} - -sub get_value($$) { - my $self = shift; - my $context = shift; - - $context = $self->_find_context($context); - if (defined($context)) { - return $context->get($self->{'symbols'}[$#{$self->{'symbols'}}]); - } - else { - return undef; - } -} - -sub set_value($$) { - my $self = shift; - my $context = shift; - my $value = shift; - - $context = $self->_find_context($context); - if (defined($context)) { - $context->set($self->{'symbols'}[$#{$self->{'symbols'}}], $value); - } - else { - die "Cannot find containing context for ", join('.', @{$self->{'symbols'}}), ".\n"; - } -} - -sub get_function($$) { - my $self = shift; - my $context = shift; - - $context = $self->_find_context($context); - if (defined($context)) { - return ($context->get($self->{'symbols'}[$#{$self->{'symbols'}}]), $context); - } -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,36 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Request; - -use strict; -use base 'Varnish::Test::Message'; - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,36 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Response; - -use strict; -use base 'Varnish::Test::Message'; - -1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -31,67 +31,136 @@ package Varnish::Test::Server; use strict; -use base 'Varnish::Test::Object'; -use IO::Socket; +use Carp 'croak'; -sub _init($) { - my $self = shift; +use IO::Socket::INET; - &Varnish::Test::Object::_init($self); +sub new($$) { + my ($this, $engine, $attrs) = @_; + my $class = ref($this) || $this; - $self->set('address', 'localhost'); - $self->set('port', '9001'); -} + my ($host, $port) = split(':', $engine->{'config'}->{'server_address'}); -sub run($) { - my $self = shift; + my $socket = IO::Socket::INET->new('Proto' => 'tcp', + 'LocalAddr' => $host, + 'LocalPort' => $port, + 'Listen' => 4, + 'ReuseAddr' => 1) + or croak "socket: $@"; - return if $self->{'finished'}; + my $self = bless({ 'engine' => $engine, + 'mux' => $engine->{'mux'}, + 'socket' => $socket, + 'requests' => 0, + 'responses' => 0 }, $class); - &Varnish::Test::Object::run($self); + $self->{'mux'}->listen($socket); + $self->{'mux'}->set_callback_object($self, $socket); - my $fh = new IO::Socket::INET(Proto => 'tcp', - LocalAddr => $self->get('address'), - LocalPort => $self->get('port'), - Listen => 4) - or die "socket: $@"; + return $self; +} - $self->{'fh'} = $fh; +sub log($$;$) { + my ($self, $str, $extra_prefix) = @_; - my $mux = $self->get_mux; - $mux->listen($fh); - $mux->set_callback_object($self, $fh); + $self->{'engine'}->log($self, 'SRV: ' . ($extra_prefix || ''), $str); } sub shutdown($) { - my $self = shift; + my ($self) = @_; - $self->get_mux->close($self->{'fh'}); + $self->{'mux'}->close($self->{'socket'}); + delete $self->{'socket'}; } sub mux_connection($$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; + my ($self, $mux, $fh) = @_; - $mux->set_callback_object($self, $fh); + $self->log('CONNECT'); + my $connection = Varnish::Test::Server::Connection->new($self, $fh); } +sub mux_close($$) { + my ($self, $mux, $fh) = @_; + + $self->log('CLOSE'); + delete $self->{'socket'} if $fh == $self->{'socket'}; +} + +sub got_request($$) { + my ($self, $connection, $request) = @_; + + $self->{'requests'} += 1; + $self->log($request->as_string, 'Rx| '); + $self->{'engine'}->ev_server_request($self, $connection, $request); +} + +package Varnish::Test::Server::Connection; + +use strict; +use Carp 'croak'; + +sub new($$) { + my ($this, $server, $fh) = @_; + my $class = ref($this) || $this; + + my $self = bless({ 'server' => $server, + 'fh' => $fh, + 'mux' => $server->{'mux'}, + 'data' => '' }, $class); + $self->{'mux'}->set_callback_object($self, $fh); + return $self; +} + +sub send_response($$) { + my ($self, $response) = @_; + + $self->{'mux'}->write($self->{'fh'}, $response->as_string); + $self->{'server'}->{'responses'} += 1; + $self->{'server'}->log($response->as_string, 'Tx| '); +} + +sub shutdown($) { + my ($self) = @_; + + $self->{'mux'}->shutdown($self->{'fh'}, 1); +} + sub mux_input($$$$) { - my $self = shift; - my $mux = shift; - my $fh = shift; - my $data = shift; + my ($self, $mux, $fh, $data) = @_; - $$data = ""; # Pretend we read the data. + while ($$data =~ /\n\r?\n/) { + my $request = HTTP::Request->parse($$data); + my $content_ref = $request->content_ref; + my $content_length = $request->content_length; - my $response = "HTTP/" . eval($self->get('protocol')) . " 200 OK\r\n" - . "Content-Type: text/plain; charset=utf-8\r\n\r\n" - . eval($self->get('data')) . "\n"; + if (defined($content_length)) { + my $data_length = length($$content_ref); + if ($data_length == $content_length) { + $$data = ''; + $self->{'server'}->got_request($self, $request); + } + elsif ($data_length < $content_length) { + last; + } + else { + $$data = substr($$content_ref, $content_length, + $data_length - $content_length, ''); + $self->{'server'}->got_request($self, $request); + } + } + else { + $$data = $$content_ref; + $$content_ref = ''; + $self->{'server'}->got_request($self, $request); + } + } +} - $mux->write($fh, $response); - print STDERR "Server sent: " . $response; - $mux->shutdown($fh, 1); +sub mux_eof($$$$) { + my ($self, $mux, $fh, $data) = @_; + + croak 'Junk or incomplete request' unless $$data eq ''; } 1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Statement.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Statement.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Statement.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,70 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Statement; - -use strict; -use base 'Varnish::Test::Object'; - -sub new($$) { - my $this = shift; - my $class = ref($this) || $this; - my $args = shift; - - my $children = []; - - if (@$args > 1 && $$args[1] eq '=') { - my $self = new Varnish::Test::Object(undef, [$$args[2]]); - bless($self, $class); - - $self->{'lhs'} = $$args[0]; - - return $self; - } - else { - return $$args[0]; - } -} - -use Data::Dumper; - -sub run($$) { - my $self = shift; - - return if $self->{'finished'}; - - &Varnish::Test::Object::run($self); - - if ($self->{'finished'}) { - $self->{'lhs'}->set_value($self->{'parent'}, $self->{'return'}); - } -} - -1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -0,0 +1,201 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Varnish; + +use strict; +use Carp 'croak'; + +use Socket; + +use Varnish::Test::Logger; + +sub new($$;$) { + my ($this, $engine, $attrs) = @_; + my $class = ref($this) || $this; + + my $self = bless({ 'engine' => $engine, + 'mux' => $engine->{'mux'}, + 'state' => 'init' }, $class); + + socketpair(STDIN_READ, STDIN_WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC); + shutdown(STDIN_READ, 1); + shutdown(STDIN_WRITE, 0); + socketpair(STDOUT_READ, STDOUT_WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC); + shutdown(STDOUT_READ, 1); + shutdown(STDOUT_WRITE, 0); + socketpair(STDERR_READ, STDERR_WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC); + shutdown(STDERR_READ, 1); + shutdown(STDERR_WRITE, 0); + + delete $SIG{CHLD}; + + my $pid = fork; + croak "fork(): $@\n" unless defined($pid); + + if ($pid == 0) { + # Child + + close STDIN_WRITE; + close STDOUT_READ; + close STDERR_READ; + + open STDIN, '<&', \*STDIN_READ; + close STDIN_READ; + open STDOUT, '>&', \*STDOUT_WRITE; + close STDOUT_WRITE; + open STDERR, '>&', \*STDERR_WRITE; + close STDERR_WRITE; + + my @opts = ('-d', '-d', + '-a', $engine->{'config'}->{'varnish_address'}, + '-b', $engine->{'config'}->{'server_address'}); + + print STDERR sprintf("Starting Varnish with options: %s\n", join(' ', @opts)); + + $ENV{'PATH'} = '/opt/varnish/sbin:/bin:/usr/bin'; + exec('varnishd', @opts); + exit(1); + } + else { + # Parent + + $SIG{CHLD} = 'IGNORE'; + + $self->log('PID: ' . $pid); + + close STDIN_READ; + close STDOUT_WRITE; + close STDERR_WRITE; + + $self->{'pid'} = $pid; + $self->{'stdin'} = \*STDIN_WRITE; + $self->{'stdout'} = \*STDOUT_READ; + $self->{'stderr'} = \*STDERR_READ; + + $self->{'mux'}->add($self->{'stdin'}); + $self->{'mux'}->set_callback_object($self, $self->{'stdin'}); + $self->{'mux'}->add($self->{'stdout'}); + $self->{'mux'}->set_callback_object($self, $self->{'stdout'}); + $self->{'mux'}->add($self->{'stderr'}); + $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); + } + + return $self; +} + +sub log($$) { + my ($self, $str) = @_; + + $self->{'engine'}->log($self, 'VAR: ', $str); +} + +sub backend_block($$) { + my ($self, $name) = @_; + + return sprintf("backend %s {\n set backend.host = \"%s\";\n set backend.port = \"%s\";\n}\n", + $name, split(':', $self->{'engine'}->{'config'}->{'server_address'})); +} + +sub send_command($$) { + my ($self, $command) = @_; + croak 'not ready' if $self->{'state'} eq 'init'; + croak sprintf('busy awaiting earlier command (%s)', $self->{'pending'}) + if defined $self->{'pending'}; + + $self->{'mux'}->write($self->{'stdin'}, $command . "\n"); + $self->{'pending'} = $command; +} + +sub send_vcl($$$) { + my ($self, $config, $vcl) = @_; + + $vcl =~ s/\n/ /g; + $vcl =~ s/"/\\"/g; + + $self->send_command(sprintf('vcl.inline %s "%s"', $config, $vcl)); +} + +sub start_child($) { + my ($self) = @_; + croak 'not ready' if $self->{'state'} eq 'init'; + croak 'already started' if $self->{'state'} eq 'started'; + + $self->send_command("start"); +} + +sub stop_child($) { + my ($self) = @_; + croak 'not ready' if $self->{'state'} eq 'init'; + croak 'already stopped' if $self->{'state'} eq 'stopped'; + + $self->send_command("stop"); +} + +sub shutdown($) { + my ($self) = @_; + + $self->{'mux'}->shutdown(delete $self->{'stdin'}, 1); +} + +sub kill($;$) { + my ($self, $signal) = @_; + + $signal ||= 15; + croak 'Not running' unless defined($self->{'pid'}); + kill($signal, $self->{'pid'}); + delete $self->{'pid'}; +} + +sub mux_input($$$$) { + my ($self, $mux, $fh, $data) = @_; + + $self->log($$data); + + if ($$data =~ /rolling\(2\)\.\.\./) { + $self->{'state'} = 'stopped'; + $self->{'engine'}->ev_varnish_started; + } + if ($$data =~ /Child starts/) { + $self->{'state'} = 'started'; + $self->{'engine'}->ev_varnish_child_started; + } + if ($$data =~ /Child dies/) { + $self->{'state'} = 'stopped'; + $self->{'engine'}->ev_varnish_child_stopped; + } + + $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) + if ($$data =~ /^200 0/ and $self->{'pending'}); + + $$data = ''; +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-12 12:26:03 UTC (rev 1510) @@ -28,92 +28,97 @@ # $Id$ # -package Varnish::Test; +=head1 NAME -use strict; -use base 'Varnish::Test::Object'; -use Varnish::Test::Accelerator; -use Varnish::Test::Case; -use Varnish::Test::Client; -use Varnish::Test::Server; -use Varnish::Test::Parser; -use IO::Multiplex; +Varnish::Test - Regression test framework for Varnish -use Data::Dumper; +=head1 DESCRIPTION -sub new($;$) { - my $this = shift; - my $class = ref($this) || $this; - my $fn = shift; +The varnish regression test framework works by starting up a Varnish +process and then communicating with this process as both client and +server. - my $self = new Varnish::Test::Object; - bless($self, $class); +=head1 STRUCTURE - $self->{'mux'} = new IO::Multiplex; +When regressions tests start, an instance of Varnish is forked off as +a child process, and its I/O channels (std{in,out,err}) are controlled +by the parent process which also performs the test by playing the role +of both HTTP client and server. - if ($fn) { - $self->parse($fn); - } +A single select(2)-driven loop is used to handle all activity on both +server and client side, as well on Varnish's I/O-channels. This is +done using IO::Multiplex. - return $self; -} +As a result of using a select-loop, the framework has an event-driven +design in order to cope with unpredictable sequence of processing on +either server og client side. To drive a test-case forward, the +select-loop is paused when certain events occur, and control returns +to the "main program" which can then inspect the situation. This +results in certain structural constraints. It is essential to be aware +of whether a piece of code is going to run inside or outside the +select-loop. -sub parse($$) { - my $self = shift; - my $fn = shift; +The framework uses Perl objects to represent instances of servers and +clients as well as the Varnish instance itself. In addition, there is +an "engine" object which propagates events and controls the program +flow related to the select-loop. - local $/; - open(SRC, "<", $fn) or die("$fn: $!\n"); - my $src = ; - close(SRC); +=cut - $::RD_HINT = 1; - my $parser = new Varnish::Test::Parser; - if (!defined($parser)) { - die("Error generating parser."); - } - my $tree = $parser->module($src); - if (!defined($tree)) { - die("Parsing error."); - } +package Varnish::Test; - print STDERR "###### SYNTAX TREE BEGIN ######\n"; - print STDERR Dumper $tree if defined($tree->{'body'}); - print STDERR "###### SYNTAX TREE END ######\n"; +use Carp 'croak'; - $self->{'objects'} = []; +use Varnish::Test::Engine; +use Varnish::Test::Case::LoadVCL; +use Varnish::Test::Case::StartChild; +use Varnish::Test::Case::StopChild; - foreach my $object (@{$tree->{'body'}}) { - if (ref($object) eq 'ARRAY') { - $self->{$$object[0]} = $$object[1]; - } - elsif (ref($object)) { - push(@{$self->{'children'}}, $object); - $object->set_parent($self); - } - } +sub new($) { + my ($this) = @_; + my $class = ref($this) || $this; + + return bless({ 'cases' => [] }, $class); } -sub main($) { - my $self = shift; +sub start_engine($;@) { + my ($self, @args) = @_; - while (!$self->{'finished'}) { - &Varnish::Test::Object::run($self); - print STDERR "Entering IO::Multiplex loop.\n"; - $self->{'mux'}->loop; - } + return if defined $self->{'engine'}; + $self->{'engine'} = Varnish::Test::Engine->new(@args); + $self->{'engine'}->run_loop; +} - print STDERR "DONE.\n"; +sub stop_engine($;$) { + my ($self) = @_; + + (delete $self->{'engine'})->shutdown if defined $self->{'engine'}; } -sub run($) { - my $self = shift; +sub run_case($$) { + my ($self, $name) = @_; - return if $self->{'finished'}; + my $module = 'Varnish::Test::Case::' . $name; - &Varnish::Test::Object::run($self); + eval 'use ' . $module; + croak $@ if $@; - $self->shutdown if $self->{'finished'}; + $self->start_engine; + + my $case = $module->new($self->{'engine'}); + + push(@{$self->{'cases'}}, $case); + + Varnish::Test::Case::LoadVCL->new($self->{'engine'})->run($case->vcl) + if $case->can('vcl'); + + Varnish::Test::Case::StartChild->new($self->{'engine'})->run; + + $case->run; + + Varnish::Test::Case::StopChild->new($self->{'engine'})->run; + + $self->stop_engine; } 1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test.pm ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/regress/test1 =================================================================== --- trunk/varnish-tools/regress/test1 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/test1 2007-06-12 12:26:03 UTC (rev 1510) @@ -1,51 +0,0 @@ -test "Preserve HTTP protocol version in PASS mode" { - ticket 56; - - client c1 { - } - - server s1 { - data = "This is a test."; - } - - accelerator a1 { - backend = s1; - vcl = " -sub vcl_recv { - pass; -} -"; - } - - case c10_s10 { - comment = "client 1.0, server 1.0"; - c1.protocol = "1.0"; - s1.protocol = "1.0"; - c1.request(a1, "http://www.example.com/"); - assert(c1.response.protocol == "1.0"); - } - - case c10_s11 { - comment = "client 1.0, server 1.1"; - c1.protocol = "1.0"; - s1.protocol = "1.1"; - c1.request(a1, "http://www.example.com/"); - assert(c1.response.protocol == "1.0"); - } - - case c11_s10 { - comment = "client 1.1, server 1.0"; - c1.protocol = "1.1"; - s1.protocol = "1.0"; - c1.request(a1, "http://www.example.com/"); - assert(c1.response.protocol == "1.1"); - } - - case c11_s11 { - comment = "client 1.1, server 1.1"; - c1.protocol = "1.1"; - s1.protocol = "1.1"; - c1.request(a1, "http://www.example.com/"); - assert(c1.response.protocol == "1.1"); - } -} Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-12 07:12:02 UTC (rev 1509) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-12 12:26:03 UTC (rev 1510) @@ -29,12 +29,73 @@ # use strict; -use lib './lib'; + +use FindBin; + +BEGIN { + $FindBin::Bin =~ /^(.*)$/; + $FindBin::Bin = $1; +} + +use lib "$FindBin::Bin/lib"; + +use Getopt::Long; use Varnish::Test; -use Data::Dumper; +my $verbose = 0; +my $help = 0; + +my $usage = <<"EOU"; +USAGE: + + $0 CASE1 [ CASE2 ... ] + + where CASEn is either a full case name or a ticket number + +Examples: + + $0 Ticket102 + $0 102 + +EOU + MAIN:{ - my $test = new Varnish::Test($ARGV[0]); - #print STDERR Dumper($test); - $test->main; + $help = 1 unless GetOptions('help|h!' => \$help); + + if (!$help and @ARGV == 0) { + print STDERR "ERROR: Need at least one case name (or ticket number)\n\n"; + $help = 1; + } + + if ($help) { + print STDERR $usage; + exit 1; + } + + my @casenames = (); + + foreach my $arg (@ARGV) { + my $case; + + if ($arg =~ /^(\d+)$/) { + push(@casenames, sprintf('Ticket%03d', $1)); + } + else { + $arg =~ /^(.*)$/; + push(@casenames, $1); + } + } + + my $controller = Varnish::Test->new; + + foreach my $casename (@casenames) { + $controller->run_case($casename); + } + + foreach my $case (@{$controller->{'cases'}}) { + (my $name = ref($case)) =~ s/.*://; + + print sprintf("%s: Successful: %d Failed: %d\n", + $name, $case->{'successful'}, $case->{'failed'}); + } } Property changes on: trunk/varnish-tools/regress/varnish-regress.pl ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Wed Jun 13 11:12:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 13 Jun 2007 13:12:08 +0200 (CEST) Subject: r1511 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070613111208.ED0341EC3F8@projects.linpro.no> Author: des Date: 2007-06-13 13:12:07 +0200 (Wed, 13 Jun 2007) New Revision: 1511 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Let send_command() take care of quoting and assembling the command. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-12 12:26:03 UTC (rev 1510) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-13 11:12:07 UTC (rev 1511) @@ -124,12 +124,20 @@ $name, split(':', $self->{'engine'}->{'config'}->{'server_address'})); } -sub send_command($$) { - my ($self, $command) = @_; +sub send_command($@) { + my ($self, @args) = @_; croak 'not ready' if $self->{'state'} eq 'init'; croak sprintf('busy awaiting earlier command (%s)', $self->{'pending'}) if defined $self->{'pending'}; + foreach (@args) { + if (m/[\s\"\n]/) { + s/\n/\\n/g; + s/\"/\\\"/g; + s/^(.*)$/"$1"/g; + } + } + my $command = join(' ', @args); $self->{'mux'}->write($self->{'stdin'}, $command . "\n"); $self->{'pending'} = $command; } @@ -137,10 +145,13 @@ sub send_vcl($$$) { my ($self, $config, $vcl) = @_; - $vcl =~ s/\n/ /g; - $vcl =~ s/"/\\"/g; + $self->send_command('vcl.inline', $config, $vcl); +} - $self->send_command(sprintf('vcl.inline %s "%s"', $config, $vcl)); +sub use_vcl($$) { + my ($self, $config) = @_; + + $self->send_command('vcl.use', $config); } sub start_child($) { @@ -193,7 +204,7 @@ } $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) - if ($$data =~ /^200 0/ and $self->{'pending'}); + if ($$data =~ /^200 0/ and $self->{'pending'}); $$data = ''; } From des at projects.linpro.no Wed Jun 13 11:26:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 13 Jun 2007 13:26:09 +0200 (CEST) Subject: r1512 - in trunk/varnish-tools/regress/lib/Varnish: . Test Test/Case Message-ID: <20070613112609.6ECDA1EC2B4@projects.linpro.no> Author: des Date: 2007-06-13 13:26:09 +0200 (Wed, 13 Jun 2007) New Revision: 1512 Removed: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm Log: Remove the "magic" StartChild, StopChild and LoadVCL test cases. Instead, Case.pm now has init() and fini() (which can of course be overloaded by individual test classes) which start / stop the child, and load a VCL script if the particular test class being run provides one. In addition, fini() will revert to the initial VCL script ("boot") if a custom script was loaded by init(). Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -1,54 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Case::LoadVCL; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testLoadVCL($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->send_vcl('main', $vcl); - $self->run_loop; - - $self->{'engine'}->{'varnish'}->send_command('vcl.use main'); - $self->run_loop; -} - -sub ev_varnish_command_ok($) { - my ($self) = @_; - - $self->pause_loop; -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -1,52 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Case::StartChild; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testStartChild($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->start_child; - croak 'Inappropriate event' if $self->run_loop ne 'Started'; - return 'OK'; -} - -sub ev_varnish_child_started($) { - my ($self) = @_; - - $self->pause_loop('Started'); -} - -1; Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -1,52 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Case::StopChild; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testStopChild($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->stop_child; - croak 'Inappropriate event' if $self->run_loop ne 'Stopped'; - return 'OK'; -} - -sub ev_varnish_child_stopped($) { - my ($self) = @_; - - $self->pause_loop('Stopped'); -} - -1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -35,6 +35,12 @@ use Carp 'croak'; +our $VCL = " +sub vcl_recv { + pass; +} +"; + sub testVersionMatch($) { my ($self) = @_; @@ -85,14 +91,4 @@ $connection->shutdown; } -sub vcl($) { - my ($self) = @_; - - return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' -sub vcl_recv { - pass; -} -EOVCL -} - 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -35,6 +35,15 @@ use Carp 'croak'; +our $VCL = <send_response($response); } -sub vcl($) { - my ($self) = @_; - - return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' -sub vcl_recv { - if (req.request == "POST" && - (!req.http.content-length || req.http.content-length == "0")) { - lookup; - } -} -EOVCL -} - 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -54,16 +54,59 @@ $self->{'engine'}->log($self, 'CAS: ', $str); } +sub init($) { + my ($self) = @_; + + $self->{'engine'}->{'case'} = $self; + + my $varnish = $self->{'engine'}->{'varnish'}; + + # Load VCL script if we have one + no strict 'refs'; + if (${ref($self)."::VCL"}) { + my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"}; + + $varnish->send_vcl(ref($self), $vcl); + $self->run_loop(); + $varnish->use_vcl(ref($self)); + $self->run_loop(); + } + + # Start the child + $varnish->start_child(); + $self->run_loop(); +} + +sub fini($) { + my ($self) = @_; + + my $varnish = $self->{'engine'}->{'varnish'}; + + # Stop the worker process + $varnish->stop_child(); + $self->run_loop(); + + # Revert to initial VCL script + no strict 'refs'; + if (${ref($self)."::VCL"}) { + $varnish->use_vcl('boot'); + $self->run_loop(); + } + + delete $self->{'engine'}->{'case'}; +} + sub run($;@) { my ($self, @args) = @_; - $self->{'engine'}->{'case'} = $self; - $self->log('Starting ' . ref($self)); no strict 'refs'; - foreach my $method (keys %{ref($self) . '::'}) { - next unless $method =~ m/^test([A-Z]\w+)/; + my @tests = @{ref($self)."::TESTS"}; + if (!@tests) { + @tests = sort grep {/^test(\w+)/} (keys %{ref($self) . '::'}); + } + foreach my $method (@tests) { eval { $self->{'count'} += 1; my $result = $self->$method(@args); @@ -77,8 +120,6 @@ $self->{'count'}, $method, $@)); } } - - delete $self->{'engine'}->{'case'}; } sub run_loop($) { @@ -99,6 +140,12 @@ return Varnish::Test::Client->new($self->{'engine'}); } +sub ev_varnish_command_ok($) { + my ($self) = @_; + + $self->pause_loop; +} + sub ev_client_response($$$) { my ($self, $client, $response) = @_; Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-13 11:12:07 UTC (rev 1511) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-13 11:26:09 UTC (rev 1512) @@ -70,9 +70,6 @@ use Carp 'croak'; use Varnish::Test::Engine; -use Varnish::Test::Case::LoadVCL; -use Varnish::Test::Case::StartChild; -use Varnish::Test::Case::StopChild; sub new($) { my ($this) = @_; @@ -85,7 +82,7 @@ my ($self, @args) = @_; return if defined $self->{'engine'}; - $self->{'engine'} = Varnish::Test::Engine->new(@args); + $self->{'engine'} = Varnish::Test::Engine->new(@args); $self->{'engine'}->run_loop; } @@ -109,15 +106,10 @@ push(@{$self->{'cases'}}, $case); - Varnish::Test::Case::LoadVCL->new($self->{'engine'})->run($case->vcl) - if $case->can('vcl'); - - Varnish::Test::Case::StartChild->new($self->{'engine'})->run; - + $case->init; $case->run; + $case->fini; - Varnish::Test::Case::StopChild->new($self->{'engine'})->run; - $self->stop_engine; } From knutroy at projects.linpro.no Thu Jun 14 12:08:15 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Thu, 14 Jun 2007 14:08:15 +0200 (CEST) Subject: r1513 - in trunk/varnish-tools/regress/lib/Varnish: . Test Test/Case Message-ID: <20070614120815.B743E1EC290@projects.linpro.no> Author: knutroy Date: 2007-06-14 14:08:15 +0200 (Thu, 14 Jun 2007) New Revision: 1513 Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Miscellaneous improvements to regression test framework, most notably changes regarding how events are processed. We now state what events we are waiting for when calling run_loop. The central event dispatcher monitors this list and decides when to pause the loop. Return value from run_loop is the event name and whatever arguments were sent by the event creator, if the event triggered no explicit handler, or otherwise, the return value(s) from the event handler. If subsequent events occur between a loop-pausing event and the time the loop actually pauses, such events are queued and eligible candidates for return value of the next call to run_loop. This way, events will not be lost accidentally, which might happen in previous revisions. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -55,9 +55,10 @@ $request->protocol($cv); $client->send_request($request, 2); - my $response = $self->run_loop; + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - croak 'No (complete) response received' unless defined($response); + croak 'Client time-out before receiving a (complete) response' + if $event eq 'ev_client_timeout'; croak 'Server was not contacted by Varnish' if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; croak sprintf('Protocol version mismatch: got: %s expected: %s', Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -54,11 +54,16 @@ my $request = HTTP::Request->new('POST', '/'); $request->protocol('HTTP/1.1'); $client->send_request($request, 2); - my $response = $self->run_loop; - croak 'No (complete) response received' unless defined($response); + + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + + croak 'Client time-out before receiving a (complete) response' + if $event eq 'ev_client_timeout'; croak 'Empty body' if $response->content eq ''; croak 'Incorrect body' if $response->content ne $body; } + + return 'OK'; } sub ev_server_request($$$$) { Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -67,14 +67,14 @@ my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"}; $varnish->send_vcl(ref($self), $vcl); - $self->run_loop(); + $self->run_loop('ev_varnish_command_ok'); $varnish->use_vcl(ref($self)); - $self->run_loop(); + $self->run_loop('ev_varnish_command_ok'); } # Start the child $varnish->start_child(); - $self->run_loop(); + $self->run_loop('ev_varnish_child_started'); } sub fini($) { @@ -84,13 +84,16 @@ # Stop the worker process $varnish->stop_child(); - $self->run_loop(); + # Wait for both events, the order is unpredictable, so wait for + # any of them both times. + $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok'); + $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok'); # Revert to initial VCL script no strict 'refs'; if (${ref($self)."::VCL"}) { $varnish->use_vcl('boot'); - $self->run_loop(); + $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown'); } delete $self->{'engine'}->{'case'}; @@ -122,41 +125,29 @@ } } -sub run_loop($) { - my ($self) = @_; +sub run_loop($@) { + my ($self, @wait_for) = @_; - $self->{'engine'}->run_loop; + return $self->{'engine'}->run_loop(@wait_for); } -sub pause_loop($;@) { - my ($self, @args) = @_; - - $self->{'engine'}->pause_loop(@args); -} - sub new_client($) { my ($self) = @_; return Varnish::Test::Client->new($self->{'engine'}); } -sub ev_varnish_command_ok($) { - my ($self) = @_; - - $self->pause_loop; -} - sub ev_client_response($$$) { my ($self, $client, $response) = @_; - $self->{'engine'}->pause_loop($response); + return $response; } sub ev_client_timeout($$) { my ($self, $client) = @_; $client->shutdown(2); - $self->{'engine'}->pause_loop; + return $client; } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -99,6 +99,8 @@ $self->got_response($response); } elsif ($data_length < $content_length) { + $self->log(sprintf('Partial response. Bytes in body: %d received, %d expected, %d remaining', + $data_length, $content_length, $content_length - $data_length)); last; } else { @@ -108,6 +110,7 @@ } } else { + $self->log('Partial response. Content-Length unknown. Expecting CLOSE as end-of-response.'); last; } } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -48,7 +48,8 @@ my $self = bless({ 'mux' => IO::Multiplex->new, 'controller' => $controller, - 'config' => \%config }, $class); + 'config' => \%config, + 'pending' => [] }, $class); $self->{'server'} = Varnish::Test::Server->new($self); $self->{'varnish'} = Varnish::Test::Varnish->new($self); @@ -65,30 +66,30 @@ print STDERR $str; } -sub run_loop($) { - my ($self) = @_; +sub run_loop($@) { + my ($self, @wait_for) = @_; - croak 'Engine::run: Already inside select-loop. Your code is buggy.' + croak 'Engine::run_loop: Already inside select-loop. Your code is buggy.' if exists($self->{'in_loop'}); + croak 'Engine::run_loop: No events to wait for.' + if @wait_for == 0; + + while (@{$self->{'pending'}} > 0) { + my ($event, @args) = @{shift @{$self->{'pending'}}}; + return ($event, @args) if grep({ $_ eq $event } @wait_for); + } + + $self->{'wait_for'} = \@wait_for; $self->{'in_loop'} = 1; $self->{'mux'}->loop; delete $self->{'in_loop'}; + delete $self->{'wait_for'}; - return delete $self->{'return'} if exists $self->{'return'}; + return @{shift @{$self->{'pending'}}} if @{$self->{'pending'}} > 0; return undef; } -sub pause_loop($;$) { - my ($self, $return) = @_; - - croak 'Engine::pause: Not inside select-loop. Your code is buggy.' - unless exists($self->{'in_loop'}); - - $self->{'return'} = $return if defined($return); - $self->{'mux'}->endloop; -} - sub shutdown($) { my ($self) = @_; @@ -99,32 +100,27 @@ } } -sub ev_varnish_started($) { - my ($self) = @_; - - $self->pause_loop; -} - sub AUTOLOAD ($;@) { my ($self, @args) = @_; - (my $event_handler = our $AUTOLOAD) =~ s/.*://; + (my $event = our $AUTOLOAD) =~ s/.*://; - return if $event_handler eq 'DESTROY'; + return if $event eq 'DESTROY'; - croak sprintf('received event (%s) while not running a case', $event_handler) - unless defined $self->{'case'}; + croak sprintf('Unknown method "%s"', $event) + unless $event =~ /^ev_(.*)$/; - croak sprintf('Unknown method "%s"', $event_handler) - unless $event_handler =~ /^ev_(.*)$/; + $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); - if ($self->{'case'}->can($event_handler)) { - $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); - return $self->{'case'}->$event_handler(@args); + @args = $self->{'case'}->$event(@args) + if (defined($self->{'case'}) and $self->{'case'}->can($event)); + + if (@{$self->{'pending'}} > 0) { + push(@{$self->{'pending'}}, [ $event, @args ]); } - else { - $self->log($self, 'ENG: ', sprintf('EVENT "%s" IGNORED', $1)); - return undef; + elsif (grep({ $_ eq $event} @{$self->{'wait_for'}}) > 0) { + push(@{$self->{'pending'}}, [ $event, @args ]); + $self->{'mux'}->endloop; } } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -190,7 +190,7 @@ $self->log($$data); - if ($$data =~ /rolling\(2\)\.\.\./) { + if ($$data =~ /^rolling\(2\)\.\.\./m) { $self->{'state'} = 'stopped'; $self->{'engine'}->ev_varnish_started; } @@ -204,8 +204,11 @@ } $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) - if ($$data =~ /^200 0/ and $self->{'pending'}); + if ($$data =~ /^200 \d+/m and $self->{'pending'}); + $self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'}) + if ($$data =~ /^300 \d+/m and $self->{'pending'}); + $$data = ''; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-13 11:26:09 UTC (rev 1512) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 12:08:15 UTC (rev 1513) @@ -83,7 +83,7 @@ return if defined $self->{'engine'}; $self->{'engine'} = Varnish::Test::Engine->new(@args); - $self->{'engine'}->run_loop; + $self->{'engine'}->run_loop('ev_varnish_started'); } sub stop_engine($;$) { From des at projects.linpro.no Thu Jun 14 14:12:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 16:12:32 +0200 (CEST) Subject: r1514 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070614141232.D73621EC3E8@projects.linpro.no> Author: des Date: 2007-06-14 16:12:32 +0200 (Thu, 14 Jun 2007) New Revision: 1514 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm Log: Add a simple test case for Vary: handling. Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 14:12:32 UTC (rev 1514) @@ -0,0 +1,85 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::Vary; + +use strict; +use base 'Varnish::Test::Case'; + +our %languages = ( + 'en' => "Hello World!\n", + 'no' => "Hallo Verden!\n", +); + +sub testVary($) { + my ($self) = @_; + + my $client = $self->new_client; + my $request = HTTP::Request->new('GET', '/'); + + foreach my $lang (keys %languages) { + $request->header('Accept-Language', $lang); + $request->protocol('HTTP/1.1'); + $client->send_request($request, 2); + my $response = $self->run_loop; + die 'No (complete) response received' + unless defined($response); + die 'Empty body' + if $response->content eq ''; + die 'Incorrect body' + if $response->content ne $languages{$lang}; + } +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + + my $body; + my @headers; + if (my $lang = $request->header("Accept-Language")) { + $lang = 'en' + unless ($lang && $languages{$lang}); + $body = $languages{$lang}; + push(@headers, ('Language', $lang)); + } else { + die 'Not ready for this!'; + } + + my $response = HTTP::Response->new(200, undef, + [ 'Connection', 'close', + 'Content-Length', length($body), + 'Vary', 'Accept-Language', + @headers ], + $body); + $response->protocol('HTTP/1.1'); + $connection->send_response($response); +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jun 14 14:14:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 16:14:12 +0200 (CEST) Subject: r1515 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070614141412.472B31EC290@projects.linpro.no> Author: des Date: 2007-06-14 16:14:12 +0200 (Thu, 14 Jun 2007) New Revision: 1515 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm Log: Oops - don't lie about closing the connection. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 14:12:32 UTC (rev 1514) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 14:14:12 UTC (rev 1515) @@ -73,8 +73,7 @@ } my $response = HTTP::Response->new(200, undef, - [ 'Connection', 'close', - 'Content-Length', length($body), + [ 'Content-Length', length($body), 'Vary', 'Accept-Language', @headers ], $body); From des at linpro.no Thu Jun 14 16:30:43 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu, 14 Jun 2007 18:30:43 +0200 Subject: r1505 - trunk/varnish-cache/bin/varnishd In-Reply-To: <20070610074751.105DE1EC035@projects.linpro.no> (phk@projects.linpro.no's message of "Sun\, 10 Jun 2007 09\:47\:51 +0200 \(CEST\)") References: <20070610074751.105DE1EC035@projects.linpro.no> Message-ID: <87lkemwlak.fsf@des.linpro.no> phk at projects.linpro.no writes: > Log: > Fix a bug I introduced in the workspace rewamp: Don't throw away > perfectly good pipelined data. Actually, this commit breaks our regression test for #102: des at des ~/projects/varnish/trunk/varnish-tools/regress% ./varnish-regress.pl 102 [...] CLI: Tx| POST / HTTP/1.1 CLI: Tx| VAR: Cache child died pid=15715 status=0x8b VAR: Clean child VAR: Child cleaned (status=0x8b is a segfault) DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Thu Jun 14 16:38:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 18:38:59 +0200 (CEST) Subject: r1516 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test Message-ID: <20070614163859.5A1151EC030@projects.linpro.no> Author: des Date: 2007-06-14 18:38:58 +0200 (Thu, 14 Jun 2007) New Revision: 1516 Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/varnish-regress.pl Log: Rather than start and stop the engine for every test case, just stop (and restart) it if a test failed. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 14:14:12 UTC (rev 1515) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 16:38:58 UTC (rev 1516) @@ -97,6 +97,11 @@ } delete $self->{'engine'}->{'case'}; + + if ($self->{'failed'}) { + die sprintf("%d out of %d tests failed\n", + $self->{'failed'}, $self->{'count'}); + } } sub run($;@) { Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 14:14:12 UTC (rev 1515) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 16:38:58 UTC (rev 1516) @@ -67,8 +67,6 @@ package Varnish::Test; -use Carp 'croak'; - use Varnish::Test::Engine; sub new($) { @@ -89,7 +87,10 @@ sub stop_engine($;$) { my ($self) = @_; - (delete $self->{'engine'})->shutdown if defined $self->{'engine'}; + if (defined($self->{'engine'})) { + $self->{'engine'}->shutdown(); + delete $self->{'engine'}; + } } sub run_case($$) { @@ -98,19 +99,23 @@ my $module = 'Varnish::Test::Case::' . $name; eval 'use ' . $module; - croak $@ if $@; + die $@ if $@; - $self->start_engine; + $self->start_engine(); my $case = $module->new($self->{'engine'}); push(@{$self->{'cases'}}, $case); - $case->init; - $case->run; - $case->fini; - - $self->stop_engine; + eval { + $case->init(); + $case->run(); + $case->fini(); + }; + if ($@) { + $self->{'engine'}->log($self, 'TST: ', $@); + $self->stop_engine(); + } } 1; Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 14:14:12 UTC (rev 1515) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 16:38:58 UTC (rev 1516) @@ -86,16 +86,18 @@ } } - my $controller = Varnish::Test->new; + my $controller = new Varnish::Test; + $controller->start_engine(); foreach my $casename (@casenames) { $controller->run_case($casename); } + $controller->stop_engine(); foreach my $case (@{$controller->{'cases'}}) { (my $name = ref($case)) =~ s/.*://; - print sprintf("%s: Successful: %d Failed: %d\n", - $name, $case->{'successful'}, $case->{'failed'}); + printf("%s: Successful: %d Failed: %d\n", + $name, $case->{'successful'}, $case->{'failed'}); } } From des at projects.linpro.no Thu Jun 14 16:44:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 18:44:59 +0200 (CEST) Subject: r1517 - in trunk/varnish-tools/regress/lib/Varnish/Test: . Case Message-ID: <20070614164459.69F441EC290@projects.linpro.no> Author: des Date: 2007-06-14 18:44:59 +0200 (Thu, 14 Jun 2007) New Revision: 1517 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Consistently replace croak with die, and fix a couple of cases where $@ was incorrectly used in place of $!. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -33,8 +33,6 @@ use strict; use base 'Varnish::Test::Case'; -use Carp 'croak'; - our $VCL = " sub vcl_recv { pass; @@ -57,13 +55,13 @@ my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - croak 'Client time-out before receiving a (complete) response' - if $event eq 'ev_client_timeout'; - croak 'Server was not contacted by Varnish' - if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; - croak sprintf('Protocol version mismatch: got: %s expected: %s', - $response->protocol, $sv) - if $response->protocol ne $sv; + die 'Client time-out before receiving a (complete) response\n' + if $event eq 'ev_client_timeout'; + die 'Server was not contacted by Varnish\n' + if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; + die sprintf('Protocol version mismatch: got: %s expected: %s\n', + $response->protocol, $sv) + if $response->protocol ne $sv; return sprintf("Client: %s Server: %s", $cv, $sv); } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -33,8 +33,6 @@ use strict; use base 'Varnish::Test::Case'; -use Carp 'croak'; - our $VCL = <run_loop('ev_client_response', 'ev_client_timeout'); - croak 'Client time-out before receiving a (complete) response' - if $event eq 'ev_client_timeout'; - croak 'Empty body' if $response->content eq ''; - croak 'Incorrect body' if $response->content ne $body; + die 'Client time-out before receiving a (complete) response\n' + if $event eq 'ev_client_timeout'; + die 'Empty body\n' + if $response->content eq ''; + die 'Incorrect body\n' + if $response->content ne $body; } return 'OK'; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -31,7 +31,6 @@ package Varnish::Test::Case; use strict; -use Carp 'croak'; use Varnish::Test::Logger; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -31,7 +31,6 @@ package Varnish::Test::Client; use strict; -use Carp 'croak'; use IO::Socket::INET; @@ -59,7 +58,7 @@ my $fh = IO::Socket::INET->new('Proto' => 'tcp', 'PeerAddr' => 'localhost', 'PeerPort' => '8080') - or croak "socket: $@"; + or die "socket(): $!\n"; $self->{'fh'} = $fh; $self->{'mux'}->add($fh); @@ -120,7 +119,8 @@ my ($self, $mux, $fh, $data) = @_; if ($$data ne '') { - croak 'Junk or incomplete response' unless $$data =~ "\n\r?\n"; + die 'Junk or incomplete response\n' + unless $$data =~ "\n\r?\n"; my $response = HTTP::Response->parse($$data); $$data = ''; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -31,7 +31,6 @@ package Varnish::Test::Engine; use strict; -use Carp 'croak'; use Varnish::Test::Server; use Varnish::Test::Varnish; @@ -69,10 +68,10 @@ sub run_loop($@) { my ($self, @wait_for) = @_; - croak 'Engine::run_loop: Already inside select-loop. Your code is buggy.' + die 'Engine::run_loop: Already inside select-loop. Your code is buggy.\n' if exists($self->{'in_loop'}); - croak 'Engine::run_loop: No events to wait for.' + die 'Engine::run_loop: No events to wait for.\n' if @wait_for == 0; while (@{$self->{'pending'}} > 0) { @@ -107,13 +106,13 @@ return if $event eq 'DESTROY'; - croak sprintf('Unknown method "%s"', $event) - unless $event =~ /^ev_(.*)$/; + die sprintf('Unknown method "%s"\n', $event) + unless $event =~ /^ev_(.*)$/; $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); @args = $self->{'case'}->$event(@args) - if (defined($self->{'case'}) and $self->{'case'}->can($event)); + if (defined($self->{'case'}) and $self->{'case'}->can($event)); if (@{$self->{'pending'}} > 0) { push(@{$self->{'pending'}}, [ $event, @args ]); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -31,7 +31,6 @@ package Varnish::Test::Server; use strict; -use Carp 'croak'; use IO::Socket::INET; @@ -46,7 +45,7 @@ 'LocalPort' => $port, 'Listen' => 4, 'ReuseAddr' => 1) - or croak "socket: $@"; + or die "socket(): $!\n"; my $self = bless({ 'engine' => $engine, 'mux' => $engine->{'mux'}, @@ -98,7 +97,6 @@ package Varnish::Test::Server::Connection; use strict; -use Carp 'croak'; sub new($$) { my ($this, $server, $fh) = @_; @@ -160,7 +158,8 @@ sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; - croak 'Junk or incomplete request' unless $$data eq ''; + die 'Junk or incomplete request\n' + unless $$data eq ''; } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-14 16:38:58 UTC (rev 1516) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-14 16:44:59 UTC (rev 1517) @@ -31,7 +31,6 @@ package Varnish::Test::Varnish; use strict; -use Carp 'croak'; use Socket; @@ -58,7 +57,8 @@ delete $SIG{CHLD}; my $pid = fork; - croak "fork(): $@\n" unless defined($pid); + die "fork(): $!\n" + unless defined($pid); if ($pid == 0) { # Child @@ -126,9 +126,10 @@ sub send_command($@) { my ($self, @args) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak sprintf('busy awaiting earlier command (%s)', $self->{'pending'}) - if defined $self->{'pending'}; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die sprintf('busy awaiting earlier command (%s)\n', $self->{'pending'}) + if defined $self->{'pending'}; foreach (@args) { if (m/[\s\"\n]/) { @@ -156,16 +157,20 @@ sub start_child($) { my ($self) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak 'already started' if $self->{'state'} eq 'started'; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die 'already started\n' + if $self->{'state'} eq 'started'; $self->send_command("start"); } sub stop_child($) { my ($self) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak 'already stopped' if $self->{'state'} eq 'stopped'; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die 'already stopped\n' + if $self->{'state'} eq 'stopped'; $self->send_command("stop"); } @@ -180,7 +185,8 @@ my ($self, $signal) = @_; $signal ||= 15; - croak 'Not running' unless defined($self->{'pid'}); + die 'Not running\n' + unless defined($self->{'pid'}); kill($signal, $self->{'pid'}); delete $self->{'pid'}; } From des at projects.linpro.no Thu Jun 14 16:47:13 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 18:47:13 +0200 (CEST) Subject: r1518 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test lib/Varnish/Test/Case Message-ID: <20070614164713.85A0C1EC030@projects.linpro.no> Author: des Date: 2007-06-14 18:47:13 +0200 (Thu, 14 Jun 2007) New Revision: 1518 Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm trunk/varnish-tools/regress/varnish-regress.pl Log: Remove -T now that the framework runs as an unprivileged user. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. @@ -80,7 +80,6 @@ print STDERR sprintf("Starting Varnish with options: %s\n", join(' ', @opts)); - $ENV{'PATH'} = '/opt/varnish/sbin:/bin:/usr/bin'; exec('varnishd', @opts); exit(1); } Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 16:44:59 UTC (rev 1517) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 16:47:13 UTC (rev 1518) @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w #- # Copyright (c) 2006 Linpro AS # All rights reserved. From des at projects.linpro.no Thu Jun 14 17:07:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 14 Jun 2007 19:07:46 +0200 (CEST) Subject: r1519 - in trunk/varnish-tools/regress: . lib/Varnish Message-ID: <20070614170746.79FDB1EC290@projects.linpro.no> Author: des Date: 2007-06-14 19:07:46 +0200 (Thu, 14 Jun 2007) New Revision: 1519 Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/varnish-regress.pl Log: Add code to enumerate all available cases. If no case name is specified, varnish-regress.pl will now run them all. Also simplify MAIN a bit. Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 16:47:13 UTC (rev 1518) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-14 17:07:46 UTC (rev 1519) @@ -67,6 +67,7 @@ package Varnish::Test; +use Varnish::Test::Case; use Varnish::Test::Engine; sub new($) { @@ -93,6 +94,19 @@ } } +sub cases($) { + my ($self) = @_; + + my $dir = $INC{'Varnish/Test/Case.pm'}; + $dir =~ s/\.pm$/\//; + local *DIR; + opendir(DIR, $dir) + or die("$dir: $!\n"); + my @cases = sort grep { s/^(\w+)\.pm$/$1/ } readdir(DIR); + closedir(DIR); + return @cases; +} + sub run_case($$) { my ($self, $name) = @_; Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 16:47:13 UTC (rev 1518) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-14 17:07:46 UTC (rev 1519) @@ -32,20 +32,13 @@ use FindBin; -BEGIN { - $FindBin::Bin =~ /^(.*)$/; - $FindBin::Bin = $1; -} - use lib "$FindBin::Bin/lib"; use Getopt::Long; use Varnish::Test; -my $verbose = 0; -my $help = 0; - -my $usage = <<"EOU"; +sub usage() { + print STDERR < \$help); + GetOptions('help|h!' => \&usage) + or usage(); - if (!$help and @ARGV == 0) { - print STDERR "ERROR: Need at least one case name (or ticket number)\n\n"; - $help = 1; - } + my $controller = new Varnish::Test; - if ($help) { - print STDERR $usage; - exit 1; + if (!@ARGV) { + @ARGV = $controller->cases(); + } else { + map { s/^(\d+)$/sprintf('Ticket%03d', $1)/e } @ARGV; } - my @casenames = (); - - foreach my $arg (@ARGV) { - my $case; - - if ($arg =~ /^(\d+)$/) { - push(@casenames, sprintf('Ticket%03d', $1)); - } - else { - $arg =~ /^(.*)$/; - push(@casenames, $1); - } - } - - my $controller = new Varnish::Test; - $controller->start_engine(); - foreach my $casename (@casenames) { + foreach my $casename (@ARGV) { $controller->run_case($casename); } $controller->stop_engine(); From des at projects.linpro.no Fri Jun 15 09:03:35 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 11:03:35 +0200 (CEST) Subject: r1520 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070615090335.4DA801EC418@projects.linpro.no> Author: des Date: 2007-06-15 11:03:34 +0200 (Fri, 15 Jun 2007) New Revision: 1520 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm Log: Catch up with framework changes. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-14 17:07:46 UTC (rev 1519) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-15 09:03:34 UTC (rev 1520) @@ -48,13 +48,14 @@ $request->header('Accept-Language', $lang); $request->protocol('HTTP/1.1'); $client->send_request($request, 2); - my $response = $self->run_loop; - die 'No (complete) response received' + my ($event, $response) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "No (complete) response received\n" unless defined($response); - die 'Empty body' - if $response->content eq ''; - die 'Incorrect body' - if $response->content ne $languages{$lang}; + die "Empty body\n" + if $response->content() eq ''; + die "Incorrect body\n" + if $response->content() ne $languages{$lang}; } } From cecilihf at projects.linpro.no Fri Jun 15 09:18:06 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 15 Jun 2007 11:18:06 +0200 (CEST) Subject: r1521 - in trunk/varnish-cache: bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishstat bin/varnishtop include lib/libvarnishapi Message-ID: <20070615091806.E11041EC030@projects.linpro.no> Author: cecilihf Date: 2007-06-15 11:18:06 +0200 (Fri, 15 Jun 2007) New Revision: 1521 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/varnishd.1 trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishhist/varnishhist.1 trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.1 trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishstat/varnishstat.1 trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtop/varnishtop.1 trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/shmlog.c Log: Added the -n option for specifying a name for varnishd. All files are now stored under /tmp/ where is either a specified name or the hostname. All the varnish tools have also been updated to let the user specify the name of the varnish instance to use. The name must conform to the hostname standard, but a test for this is not yet implemented. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-15 09:18:06 UTC (rev 1521) @@ -119,6 +119,9 @@ /* Ping interval */ unsigned ping_interval; + + /* Varnishd name */ + char *name; }; extern volatile struct params *params; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -30,6 +30,7 @@ */ #include +#include #include #include @@ -497,6 +498,65 @@ /*--------------------------------------------------------------------*/ +static void +tweak_name(struct cli *cli, struct parspec *par, const char* arg) +{ + struct stat st; + struct stat st_old; + char *path; + char *old_path; + int renaming; + (void)par; + + if (arg != NULL) { + /* Check that the new name follows hostname convention */ + /* [a-zA-Z0-9.-] */ + asprintf(&old_path, "/tmp/%s", master.name); + master.name = strdup(arg); + /* Create/rename the temporary varnish directory */ + asprintf(&path, "/tmp/%s", arg); + renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode)); + if (stat(path, &st)) { + if (renaming) { + if (renaming && rename(old_path, path)) { + cli_out(cli, + "Error: Directory %s could not be " + "renamed to %s", + old_path, path); + cli_result(cli, CLIS_PARAM); + return; + } + } else { + if (mkdir(path, 0600)) { + fprintf(stderr, + "Error: Directory %s could not be created", + path); + exit (2); + } + } + } else if (renaming) { + cli_out(cli, "Error: Directory %s could not be " + "renamed to %s", old_path, path); + cli_result(cli, CLIS_PARAM); + return; + } + stat(path, &st); + /* /tmp/varnishname should now be a directory */ + if (!S_ISDIR(st.st_mode)) { + fprintf(stderr, + "Error: \"%s\" " + "is not a directory\n", path); + exit (2); + } + /* Everything is fine, store the (new) name */ + master.name = strdup(arg); + } + else + cli_out(cli, "\"%s\"", master.name); +} + +/*--------------------------------------------------------------------*/ + /* * Make sure to end all lines with either a space or newline of the * formatting will go haywire. @@ -513,7 +573,6 @@ "\nNB: We don't know yet if it is a good idea to change " \ "this parameter. Caution advised.\n" - /* * Remember to update varnishd.1 whenever you add / remove a parameter or * change its default value. @@ -671,6 +730,12 @@ "it possible to attach a debugger to the child.\n" MUST_RESTART, "3", "seconds" }, + { "name", tweak_name, + "Name of varnishd instance. Must follow hostname " + "naming conventions. Makes it possible to run " + "multiple varnishd instances on one server.\n" + EXPERIMENTAL, + "hostname"}, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -52,6 +52,7 @@ #include "mgt.h" #include "mgt_cli.h" +#include "heritage.h" #include "vss.h" @@ -144,7 +145,7 @@ void *p; /* Create temporary C source file */ - sf = strdup("/tmp/vcl.XXXXXXXX"); + asprintf(&sf, "/tmp/%s/vcl.XXXXXXXX", params->name); assert(sf != NULL); sfd = mkstemp(sf); if (sfd < 0) { @@ -168,16 +169,16 @@ rewind(fs); /* Name the output shared library */ - of = strdup("/tmp/vcl.XXXXXXXX"); + asprintf(&of, "/tmp/%s/vcl.XXXXXXXX", params->name); assert(of != NULL); of = mktemp(of); assert(of != NULL); /* Attempt to open a pipe to the system C-compiler */ sprintf(buf, - "ln -f %s /tmp/_.c ;" /* XXX: for debugging */ + "ln -f %s /tmp/%s/_.c ;" /* XXX: for debugging */ "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", - sf, of, sf); + sf, params->name, of, sf); fo = popen(buf, "r"); if (fo == NULL) { Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-15 09:18:06 UTC (rev 1521) @@ -33,7 +33,7 @@ struct sess; struct iovec; -typedef void storage_init_f(struct stevedore *, const char *spec); +typedef void storage_init_f(struct stevedore *, const char *spec, const char *name); typedef void storage_open_f(struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef void storage_trim_f(struct storage *, size_t size); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -242,7 +242,7 @@ } static void -smf_init(struct stevedore *parent, const char *spec) +smf_init(struct stevedore *parent, const char *spec, const char *varnish_name) { char *size; char *p, *q; @@ -262,9 +262,8 @@ /* If no size specified, use 50% of filesystem free space */ if (spec == NULL || *spec == '\0') - spec = "/tmp,50%"; - - if (strchr(spec, ',') == NULL) + asprintf(&p, "/tmp/%s,50%%", varnish_name); + else if (strchr(spec, ',') == NULL) asprintf(&p, "%s,", spec); else p = strdup(spec); Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -42,6 +42,7 @@ .Op Fl f Ar config .Op Fl g Ar group .Op Fl h Ar type Ns Op , Ns Ar options +.Op Fl n Ar name .Op Fl P Ar file .Op Fl p Ar param Ns = Ns Ar value .Op Fl s Ar type Ns Op , Ns Ar options @@ -127,6 +128,10 @@ See .Sx Hash Algorithms for a list of supported algorithms. +.It Fl n +Specify a name for this instance. If +.Fl n +is not specified, hostname is used. Files will be stored in /tmp// .It Fl P Ar file Write the process's PID to the specified .Ar file . @@ -494,6 +499,11 @@ .Pp The default is .Dv off . +.It Va name +The name if this varnishd instance. All temporary files are stored in +/tmp// +.Pp +The default is the hostname .El .Sh SEE ALSO .Xr varnishlog 1 , Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -150,7 +150,7 @@ heritage.stevedore = malloc(sizeof *heritage.stevedore); *heritage.stevedore = *stp; if (stp->init != NULL) - stp->init(heritage.stevedore, q); + stp->init(heritage.stevedore, q, params->name); } /*--------------------------------------------------------------------*/ @@ -177,6 +177,7 @@ " -h classic [default]"); fprintf(stderr, " %-28s # %s\n", "", " -h classic,"); + fprintf(stderr, " %-28s # %s\n", "-n name", "varnishd instance name"); fprintf(stderr, " %-28s # %s\n", "-P file", "PID file"); fprintf(stderr, " %-28s # %s\n", "-p param=value", "set parameter"); @@ -402,6 +403,7 @@ const char *b_arg = NULL; const char *f_arg = NULL; const char *h_arg = "classic"; + char *n_arg = NULL; const char *P_arg = NULL; const char *s_arg = "file"; const char *T_arg = NULL; @@ -409,6 +411,7 @@ char *p; struct cli cli[1]; struct pidfh *pfh = NULL; + char buf[BUFSIZ]; setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -424,7 +427,7 @@ MCF_ParamInit(cli); cli_check(cli); - while ((o = getopt(argc, argv, "a:b:Cdf:g:h:P:p:s:T:t:u:Vw:")) != -1) + while ((o = getopt(argc, argv, "a:b:Cdf:g:h:n:P:p:s:T:t:u:Vw:")) != -1) switch (o) { case 'a': MCF_ParamSet(cli, "listen_address", optarg); @@ -448,6 +451,9 @@ case 'h': h_arg = optarg; break; + case 'n': + n_arg = optarg; + break; case 'P': P_arg = optarg; break; @@ -498,7 +504,13 @@ fprintf(stderr, "One of -b or -f must be specified\n"); usage(); } - + + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } + MCF_ParamSet(cli, "name", n_arg); + if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) { perror(P_arg); exit(1); @@ -512,7 +524,8 @@ setup_storage(s_arg); setup_hash(h_arg); - VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); + sprintf(buf, "/tmp/%s/%s", params->name, SHMLOG_FILENAME); + VSL_MgtInit(buf, 8*1024*1024); if (d_flag == 1) DebugStunt(); Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.1 =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -42,6 +42,7 @@ .Op Fl d .Op Fl I Ar regex .Op Fl i Ar tag +.Op Fl n Ar varnish_name .Op Fl r Ar file .Op Fl V .Op Fl w Ar delay @@ -100,6 +101,12 @@ nor .Fl i is specified, all log entries are included. +.It Fl n +Specify the name of the varnishd to get logs from. If +.Fl n +is not specified, hostname is used. If varnishd was started with +.Fl n +the option must be specified. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -40,6 +40,7 @@ #include #include #include +#include #include "libvarnish.h" #include "shmlog.h" @@ -170,7 +171,7 @@ usage(void) { fprintf(stderr, - "usage: varnishhist %s [-V] [-w delay]\n", VSL_USAGE); + "usage: varnishhist %s [-n varnish_name] [-V] [-w delay]\n", VSL_USAGE); exit(1); } @@ -179,11 +180,15 @@ { int i, c, x; struct VSL_data *vd; + char *n_arg = NULL; vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) { switch (c) { + case 'n': + n_arg = optarg; + break; case 'V': varnish_version("varnishhist"); exit(0); @@ -197,7 +202,12 @@ } } - if (VSL_OpenLog(vd)) + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } + + if (VSL_OpenLog(vd, n_arg)) exit (1); c_hist = 10.0 / log(10.0); Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.1 =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -46,6 +46,7 @@ .Op Fl i Ar tag .Op Fl o .Op Fl P Ar file +.Op Fl n Ar varnish_name .Op Fl r Ar file .Op Fl V .Op Fl w Ar file @@ -106,6 +107,12 @@ nor .Fl i is specified, all log entries are included. +.It Fl n +Specify the name of the varnishd to get logs from. If +.Fl n +is not specified, hostname is used. If varnishd was started with +.Fl n +the option must be specified. .It Fl o Group log entries by request ID. This has no effect when writing to a file using the Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -39,6 +39,7 @@ #include #include #include +#include #ifndef HAVE_DAEMON #include "compat/daemon.h" @@ -273,7 +274,7 @@ usage(void) { fprintf(stderr, - "usage: varnishlog %s [-aDoV] [-P file] [-w file]\n", VSL_USAGE); + "usage: varnishlog %s [-aDoV] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE); exit(1); } @@ -284,12 +285,13 @@ int a_flag = 0, D_flag = 0, o_flag = 0; const char *P_arg = NULL; const char *w_arg = NULL; + char *n_arg = NULL; struct pidfh *pfh = NULL; struct VSL_data *vd; vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "aDoP:Vw:")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "aDon:P:Vw:")) != -1) { switch (c) { case 'a': a_flag = 1; @@ -297,6 +299,9 @@ case 'D': D_flag = 1; break; + case 'n': + n_arg = optarg; + break; case 'o': o_flag = 1; break; @@ -329,7 +334,12 @@ if (o_flag && w_arg != NULL) usage(); - if (VSL_OpenLog(vd)) + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } + + if (VSL_OpenLog(vd, n_arg)) exit(1); if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) { Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -43,6 +43,7 @@ .Op Fl d .Op Fl I Ar regex .Op Fl i Ar tag +.Op Fl n Ar varnish_name .Op Fl r Ar file .Op Fl V .Op Fl w Ar file @@ -101,6 +102,12 @@ nor .Fl i is specified, all log entries are included. +.It Fl n +Specify the name of the varnishd to get logs from. If +.Fl n +is not specified, hostname is used. If varnishd was started with +.Fl n +the option must be specified. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -67,6 +67,7 @@ #include #include #include +#include #include "libvarnish.h" #include "shmlog.h" @@ -433,7 +434,7 @@ usage(void) { - fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS); + fprintf(stderr, "usage: varnishncsa %s [-aV] [-n varnish_name] [-w file]\n", VSL_ARGS); exit(1); } @@ -443,12 +444,13 @@ int i, c; struct VSL_data *vd; const char *ofn = NULL; + char *n_arg = NULL; int append = 0; FILE *of; vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "aVw:")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "an:Vw:")) != -1) { i = VSL_Arg(vd, c, optarg); if (i < 0) exit (1); @@ -458,6 +460,9 @@ case 'a': append = 1; break; + case 'n': + n_arg = optarg; + break; case 'V': varnish_version("varnishncsa"); exit(0); @@ -470,8 +475,13 @@ usage(); } } + + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } - if (VSL_OpenLog(vd)) + if (VSL_OpenLog(vd, n_arg)) exit(1); if (ofn) { Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -37,6 +37,7 @@ .Sh SYNOPSIS .Nm .Op Fl 1 +.Op Fl n Ar varnish_name .Op Fl V .Op Fl w Ar delay .Sh DESCRIPTION @@ -51,6 +52,12 @@ .It Fl 1 Instead of presenting of a continuously updated display, print the statistics once and exit. +.It Fl n +Specify the name of the varnishd to get logs from. If +.Fl n +is not specified, hostname is used. If varnishd was started with +.Fl n +the option must be specified. .It Fl V Display the version number and exit. .It Fl w Ar delay Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -38,6 +38,7 @@ #include #include #include +#include #ifndef HAVE_CLOCK_GETTIME #include "compat/clock_gettime.h" @@ -130,7 +131,7 @@ static void usage(void) { - fprintf(stderr, "usage: varnishstat [-1V] [-w delay]\n"); + fprintf(stderr, "usage: varnishstat [-1V] [-n varnish_name] [-w delay]\n"); exit(1); } @@ -140,14 +141,16 @@ int c; struct varnish_stats *VSL_stats; int delay = 1, once = 0; + char *n_arg = NULL; - VSL_stats = VSL_OpenStats(); - - while ((c = getopt(argc, argv, "1Vw:")) != -1) { + while ((c = getopt(argc, argv, "1n:Vw:")) != -1) { switch (c) { case '1': once = 1; break; + case 'n': + n_arg = optarg; + break; case 'V': varnish_version("varnishstat"); exit(0); @@ -158,7 +161,16 @@ usage(); } } + + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } + if (!(VSL_stats = VSL_OpenStats(n_arg))) { + exit(1); + } + if (!once) { do_curses(VSL_stats, delay); } else { Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.1 =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-15 09:18:06 UTC (rev 1521) @@ -44,6 +44,7 @@ .Op Fl f .Op Fl I Ar regex .Op Fl i Ar tag +.Op Fl n Ar varnish_name .Op Fl r Ar file .Op Fl V .Op Fl X Ar regex @@ -116,6 +117,12 @@ nor .Fl i is specified, all log entries are included. +.It Fl n +Specify the name of the varnishd to get logs from. If +.Fl n +is not specified, hostname is used. If varnishd was started with +.Fl n +the option must be specified. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -38,6 +38,7 @@ #include #include #include +#include #include "vsb.h" @@ -63,7 +64,7 @@ static void usage(void) { - fprintf(stderr, "usage: varnishtop %s [-1V]\n", VSL_USAGE); + fprintf(stderr, "usage: varnishtop %s [-1V] [-n varnish_name]\n", VSL_USAGE); exit(1); } @@ -112,11 +113,11 @@ unsigned u, v; struct top *tp, *tp2; int f_flag = 0; + char *n_arg = NULL; - vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "1fV")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) { i = VSL_Arg(vd, c, optarg); if (i < 0) exit (1); @@ -126,6 +127,9 @@ case '1': VSL_NonBlocking(vd, 1); break; + case 'n': + n_arg = optarg; + break; case 'f': f_flag = 1; break; @@ -136,8 +140,13 @@ usage(); } } + + if (n_arg == NULL) { + n_arg = malloc(HOST_NAME_MAX+1); + gethostname(n_arg, HOST_NAME_MAX+1); + } - if (VSL_OpenLog(vd)) + if (VSL_OpenLog(vd, n_arg)) exit (1); initscr(); Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/include/shmlog.h 2007-06-15 09:18:06 UTC (rev 1521) @@ -36,7 +36,7 @@ #ifndef SHMLOG_H_INCLUDED #define SHMLOG_H_INCLUDED -#define SHMLOG_FILENAME "/tmp/_.vsl" +#define SHMLOG_FILENAME "_.vsl" #include Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/include/varnishapi.h 2007-06-15 09:18:06 UTC (rev 1521) @@ -50,12 +50,12 @@ struct VSL_data; struct VSL_data *VSL_New(void); void VSL_Select(struct VSL_data *vd, unsigned tag); -int VSL_OpenLog(struct VSL_data *vd); +int VSL_OpenLog(struct VSL_data *vd, char *varnish_name); void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); -struct varnish_stats *VSL_OpenStats(void); +struct varnish_stats *VSL_OpenStats(char *varnish_name); extern const char *VSL_tags[256]; /* varnish_debug.c */ Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-15 09:03:34 UTC (rev 1520) +++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-15 09:18:06 UTC (rev 1521) @@ -102,29 +102,32 @@ /*--------------------------------------------------------------------*/ static int -vsl_shmem_map(void) +vsl_shmem_map(char* varnish_name) { int i; struct shmloghead slh; + char buf[BUFSIZ]; if (vsl_lh != NULL) return (0); - vsl_fd = open(SHMLOG_FILENAME, O_RDONLY); + sprintf(buf, "/tmp/%s/%s", varnish_name, SHMLOG_FILENAME); + + vsl_fd = open(buf, O_RDONLY); if (vsl_fd < 0) { fprintf(stderr, "Cannot open %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); + buf, strerror(errno)); return (1); } i = read(vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { fprintf(stderr, "Cannot read %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); + buf, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { fprintf(stderr, "Wrong magic number in file %s\n", - SHMLOG_FILENAME); + buf); return (1); } @@ -132,7 +135,7 @@ PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0); if (vsl_lh == MAP_FAILED) { fprintf(stderr, "Cannot mmap %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); + buf, strerror(errno)); return (1); } return (0); @@ -167,7 +170,7 @@ /*--------------------------------------------------------------------*/ int -VSL_OpenLog(struct VSL_data *vd) +VSL_OpenLog(struct VSL_data *vd, char *varnish_name) { unsigned char *p; @@ -175,7 +178,7 @@ if (vd->fi != NULL) return (0); - if (vsl_shmem_map()) + if (vsl_shmem_map(varnish_name)) return (1); vd->head = vsl_lh; @@ -474,10 +477,10 @@ } struct varnish_stats * -VSL_OpenStats(void) +VSL_OpenStats(char *varnish_name) { - if (vsl_shmem_map()) + if (vsl_shmem_map(varnish_name)) return (NULL); return (&vsl_lh->stats); } From des at projects.linpro.no Fri Jun 15 09:23:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 11:23:25 +0200 (CEST) Subject: r1522 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test lib/Varnish/Test/Report Message-ID: <20070615092325.818111EC2EE@projects.linpro.no> Author: des Date: 2007-06-15 11:23:25 +0200 (Fri, 15 Jun 2007) New Revision: 1522 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report/ trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/varnish-regress.pl Log: Add reporting functionality. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 09:18:06 UTC (rev 1521) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 09:23:25 UTC (rev 1522) @@ -36,6 +36,7 @@ use HTTP::Request; use HTTP::Response; +use Time::HiRes qw(gettimeofday tv_interval); sub new($$) { my ($this, $engine) = @_; @@ -113,6 +114,7 @@ if (!@tests) { @tests = sort grep {/^test(\w+)/} (keys %{ref($self) . '::'}); } + $self->{'start'} = [gettimeofday()]; foreach my $method (@tests) { eval { $self->{'count'} += 1; @@ -127,6 +129,7 @@ $self->{'count'}, $method, $@)); } } + $self->{'stop'} = [gettimeofday()]; } sub run_loop($@) { @@ -141,6 +144,22 @@ return Varnish::Test::Client->new($self->{'engine'}); } +sub results($) { + my ($self) = @_; + + no strict 'refs'; + my $name = ${ref($self)."::NAME"} || (split('::', ref($self)))[-1]; + my $descr = ${ref($self)."::DESCR"} || "N/A"; + return { + 'name' => $name, + 'descr' => $descr, + 'count' => $self->{'count'}, + 'pass' => $self->{'successful'}, + 'fail' => $self->{'failed'}, + 'time' => tv_interval($self->{'start'}, $self->{'stop'}), + }; +} + sub ev_client_response($$$) { my ($self, $client, $response) = @_; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm 2007-06-15 09:23:25 UTC (rev 1522) @@ -0,0 +1,44 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Report::HTML; + +use strict; + +use base 'Varnish::Test::Report'; + +sub init($) { + my ($self) = @_; + + $self->{'template'} = 'report.html'; + $self->{'config'}->{'TAG_STYLE'} = 'html'; +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-06-15 09:23:25 UTC (rev 1522) @@ -0,0 +1,43 @@ + + + + + Varnish test report + + + + +

Varnish test report

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTimeTestsPassedFailedDescription
+ + Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-06-15 09:23:25 UTC (rev 1522) @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Report; + +use strict; + +use Template; + +sub new($) { + my ($this) = @_; + my $class = ref($this) || $this; + + my $self = bless({ + 'config' => { + }, + 'template' => undef, + }, $class); + + ($self->{'config'}->{'INCLUDE_PATH'} = $INC{'Varnish/Test/Report.pm'}) =~ s/\.pm$//; + + $self->init(); + + return $self; +} + +sub run($@) { + my ($self, @cases) = @_; + + die "No template defined\n" + unless defined($self->{'template'}); + my $template = new Template($self->{'config'}); + $template->process($self->{'template'}, { 'cases' => \@cases }) + or die $template->error(); +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 09:18:06 UTC (rev 1521) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 09:23:25 UTC (rev 1522) @@ -132,4 +132,10 @@ } } +sub results($) { + my ($self) = @_; + + map { $_->results() } @{$self->{'cases'}}; +} + 1; Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-15 09:18:06 UTC (rev 1521) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-15 09:23:25 UTC (rev 1522) @@ -36,17 +36,20 @@ use Getopt::Long; use Varnish::Test; +use Varnish::Test::Report::HTML; sub usage() { print STDERR <stop_engine(); - foreach my $case (@{$controller->{'cases'}}) { - (my $name = ref($case)) =~ s/.*://; - - printf("%s: Successful: %d Failed: %d\n", - $name, $case->{'successful'}, $case->{'failed'}); - } + my $report = new Varnish::Test::Report::HTML; + $report->run($controller->results()); } From des at projects.linpro.no Fri Jun 15 09:26:54 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 11:26:54 +0200 (CEST) Subject: r1523 - in trunk/varnish-tools/regress/lib/Varnish/Test: . Case Message-ID: <20070615092654.750D71EC030@projects.linpro.no> Author: des Date: 2007-06-15 11:26:54 +0200 (Fri, 15 Jun 2007) New Revision: 1523 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: \n is not expanded in single-quoted strings. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -55,11 +55,11 @@ my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die 'Client time-out before receiving a (complete) response\n' + die "Client time-out before receiving a (complete) response\n" if $event eq 'ev_client_timeout'; - die 'Server was not contacted by Varnish\n' + die "Server was not contacted by Varnish\n" if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; - die sprintf('Protocol version mismatch: got: %s expected: %s\n', + die sprintf("Protocol version mismatch: got: %s expected: %s\n", $response->protocol, $sv) if $response->protocol ne $sv; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -55,11 +55,11 @@ my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die 'Client time-out before receiving a (complete) response\n' + die "Client time-out before receiving a (complete) response\n" if $event eq 'ev_client_timeout'; - die 'Empty body\n' + die "Empty body\n" if $response->content eq ''; - die 'Incorrect body\n' + die "Incorrect body\n" if $response->content ne $body; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -119,7 +119,7 @@ my ($self, $mux, $fh, $data) = @_; if ($$data ne '') { - die 'Junk or incomplete response\n' + die "Junk or incomplete response\n" unless $$data =~ "\n\r?\n"; my $response = HTTP::Response->parse($$data); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -68,11 +68,11 @@ sub run_loop($@) { my ($self, @wait_for) = @_; - die 'Engine::run_loop: Already inside select-loop. Your code is buggy.\n' - if exists($self->{'in_loop'}); + die "Engine::run_loop: Already inside select-loop. Your code is buggy.\n" + if exists($self->{'in_loop'}); - die 'Engine::run_loop: No events to wait for.\n' - if @wait_for == 0; + die "Engine::run_loop: No events to wait for.\n" + if @wait_for == 0; while (@{$self->{'pending'}} > 0) { my ($event, @args) = @{shift @{$self->{'pending'}}}; @@ -106,7 +106,7 @@ return if $event eq 'DESTROY'; - die sprintf('Unknown method "%s"\n', $event) + die sprintf("Unknown method '%s'\n", $event) unless $event =~ /^ev_(.*)$/; $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -158,7 +158,7 @@ sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; - die 'Junk or incomplete request\n' + die "Junk or incomplete request\n" unless $$data eq ''; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-15 09:23:25 UTC (rev 1522) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-15 09:26:54 UTC (rev 1523) @@ -125,9 +125,9 @@ sub send_command($@) { my ($self, @args) = @_; - die 'not ready\n' + die "not ready\n" if $self->{'state'} eq 'init'; - die sprintf('busy awaiting earlier command (%s)\n', $self->{'pending'}) + die sprintf("busy awaiting earlier command (%s)\n", $self->{'pending'}) if defined $self->{'pending'}; foreach (@args) { @@ -156,19 +156,19 @@ sub start_child($) { my ($self) = @_; - die 'not ready\n' - if $self->{'state'} eq 'init'; - die 'already started\n' - if $self->{'state'} eq 'started'; + die "not ready\n" + if $self->{'state'} eq "init"; + die "already started\n" + if $self->{'state'} eq "started"; $self->send_command("start"); } sub stop_child($) { my ($self) = @_; - die 'not ready\n' + die "not ready\n" if $self->{'state'} eq 'init'; - die 'already stopped\n' + die "already stopped\n" if $self->{'state'} eq 'stopped'; $self->send_command("stop"); @@ -184,7 +184,7 @@ my ($self, $signal) = @_; $signal ||= 15; - die 'Not running\n' + die "Not running\n" unless defined($self->{'pid'}); kill($signal, $self->{'pid'}); delete $self->{'pid'}; From cecilihf at projects.linpro.no Fri Jun 15 09:27:29 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 15 Jun 2007 11:27:29 +0200 (CEST) Subject: r1524 - trunk/varnish-cache/bin/varnishd Message-ID: <20070615092729.6099D1EC3FC@projects.linpro.no> Author: cecilihf Date: 2007-06-15 11:27:29 +0200 (Fri, 15 Jun 2007) New Revision: 1524 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Forgot to remove this line (it was moved further down) Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 09:26:54 UTC (rev 1523) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 09:27:29 UTC (rev 1524) @@ -512,7 +512,6 @@ /* Check that the new name follows hostname convention */ /* [a-zA-Z0-9.-] */ asprintf(&old_path, "/tmp/%s", master.name); - master.name = strdup(arg); /* Create/rename the temporary varnish directory */ asprintf(&path, "/tmp/%s", arg); renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode)); From des at projects.linpro.no Fri Jun 15 10:40:54 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 12:40:54 +0200 (CEST) Subject: r1525 - in trunk/varnish-cache: bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishstat bin/varnishtop include lib/libvarnishapi Message-ID: <20070615104054.2740D1EC030@projects.linpro.no> Author: des Date: 2007-06-15 12:40:53 +0200 (Fri, 15 Jun 2007) New Revision: 1525 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.1 trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishhist/varnishhist.1 trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.1 trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishstat/varnishstat.1 trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtop/varnishtop.1 trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/shmlog.c Log: Slight improvements on Cecilie's commit: correct nroff style and man page wording, constify varnish_name, move default name logic into VSL_Open*(). Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -507,7 +507,7 @@ char *old_path; int renaming; (void)par; - + if (arg != NULL) { /* Check that the new name follows hostname convention */ /* [a-zA-Z0-9.-] */ @@ -518,7 +518,7 @@ if (stat(path, &st)) { if (renaming) { if (renaming && rename(old_path, path)) { - cli_out(cli, + cli_out(cli, "Error: Directory %s could not be " "renamed to %s", old_path, path); @@ -578,12 +578,12 @@ */ static struct parspec parspec[] = { { "user", tweak_user, - "The unprivileged user to run as. Setting this will " + "The unprivileged user to run as. Setting this will " "also set \"group\" to the specified user's primary group.\n" MUST_RESTART, "nobody" }, { "group", tweak_group, - "The unprivileged group to run as.\n" + "The unprivileged group to run as.\n" MUST_RESTART, "nogroup" }, { "default_ttl", tweak_default_ttl, @@ -734,7 +734,7 @@ "naming conventions. Makes it possible to run " "multiple varnishd instances on one server.\n" EXPERIMENTAL, - "hostname"}, + "hostname" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd May 30, 2007 +.Dd June 15, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -129,9 +129,10 @@ .Sx Hash Algorithms for a list of supported algorithms. .It Fl n -Specify a name for this instance. If -.Fl n -is not specified, hostname is used. Files will be stored in /tmp// +Specify a name for this instance. +This is a shortcut for specifying the +.Va name +run-time parameter. .It Fl P Ar file Write the process's PID to the specified .Ar file . @@ -401,6 +402,14 @@ The depth of the TCP listen queue. .Pp The default is 512. +.It Va name +The name of this +.Nm +instance. +All temporary files are stored in +.Pa /tmp/ Ns Va name . +.Pp +The default is the hostname. .It Va overflow_max The maximum depth of the overflow queue as a percentage of .Va thread_pool_max . @@ -499,11 +508,6 @@ .Pp The default is .Dv off . -.It Va name -The name if this varnishd instance. All temporary files are stored in -/tmp// -.Pp -The default is the hostname .El .Sh SEE ALSO .Xr varnishlog 1 , Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -403,7 +403,6 @@ const char *b_arg = NULL; const char *f_arg = NULL; const char *h_arg = "classic"; - char *n_arg = NULL; const char *P_arg = NULL; const char *s_arg = "file"; const char *T_arg = NULL; @@ -452,7 +451,7 @@ h_arg = optarg; break; case 'n': - n_arg = optarg; + MCF_ParamSet(cli, "name", optarg); break; case 'P': P_arg = optarg; @@ -504,13 +503,7 @@ fprintf(stderr, "One of -b or -f must be specified\n"); usage(); } - - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } - MCF_ParamSet(cli, "name", n_arg); - + if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) { perror(P_arg); exit(1); Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.1 =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHHIST 1 .Os .Sh NAME @@ -102,11 +102,12 @@ .Fl i is specified, all log entries are included. .It Fl n -Specify the name of the varnishd to get logs from. If +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -is not specified, hostname is used. If varnishd was started with -.Fl n -the option must be specified. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -180,7 +180,7 @@ { int i, c, x; struct VSL_data *vd; - char *n_arg = NULL; + const char *n_arg = NULL; vd = VSL_New(); @@ -202,11 +202,6 @@ } } - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } - if (VSL_OpenLog(vd, n_arg)) exit (1); Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.1 =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd May 11, 2007 +.Dd June 15, 2007 .Dt VARNISHLOG 1 .Os .Sh NAME @@ -108,11 +108,12 @@ .Fl i is specified, all log entries are included. .It Fl n -Specify the name of the varnishd to get logs from. If +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -is not specified, hostname is used. If varnishd was started with -.Fl n -the option must be specified. +is not specified, the host name is used. .It Fl o Group log entries by request ID. This has no effect when writing to a file using the Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -285,7 +285,7 @@ int a_flag = 0, D_flag = 0, o_flag = 0; const char *P_arg = NULL; const char *w_arg = NULL; - char *n_arg = NULL; + const char *n_arg = NULL; struct pidfh *pfh = NULL; struct VSL_data *vd; @@ -334,11 +334,6 @@ if (o_flag && w_arg != NULL) usage(); - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } - if (VSL_OpenLog(vd, n_arg)) exit(1); Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd April 21, 2007 +.Dd June 15, 2007 .Dt VARNISHNCSA 1 .Os .Sh NAME @@ -103,11 +103,12 @@ .Fl i is specified, all log entries are included. .It Fl n -Specify the name of the varnishd to get logs from. If +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -is not specified, hostname is used. If varnishd was started with -.Fl n -the option must be specified. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -444,7 +444,7 @@ int i, c; struct VSL_data *vd; const char *ofn = NULL; - char *n_arg = NULL; + const char *n_arg = NULL; int append = 0; FILE *of; @@ -475,11 +475,6 @@ usage(); } } - - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } if (VSL_OpenLog(vd, n_arg)) exit(1); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHSTAT 1 .Os .Sh NAME @@ -53,11 +53,12 @@ Instead of presenting of a continuously updated display, print the statistics once and exit. .It Fl n -Specify the name of the varnishd to get logs from. If +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -is not specified, hostname is used. If varnishd was started with -.Fl n -the option must be specified. +is not specified, the host name is used. .It Fl V Display the version number and exit. .It Fl w Ar delay Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -141,7 +141,7 @@ int c; struct varnish_stats *VSL_stats; int delay = 1, once = 0; - char *n_arg = NULL; + const char *n_arg = NULL; while ((c = getopt(argc, argv, "1n:Vw:")) != -1) { switch (c) { @@ -161,15 +161,9 @@ usage(); } } - - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } - if (!(VSL_stats = VSL_OpenStats(n_arg))) { + if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); - } if (!once) { do_curses(VSL_stats, delay); Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.1 =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-15 10:40:53 UTC (rev 1525) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHTOP 1 .Os .Sh NAME @@ -118,11 +118,12 @@ .Fl i is specified, all log entries are included. .It Fl n -Specify the name of the varnishd to get logs from. If +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -is not specified, hostname is used. If varnishd was started with -.Fl n -the option must be specified. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -113,7 +113,7 @@ unsigned u, v; struct top *tp, *tp2; int f_flag = 0; - char *n_arg = NULL; + const char *n_arg = NULL; vd = VSL_New(); @@ -140,11 +140,6 @@ usage(); } } - - if (n_arg == NULL) { - n_arg = malloc(HOST_NAME_MAX+1); - gethostname(n_arg, HOST_NAME_MAX+1); - } if (VSL_OpenLog(vd, n_arg)) exit (1); Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/include/varnishapi.h 2007-06-15 10:40:53 UTC (rev 1525) @@ -50,12 +50,12 @@ struct VSL_data; struct VSL_data *VSL_New(void); void VSL_Select(struct VSL_data *vd, unsigned tag); -int VSL_OpenLog(struct VSL_data *vd, char *varnish_name); +int VSL_OpenLog(struct VSL_data *vd, const char *varnish_name); void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); -struct varnish_stats *VSL_OpenStats(char *varnish_name); +struct varnish_stats *VSL_OpenStats(const char *varnish_name); extern const char *VSL_tags[256]; /* varnish_debug.c */ Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-15 09:27:29 UTC (rev 1524) +++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-15 10:40:53 UTC (rev 1525) @@ -102,7 +102,7 @@ /*--------------------------------------------------------------------*/ static int -vsl_shmem_map(char* varnish_name) +vsl_shmem_map(const char *varnish_name) { int i; struct shmloghead slh; @@ -170,16 +170,21 @@ /*--------------------------------------------------------------------*/ int -VSL_OpenLog(struct VSL_data *vd, char *varnish_name) +VSL_OpenLog(struct VSL_data *vd, const char *varnish_name) { + char hostname[1024]; unsigned char *p; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->fi != NULL) return (0); + if (varnish_name == NULL) { + gethostname(hostname, sizeof hostname); + varnish_name = hostname; + } if (vsl_shmem_map(varnish_name)) - return (1); + return (-1); vd->head = vsl_lh; vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start; @@ -477,7 +482,7 @@ } struct varnish_stats * -VSL_OpenStats(char *varnish_name) +VSL_OpenStats(const char *varnish_name) { if (vsl_shmem_map(varnish_name)) From des at projects.linpro.no Fri Jun 15 10:52:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 12:52:57 +0200 (CEST) Subject: r1526 - trunk/varnish-cache/bin/varnishd Message-ID: <20070615105257.41C261EC303@projects.linpro.no> Author: des Date: 2007-06-15 12:52:57 +0200 (Fri, 15 Jun 2007) New Revision: 1526 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Use mode 0755 rather than 0600 for the state directory. Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 10:40:53 UTC (rev 1525) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 10:52:57 UTC (rev 1526) @@ -526,7 +526,7 @@ return; } } else { - if (mkdir(path, 0600)) { + if (mkdir(path, 0755)) { fprintf(stderr, "Error: Directory %s could not be created", path); From des at projects.linpro.no Fri Jun 15 11:23:13 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 15 Jun 2007 13:23:13 +0200 (CEST) Subject: r1527 - in trunk/varnish-tools/regress/lib/Varnish/Test: . Report Message-ID: <20070615112313.4EC371EC2EE@projects.linpro.no> Author: des Date: 2007-06-15 13:23:13 +0200 (Fri, 15 Jun 2007) New Revision: 1527 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html Log: Improve the report further. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-06-15 10:52:57 UTC (rev 1526) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-06-15 11:23:13 UTC (rev 1527) @@ -6,38 +6,57 @@ Varnish test report +

Varnish test report

- - - - - - - - + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + +
NameTimeTestsPassedFailedDescription
NameTestsPassFailTimeDescription
s
Total s 
Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-06-15 10:52:57 UTC (rev 1526) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-06-15 11:23:13 UTC (rev 1527) @@ -57,7 +57,20 @@ die "No template defined\n" unless defined($self->{'template'}); my $template = new Template($self->{'config'}); - $template->process($self->{'template'}, { 'cases' => \@cases }) + my ($count, $pass, $fail, $time); + map { + $count += $_->{'count'}; + $pass += $_->{'pass'}; + $fail += $_->{'fail'}; + $time += $_->{'time'}; + } @cases; + $template->process($self->{'template'}, { + 'cases' => \@cases, + 'count' => $count, + 'pass' => $pass, + 'fail' => $fail, + 'time' => $time, + }) or die $template->error(); } From cecilihf at projects.linpro.no Fri Jun 15 12:26:56 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 15 Jun 2007 14:26:56 +0200 (CEST) Subject: r1528 - trunk/varnish-cache/bin/varnishd Message-ID: <20070615122656.AB0CF1EC030@projects.linpro.no> Author: cecilihf Date: 2007-06-15 14:26:56 +0200 (Fri, 15 Jun 2007) New Revision: 1528 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: A change in the default value of the name, and test for correct naming convention Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 11:23:13 UTC (rev 1527) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 12:26:56 UTC (rev 1528) @@ -506,18 +506,31 @@ char *path; char *old_path; int renaming; + char hostname[1024]; + char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789.-"; (void)par; if (arg != NULL) { + if (strlen(arg) == 0) { + gethostname(hostname, sizeof hostname); + arg = hostname; + } /* Check that the new name follows hostname convention */ - /* [a-zA-Z0-9.-] */ + if (strspn(arg, valid_chars) != strlen(arg)) { + cli_out(cli, "Error: %s is an invalid name\n", arg); + cli_result(cli, CLIS_PARAM); + return; + } asprintf(&old_path, "/tmp/%s", master.name); /* Create/rename the temporary varnish directory */ asprintf(&path, "/tmp/%s", arg); - renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode)); + renaming = (master.name && !stat(old_path, &st_old) && + S_ISDIR(st_old.st_mode)); if (stat(path, &st)) { if (renaming) { - if (renaming && rename(old_path, path)) { + if (rename(old_path, path)) { cli_out(cli, "Error: Directory %s could not be " "renamed to %s", @@ -548,6 +561,7 @@ exit (2); } /* Everything is fine, store the (new) name */ + free(master.name); master.name = strdup(arg); } else @@ -734,7 +748,7 @@ "naming conventions. Makes it possible to run " "multiple varnishd instances on one server.\n" EXPERIMENTAL, - "hostname" }, + "", "hostname" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 11:23:13 UTC (rev 1527) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 12:26:56 UTC (rev 1528) @@ -411,7 +411,10 @@ struct cli cli[1]; struct pidfh *pfh = NULL; char buf[BUFSIZ]; - + char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789.-"; + setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -451,6 +454,10 @@ h_arg = optarg; break; case 'n': + if (strspn(optarg, valid_chars) != strlen(optarg)) { + fprintf(stderr, "%s is not a valid name\n", optarg); + exit(1); + } MCF_ParamSet(cli, "name", optarg); break; case 'P': From knutroy at projects.linpro.no Fri Jun 15 17:04:17 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 15 Jun 2007 19:04:17 +0200 (CEST) Subject: r1529 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test Message-ID: <20070615170417.486241EC2EE@projects.linpro.no> Author: knutroy Date: 2007-06-15 19:04:16 +0200 (Fri, 15 Jun 2007) New Revision: 1529 Removed: trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm Modified: trunk/varnish-tools/regress/TODO trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Added some documentation. Modified: trunk/varnish-tools/regress/TODO =================================================================== --- trunk/varnish-tools/regress/TODO 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/TODO 2007-06-15 17:04:16 UTC (rev 1529) @@ -1,3 +1,2 @@ -* Ticket 55. * Completely POD-ify Perl-code. * Detect and act upon unexpected death of Varnish grandchild process. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -28,12 +28,27 @@ # $Id$ # +=head1 NAME + +Varnish::Test::Case - test-case superclass + +=head1 DESCRIPTION + +Varnish::Test::Case is meant to be the superclass of specific +test-case clases. It provides functionality to run a number of tests +defined in methods whose names start with "test", as well as keeping +track of the number of successful or failed tests. + +It also provides default event handlers for "ev_client_response" and +"ev_client_timeout", which are standard for most test-cases. + +=cut + package Varnish::Test::Case; use strict; -use Varnish::Test::Logger; - +use Varnish::Test::Client; use HTTP::Request; use HTTP::Response; use Time::HiRes qw(gettimeofday tv_interval); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -28,6 +28,17 @@ # $Id$ # +=head1 NAME + +Varnish::Test::Client - HTTP-client emulator + +=head1 DESCRIPTION + +Varnish::Test::Client objects have the capability of establishing HTTP +connections, sending requests and receiving responses. + +=cut + package Varnish::Test::Client; use strict; @@ -86,7 +97,18 @@ sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; + # Iterate through the input buffer ($$data) and identify HTTP + # messages, one per iteration. Break out of the loop when there + # are no complete HTTP messages left in the buffer, and let + # whatever data remains stay in the buffer, as we will get a new + # chance to parse it next time we get more data ("mux_input") or + # if connection is closed ("mux_eof"). + while ($$data =~ /\n\r?\n/) { + # If we find a double (CR)LF in the input data, we have at + # least a complete header section of a message, so look for + # content-length and decide what to do. + my $response = HTTP::Response->parse($$data); my $content_length = $response->content_length; @@ -94,25 +116,47 @@ my $content_ref = $response->content_ref; my $data_length = length($$content_ref); if ($data_length == $content_length) { + # We found exactly content-length amount of data, so + # empty input buffer and send response to event + # handling. $$data = ''; $self->got_response($response); } elsif ($data_length < $content_length) { + # We only received the first part of an HTTP message, + # so break out of loop and wait for more. $self->log(sprintf('Partial response. Bytes in body: %d received, %d expected, %d remaining', $data_length, $content_length, $content_length - $data_length)); last; } else { + # We have more than content-length data, which means + # more than just one HTTP message. The extra data + # (beyond content-length) is now at the end of + # $$content_ref, so move it back to the input buffer + # so we can parse it on the next iteration. Note that + # this "substr" also removes this data from + # $$content_ref (the message body of $response + # itself). $$data = substr($$content_ref, $content_length, $data_length - $content_length, ''); + + # Send response to event handling. $self->got_response($response); } } else { + # There is no content-length among the headers, so break + # out of loop and wait for EOF, in which case mux_eof will + # reparse the input buffer as a HTTP message and send it + # to event handling from there. $self->log('Partial response. Content-Length unknown. Expecting CLOSE as end-of-response.'); last; } } + + # At this point, what remains in the input buffer is either + # nothing at all or a partial HTTP message. } sub mux_eof($$$$) { Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -28,13 +28,29 @@ # $Id$ # +=head1 NAME + +Varnish::Test::Engine - select-loop wrapper and event dispatcher + +=head1 DESCRIPTION + +Varnish::Test::Engine is primarily a wrapper around a +IO::Multiplex-based select-loop which monitors activity on +client-side, server-side and Varnish's I/O-channels. On startup, it +automatically creates an associated Server object and a Varnish +objects whoses sockets/filehandles are registered in the +IO::Multiplex-object. + +Additionally, event dispatching is performed by the AUTOLOAD method. + +=cut + package Varnish::Test::Engine; use strict; use Varnish::Test::Server; use Varnish::Test::Varnish; -use Varnish::Test::Client; use IO::Multiplex; sub new($$;%) { @@ -68,32 +84,53 @@ sub run_loop($@) { my ($self, @wait_for) = @_; + # Sanity-check to help the novice test-case writer. die "Engine::run_loop: Already inside select-loop. Your code is buggy.\n" if exists($self->{'in_loop'}); + # We need to wait for at least one event. die "Engine::run_loop: No events to wait for.\n" if @wait_for == 0; + # Check the queue for pending events which occurred between the + # last pausing event and the time the loop actually paused. If we + # are waiting for any of these events (which already occurred), + # return the first one we find immediately. while (@{$self->{'pending'}} > 0) { my ($event, @args) = @{shift @{$self->{'pending'}}}; return ($event, @args) if grep({ $_ eq $event } @wait_for); } + # At this point, the queue of pending events is always empty. + # Prepare and run IO::Multiplex::loop. + $self->{'wait_for'} = \@wait_for; $self->{'in_loop'} = 1; $self->{'mux'}->loop; delete $self->{'in_loop'}; delete $self->{'wait_for'}; + # Loop has now been paused due to the occurrence of an event we + # were waiting for. This event is always found in the front of the + # pending events queue at this point, so return it. return @{shift @{$self->{'pending'}}} if @{$self->{'pending'}} > 0; + + # Hm... we should usually not reach this point. The pending queue + # is empty. Either someone (erroneously) requested a loop pause by + # calling IO::Multiplex::endloop and forgot to put any event in + # the queue, or the loop ended itself because all registered + # filehandles/sockets closed. return undef; } sub shutdown($) { my ($self) = @_; + # Shutdown varnish and server. $self->{'varnish'}->shutdown if defined $self->{'varnish'}; $self->{'server'}->shutdown if defined $self->{'server'}; + + # Close any lingering sockets registered with IO::Multiplex. foreach my $fh ($self->{'mux'}->handles) { $self->{'mux'}->close($fh); } @@ -106,18 +143,32 @@ return if $event eq 'DESTROY'; + # For the sake of readability, we want all method names we handle + # to start with "ev_". die sprintf("Unknown method '%s'\n", $event) unless $event =~ /^ev_(.*)$/; $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); + # Check to see if the active case object defines an event handler + # for this event. If so, call it and bring the event arguments + # along. This will also replace @args, which is significant if + # this event will pause and return. @args = $self->{'case'}->$event(@args) if (defined($self->{'case'}) and $self->{'case'}->can($event)); if (@{$self->{'pending'}} > 0) { - push(@{$self->{'pending'}}, [ $event, @args ]); + # Pending event queue is NOT empty, meaning this is an event + # arriving after a pausing (wait_for) event, but before the + # pause is in effect. We queue this event unconditionally + # because it might be the one we are waiting for on the next + # call to run_loop. + push(@{$self->{'pending'}}, [ $event, @args ]); } elsif (grep({ $_ eq $event} @{$self->{'wait_for'}}) > 0) { + # Pending event queue is empty and this event is one of those + # we are waiting for, so put it in the front of the queue and + # signal loop pause by calling IO::Multiplex::endloop. push(@{$self->{'pending'}}, [ $event, @args ]); $self->{'mux'}->endloop; } Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Logger.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -1,55 +0,0 @@ -#!/usr/bin/perl -w -#- -# Copyright (c) 2006 Linpro AS -# 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$ -# - -package Varnish::Test::Logger; - -sub new($;$) { - my ($this, $prefix) = @_; - my $class = ref($this) || $this; - - my $self = bless({ 'prefix' => $prefix || '' }, $class); -} - -sub write($$;$) { - my ($self, $data, $extra_prefix) = @_; - - my $prefix = $self->{'prefix'}; - $prefix .= ': ' . $extra_prefix if defined($extra_prefix); - - if ($prefix) { - $data =~ s/^/$prefix: /gm; - } - - $data =~ s/\n?$/\n/; - - print STDERR $data; -} - -1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -28,6 +28,20 @@ # $Id$ # +=head1 NAME + +Varnish::Test::Server - HTTP-server emulator + +=head1 DESCRIPTION + +A Varnish::Test::Server object has the capability of listening on a +TCP socket, receiving HTTP requests and sending responses. + +Every established connection is handled by an associated object of +type Varnish::Test::Server::Connection. + +=cut + package Varnish::Test::Server; use strict; @@ -127,7 +141,17 @@ sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; + # Iterate through the input buffer ($$data) and identify HTTP + # messages, one per iteration. Break out of the loop when there + # are no complete HTTP messages left in the buffer, and let + # whatever data remains stay in the buffer, as we will get a new + # chance to parse it next time we get more data ("mux_input"). + while ($$data =~ /\n\r?\n/) { + # If we find a double (CR)LF in the input data, we have at + # least a complete header section of a message, so look for + # content-length and decide what to do. + my $request = HTTP::Request->parse($$data); my $content_ref = $request->content_ref; my $content_length = $request->content_length; @@ -135,19 +159,38 @@ if (defined($content_length)) { my $data_length = length($$content_ref); if ($data_length == $content_length) { + # We found exactly content-length amount of data, so + # empty input buffer and send request to event + # handling. $$data = ''; $self->{'server'}->got_request($self, $request); } elsif ($data_length < $content_length) { + # We only received the first part of an HTTP message, + # so break out of loop and wait for more. last; } else { + # We have more than content-length data, which means + # more than just one HTTP message. The extra data + # (beyond content-length) is now at the end of + # $$content_ref, so move it back to the input buffer + # so we can parse it on the next iteration. Note that + # this "substr" also removes this data from + # $$content_ref (the message body of $request itself). $$data = substr($$content_ref, $content_length, $data_length - $content_length, ''); + # Send request to event handling. $self->{'server'}->got_request($self, $request); } } else { + # HTTP requests without a content-length has no body by + # definition, so whatever was parsed as content must be + # the start of another request. Hence, move this back to + # input buffer and empty the body of this $request. Then, + # send $request to event handling. + $$data = $$content_ref; $$content_ref = ''; $self->{'server'}->got_request($self, $request); @@ -158,6 +201,10 @@ sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; + # On server side, HTTP does not use EOF from client to signal end + # of request, so if there is anything left in input buffer, it + # must be incomplete because "mux_input" left it there. + die "Junk or incomplete request\n" unless $$data eq ''; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -28,14 +28,27 @@ # $Id$ # +=head1 NAME + +Varnish::Test::Varnish - Varnish child-process controller + +=head1 DESCRIPTION + +A Varnish::Test::Varnish object is used to fork off a Varnish child +process and control traffic going into and coming out of the Varnish +(management process) command-line interface (CLI). + +Various events are generated when certain strings are identified in +the output from the CLI. + +=cut + package Varnish::Test::Varnish; use strict; use Socket; -use Varnish::Test::Logger; - sub new($$;$) { my ($this, $engine, $attrs) = @_; my $class = ref($this) || $this; @@ -44,6 +57,9 @@ 'mux' => $engine->{'mux'}, 'state' => 'init' }, $class); + # Create pipes (actually socket pairs) for communication between + # parent and child. + socketpair(STDIN_READ, STDIN_WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC); shutdown(STDIN_READ, 1); shutdown(STDIN_WRITE, 0); @@ -54,7 +70,8 @@ shutdown(STDERR_READ, 1); shutdown(STDERR_WRITE, 0); - delete $SIG{CHLD}; + # Ignore SIGCHLD. + $SIG{CHLD} = 'IGNORE'; my $pid = fork; die "fork(): $!\n" @@ -67,6 +84,9 @@ close STDOUT_READ; close STDERR_READ; + # dup2(2) the I/O-channels to std{in,out,err} and close the + # original file handles before transforming into Varnish. + open STDIN, '<&', \*STDIN_READ; close STDIN_READ; open STDOUT, '>&', \*STDOUT_WRITE; @@ -80,14 +100,17 @@ print STDERR sprintf("Starting Varnish with options: %s\n", join(' ', @opts)); + # Unset ignoring of SIGCHLD, so Varnish will get signals from + # its children. + + delete $SIG{CHLD}; + + # Transform into Varnish. Goodbye Perl-code! exec('varnishd', @opts); exit(1); } else { # Parent - - $SIG{CHLD} = 'IGNORE'; - $self->log('PID: ' . $pid); close STDIN_READ; @@ -99,6 +122,9 @@ $self->{'stdout'} = \*STDOUT_READ; $self->{'stderr'} = \*STDERR_READ; + # Register the Varnish I/O-channels with the IO::Multiplex + # loop object. + $self->{'mux'}->add($self->{'stdin'}); $self->{'mux'}->set_callback_object($self, $self->{'stdin'}); $self->{'mux'}->add($self->{'stdout'}); Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 12:26:56 UTC (rev 1528) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 17:04:16 UTC (rev 1529) @@ -38,31 +38,66 @@ process and then communicating with this process as both client and server. + +---------------------------------------------------------+ + | TEST FRAMEWORK | + | | + | Controller | + | +-----------------------------------+ | + | | | C ^ | | + | | configuration | L | status | | + | | v I | | | + | | requests +---------+ requests | | + | | =========> | | =========> | | + | Client | HTTP | VARNISH | HTTP | Server | + | emulator | <========= | | <========= | emulator | + | | responses +---------+ responses | | + +----------+ +----------+ + =head1 STRUCTURE -When regressions tests start, an instance of Varnish is forked off as -a child process, and its I/O channels (std{in,out,err}) are controlled -by the parent process which also performs the test by playing the role +When regression tests start, an instance of Varnish is forked off as a +child process, and its I/O channels (std{in,out,err} which are +connected to the command-line interface of Varnish) are controlled by +the parent process which also performs the tests by playing the role of both HTTP client and server. A single select(2)-driven loop is used to handle all activity on both server and client side, as well on Varnish's I/O-channels. This is done using IO::Multiplex. -As a result of using a select-loop, the framework has an event-driven -design in order to cope with unpredictable sequence of processing on -either server og client side. To drive a test-case forward, the -select-loop is paused when certain events occur, and control returns -to the "main program" which can then inspect the situation. This -results in certain structural constraints. It is essential to be aware -of whether a piece of code is going to run inside or outside the -select-loop. +As a result of using a select-loop (as opposed to a multi-threaded or +multi-process approach), the framework has an event-driven design in +order to cope with the unpredictable sequence of I/O on server or +client side (or Varnish's I/O-channels for that matter) . To drive a +test-case forward, the select-loop is paused when certain events +occur, and control returns to the "main program" which can then +inspect the situation. This results in certain structural constraints, +and it is essential to be aware of whether a piece of code is going to +run inside (event handler) or outside (main program) the select-loop. -The framework uses Perl objects to represent instances of servers and -clients as well as the Varnish instance itself. In addition, there is -an "engine" object which propagates events and controls the program -flow related to the select-loop. +The framework uses Perl objects to represent instances of servers +(Varnish::Test::Server) and clients (Varnish::Test::Client) as well as +the Varnish instance itself (Varnish::Test::Varnish). In addition, +there is an engine object (Varnish::Test::Engine) which dispatches +events and controls the program flow related to the select-loop. +Futhermore, each test case is represented by an object +(Varnish::Test::Case subclass). HTTP requests and responses are +represented by objects of HTTP::Request and HTTP::Response, +respectively. Finally, there is an overall test-case controller object +(Varnish::Test) which accumulates test-case results. +=head1 EVENT PROCESSING + +Events typically occur in the call-back routines (mux_*) of client, +server, and Varnish objects. An event is created by calling an ev_* +method of the engine object. These calls are handled by Perl's +AUTOLOAD mechanism since Engine does not define any ev_* methods +explicitly. The AUTOLOAD routine works as the event dispatcher by +looking for an event handler in the currently running test-case +object, and also determines whether the event being processed is +supposed to pause the select-loop and return control back to the main +program. + =cut package Varnish::Test; From knutroy at projects.linpro.no Fri Jun 15 17:06:15 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 15 Jun 2007 19:06:15 +0200 (CEST) Subject: r1530 - in trunk/varnish-tools/regress: . doc Message-ID: <20070615170615.AA7F31EC030@projects.linpro.no> Author: knutroy Date: 2007-06-15 19:06:15 +0200 (Fri, 15 Jun 2007) New Revision: 1530 Added: trunk/varnish-tools/regress/doc/ trunk/varnish-tools/regress/doc/README trunk/varnish-tools/regress/doc/structure.dia Removed: trunk/varnish-tools/regress/README Log: Added a glossy Dia-diagram showing the overall structure of the test framework. Deleted: trunk/varnish-tools/regress/README =================================================================== --- trunk/varnish-tools/regress/README 2007-06-15 17:04:16 UTC (rev 1529) +++ trunk/varnish-tools/regress/README 2007-06-15 17:06:15 UTC (rev 1530) @@ -1,4 +0,0 @@ -VARNISH REGRESSION TEST FRAMEWORK - -This is a regression test framework written in Perl. It is being -tailored to the needs of the Varnish HTTP accelerator. Copied: trunk/varnish-tools/regress/doc/README (from rev 1528, trunk/varnish-tools/regress/README) =================================================================== --- trunk/varnish-tools/regress/doc/README (rev 0) +++ trunk/varnish-tools/regress/doc/README 2007-06-15 17:06:15 UTC (rev 1530) @@ -0,0 +1,4 @@ +VARNISH REGRESSION TEST FRAMEWORK + +This is a regression test framework written in Perl. It is being +tailored to the needs of the Varnish HTTP accelerator. Added: trunk/varnish-tools/regress/doc/structure.dia =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/regress/doc/structure.dia ___________________________________________________________________ Name: svn:mime-type + application/octet-stream From des at projects.linpro.no Sun Jun 17 15:10:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 17 Jun 2007 17:10:09 +0200 (CEST) Subject: r1531 - trunk/varnish-cache/bin/varnishncsa Message-ID: <20070617151009.53A441EC3EC@projects.linpro.no> Author: des Date: 2007-06-17 17:10:08 +0200 (Sun, 17 Jun 2007) New Revision: 1531 Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c Log: Don't allow len to go negative if the header is empty. Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-15 17:06:15 UTC (rev 1530) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2007-06-17 15:10:08 UTC (rev 1531) @@ -155,7 +155,7 @@ /* nothing */ ; /* trim trailing space */ - while (str[len - 1] == ' ') + while (len && str[len - 1] == ' ') --len; /* copy and return */ From des at projects.linpro.no Mon Jun 18 07:31:53 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 18 Jun 2007 09:31:53 +0200 (CEST) Subject: r1532 - trunk/varnish-cache/bin/varnishd Message-ID: <20070618073153.566861EC2F2@projects.linpro.no> Author: des Date: 2007-06-18 09:31:50 +0200 (Mon, 18 Jun 2007) New Revision: 1532 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Further tweak_name() improvements: restructure to reduce indentation; simplify error handling; use a regexp to check the name syntax; check CLI errors after the getopt() loop. Discussed with: ceciliehf Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-17 15:10:08 UTC (rev 1531) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-18 07:31:50 UTC (rev 1532) @@ -33,8 +33,9 @@ #include #include -#include #include +#include +#include #include #include #include @@ -498,74 +499,68 @@ /*--------------------------------------------------------------------*/ +#define NAME_RE "^([0-9A-Za-z-]+)(\\.[0-9A-Za-z-]+)*$" +static regex_t *name_re; + static void -tweak_name(struct cli *cli, struct parspec *par, const char* arg) +tweak_name(struct cli *cli, struct parspec *par, const char *arg) { - struct stat st; - struct stat st_old; - char *path; - char *old_path; - int renaming; - char hostname[1024]; - char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789.-"; + char hostname[1024], path[1024]; + int error; + (void)par; - if (arg != NULL) { - if (strlen(arg) == 0) { - gethostname(hostname, sizeof hostname); + if (arg == NULL) { + cli_out(cli, "\"%s\"", master.name); + return; + } + + /* empty string -> hostname */ + if (*arg == '\0') { + if (gethostname(hostname, sizeof hostname) == 0) arg = hostname; + else + arg = "localhost"; + } + + /* check that the new name follows hostname convention */ + if (name_re == NULL) { + name_re = malloc(sizeof *name_re); + AN(name_re); + AZ(regcomp(name_re, NAME_RE, REG_EXTENDED|REG_NOSUB)); + } + if (regexec(name_re, arg, 0, NULL, 0) != 0) { + cli_out(cli, "Invalid instance name"); + cli_result(cli, CLIS_PARAM); + return; + } + + error = 0; + snprintf(path, sizeof path, "/tmp/%s", arg); /* XXX overflow */ + if (master.name && *master.name) { + struct stat old_st; + char old_path[1024]; + + /* rename old directory */ + snprintf(old_path, sizeof old_path, "/tmp/%s", master.name); /* XXX overflow */ + if (stat(old_path, &old_st) == 0 && S_ISDIR(old_st.st_mode)) { + error = rename(old_path, path); + } else { + error = (mkdir(path, 0755) != 0 && errno != EEXIST); } - /* Check that the new name follows hostname convention */ - if (strspn(arg, valid_chars) != strlen(arg)) { - cli_out(cli, "Error: %s is an invalid name\n", arg); - cli_result(cli, CLIS_PARAM); - return; - } - asprintf(&old_path, "/tmp/%s", master.name); - /* Create/rename the temporary varnish directory */ - asprintf(&path, "/tmp/%s", arg); - renaming = (master.name && !stat(old_path, &st_old) && - S_ISDIR(st_old.st_mode)); - if (stat(path, &st)) { - if (renaming) { - if (rename(old_path, path)) { - cli_out(cli, - "Error: Directory %s could not be " - "renamed to %s", - old_path, path); - cli_result(cli, CLIS_PARAM); - return; - } - } else { - if (mkdir(path, 0755)) { - fprintf(stderr, - "Error: Directory %s could not be created", - path); - exit (2); - } - } - } else if (renaming) { - cli_out(cli, "Error: Directory %s could not be " - "renamed to %s", old_path, path); - cli_result(cli, CLIS_PARAM); - return; - } - stat(path, &st); - /* /tmp/varnishname should now be a directory */ - if (!S_ISDIR(st.st_mode)) { - fprintf(stderr, - "Error: \"%s\" " - "is not a directory\n", path); - exit (2); - } - /* Everything is fine, store the (new) name */ - free(master.name); - master.name = strdup(arg); + } else { + error = (mkdir(path, 0755) != 0 && errno != EEXIST); } - else - cli_out(cli, "\"%s\"", master.name); + + if (error || chdir(path) != 0) { + cli_out(cli, "could not create %s: %s", path, strerror(errno)); + cli_result(cli, CLIS_CANT); + return; + } + + /* Everything is fine, store the (new) name */ + master.name = strdup(arg); + XXXAN(master.name); } /*--------------------------------------------------------------------*/ @@ -748,7 +743,7 @@ "naming conventions. Makes it possible to run " "multiple varnishd instances on one server.\n" EXPERIMENTAL, - "", "hostname" }, + "" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-17 15:10:08 UTC (rev 1531) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-18 07:31:50 UTC (rev 1532) @@ -411,10 +411,7 @@ struct cli cli[1]; struct pidfh *pfh = NULL; char buf[BUFSIZ]; - char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789.-"; - + setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -454,10 +451,6 @@ h_arg = optarg; break; case 'n': - if (strspn(optarg, valid_chars) != strlen(optarg)) { - fprintf(stderr, "%s is not a valid name\n", optarg); - exit(1); - } MCF_ParamSet(cli, "name", optarg); break; case 'P': @@ -502,6 +495,13 @@ usage(); } + if (cli[0].result != CLIS_OK) { + fprintf(stderr, "Parameter errors:\n"); + vsb_finish(cli[0].sb); + fprintf(stderr, "%s\n", vsb_data(cli[0].sb)); + exit(1); + } + if (b_arg != NULL && f_arg != NULL) { fprintf(stderr, "Only one of -b or -f can be specified\n"); usage(); From des at projects.linpro.no Mon Jun 18 07:52:20 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 18 Jun 2007 09:52:20 +0200 (CEST) Subject: r1533 - trunk/varnish-cache/bin/varnishd Message-ID: <20070618075220.677791EC2AF@projects.linpro.no> Author: des Date: 2007-06-18 09:52:19 +0200 (Mon, 18 Jun 2007) New Revision: 1533 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Since the previous commit added a chdir() to our temp directory, we can stop juggling file names and simply do everything relative to our cwd. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-18 07:31:50 UTC (rev 1532) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-18 07:52:19 UTC (rev 1533) @@ -140,13 +140,13 @@ mgt_CallCc(const char *source, struct vsb *sb) { FILE *fo, *fs; - char *of, *sf, buf[BUFSIZ]; - int i, j, sfd; + char sf[] = "./vcl.XXXXXXXX"; + char *of; + char buf[BUFSIZ]; + int i, j, len, sfd; void *p; /* Create temporary C source file */ - asprintf(&sf, "/tmp/%s/vcl.XXXXXXXX", params->name); - assert(sf != NULL); sfd = mkstemp(sf); if (sfd < 0) { vsb_printf(sb, @@ -156,7 +156,7 @@ return (NULL); } fs = fdopen(sfd, "r+"); - assert(fs != NULL); + AN(fs); if (fputs(source, fs) < 0 || fflush(fs)) { vsb_printf(sb, @@ -169,16 +169,16 @@ rewind(fs); /* Name the output shared library */ - asprintf(&of, "/tmp/%s/vcl.XXXXXXXX", params->name); - assert(of != NULL); - of = mktemp(of); - assert(of != NULL); + of = strdup(sf); + AN(of); + memcpy(of, "./bin", 5); /* Attempt to open a pipe to the system C-compiler */ - sprintf(buf, - "ln -f %s /tmp/%s/_.c ;" /* XXX: for debugging */ + len = snprintf(buf, sizeof buf, + "ln -f %s _.c ;" /* XXX: for debugging */ "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", - sf, params->name, of, sf); + sf, of, sf); + xxxassert(len < sizeof buf); fo = popen(buf, "r"); if (fo == NULL) { @@ -201,7 +201,7 @@ j++; } vsb_cat(sb, buf); - } + } i = pclose(fo); if (j == 0 && i != 0) @@ -228,7 +228,6 @@ /* clean up and return */ unlink(sf); - free(sf); fclose(fs); return (of); } Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-18 07:31:50 UTC (rev 1532) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-18 07:52:19 UTC (rev 1533) @@ -33,7 +33,7 @@ struct sess; struct iovec; -typedef void storage_init_f(struct stevedore *, const char *spec, const char *name); +typedef void storage_init_f(struct stevedore *, const char *spec); typedef void storage_open_f(struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef void storage_trim_f(struct storage *, size_t size); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-18 07:31:50 UTC (rev 1532) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-18 07:52:19 UTC (rev 1533) @@ -242,7 +242,7 @@ } static void -smf_init(struct stevedore *parent, const char *spec, const char *varnish_name) +smf_init(struct stevedore *parent, const char *spec) { char *size; char *p, *q; @@ -262,7 +262,7 @@ /* If no size specified, use 50% of filesystem free space */ if (spec == NULL || *spec == '\0') - asprintf(&p, "/tmp/%s,50%%", varnish_name); + asprintf(&p, ".,50%%"); else if (strchr(spec, ',') == NULL) asprintf(&p, "%s,", spec); else Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-18 07:31:50 UTC (rev 1532) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-18 07:52:19 UTC (rev 1533) @@ -150,7 +150,7 @@ heritage.stevedore = malloc(sizeof *heritage.stevedore); *heritage.stevedore = *stp; if (stp->init != NULL) - stp->init(heritage.stevedore, q, params->name); + stp->init(heritage.stevedore, q); } /*--------------------------------------------------------------------*/ @@ -410,7 +410,6 @@ char *p; struct cli cli[1]; struct pidfh *pfh = NULL; - char buf[BUFSIZ]; setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -524,8 +523,7 @@ setup_storage(s_arg); setup_hash(h_arg); - sprintf(buf, "/tmp/%s/%s", params->name, SHMLOG_FILENAME); - VSL_MgtInit(buf, 8*1024*1024); + VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); if (d_flag == 1) DebugStunt(); From phk at projects.linpro.no Sun Jun 24 09:23:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:23:41 +0200 (CEST) Subject: r1534 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624092341.7DB8D1EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 11:23:38 +0200 (Sun, 24 Jun 2007) New Revision: 1534 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c Log: Remove http_IsBodyless, it is no longer used. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-18 07:52:19 UTC (rev 1533) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-24 09:23:38 UTC (rev 1534) @@ -405,7 +405,6 @@ int http_GetHdr(struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr); int http_GetStatus(struct http *hp); -int http_IsBodyless(struct http *hp); int http_HdrIs(struct http *hp, const char *hdr, const char *val); int http_GetTail(struct http *hp, unsigned len, char **b, char **e); int http_Read(struct http *hp, int fd, void *b, unsigned len); Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-18 07:52:19 UTC (rev 1533) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-24 09:23:38 UTC (rev 1534) @@ -383,21 +383,6 @@ NULL /* XXX */, 10)); } -/*--------------------------------------------------------------------- - * All 1xx (informational), 204 (no content), and 304 (not modified) - * responses MUST NOT include a message-body. - */ - -int -http_IsBodyless(struct http *hp) -{ - int status; - - status = http_GetStatus(hp); - return (status >= 100 && status < 200) - || status == 204 || status == 304; -} - /*-------------------------------------------------------------------- * Dissect the headers of the HTTP protocol message. * Detect conditionals (headers which start with '^[Ii][Ff]-') From phk at projects.linpro.no Sun Jun 24 09:27:19 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:27:19 +0200 (CEST) Subject: r1535 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624092719.20F011EC030@projects.linpro.no> Author: phk Date: 2007-06-24 11:27:18 +0200 (Sun, 24 Jun 2007) New Revision: 1535 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Make HSH_Freestore() static Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-24 09:23:38 UTC (rev 1534) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-24 09:27:18 UTC (rev 1535) @@ -378,7 +378,6 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); -void HSH_Freestore(struct object *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(struct object *o); void HSH_Ref(struct object *o); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-24 09:23:38 UTC (rev 1534) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-24 09:27:18 UTC (rev 1535) @@ -96,7 +96,7 @@ CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } -void +static void HSH_Freestore(struct object *o) { struct storage *st, *stn; From phk at projects.linpro.no Sun Jun 24 09:29:21 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:29:21 +0200 (CEST) Subject: r1536 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624092921.DC7CD1EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 11:29:21 +0200 (Sun, 24 Jun 2007) New Revision: 1536 Modified: trunk/varnish-cache/bin/varnishd/common.h Log: remove unnecessary struct tcp_addr forward decl. Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2007-06-24 09:27:18 UTC (rev 1535) +++ trunk/varnish-cache/bin/varnishd/common.h 2007-06-24 09:29:21 UTC (rev 1536) @@ -41,8 +41,6 @@ #define TCP_ADDRBUFSIZE 64 #define TCP_PORTBUFSIZE 16 -struct tcp_addr; - void TCP_name(struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen); void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen); int TCP_filter_http(int sock); From phk at projects.linpro.no Sun Jun 24 09:40:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:40:09 +0200 (CEST) Subject: r1537 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624094009.30CD91EC030@projects.linpro.no> Author: phk Date: 2007-06-24 11:40:09 +0200 (Sun, 24 Jun 2007) New Revision: 1537 Modified: trunk/varnish-cache/bin/varnishd/cache_session.c Log: Make sure we cache a consistent view of the workspace size. Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-24 09:29:21 UTC (rev 1536) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-24 09:40:09 UTC (rev 1537) @@ -255,9 +255,8 @@ SES_New(struct sockaddr *addr, unsigned len) { struct sessmem *sm; - unsigned u; + volatile unsigned u; - /* * One of the two queues is unlocked because only one * thread ever gets here to empty it. @@ -279,6 +278,10 @@ } else { /* * If that fails, alloc new one. + * + * It is not necessary to lock mem_workspace, but we + * need to cache it locally, to make sure we get a + * consistent view of it. */ u = params->mem_workspace; sm = malloc(sizeof *sm + u); From phk at projects.linpro.no Sun Jun 24 09:40:22 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:40:22 +0200 (CEST) Subject: r1538 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624094022.79FF01EC461@projects.linpro.no> Author: phk Date: 2007-06-24 11:40:22 +0200 (Sun, 24 Jun 2007) New Revision: 1538 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c Log: Use sockaddr_storage also here. Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-24 09:40:09 UTC (rev 1537) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-24 09:40:22 UTC (rev 1538) @@ -137,7 +137,8 @@ { struct sess *sp; socklen_t l; - struct sockaddr addr[2]; /* XXX: IPv6 hack */ + struct sockaddr_storage addr_s; + struct sockaddr *addr; int i, j; struct pollfd *pfd; struct listen_sock *ls; @@ -178,7 +179,8 @@ if (pfd[j].revents == 0) continue; VSL_stats->client_conn++; - l = sizeof addr; + l = sizeof addr_s; + addr = (void*)&addr_s; i = accept(pfd[j].fd, addr, &l); if (i < 0) { if (errno != EAGAIN) { From phk at projects.linpro.no Sun Jun 24 09:41:55 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:41:55 +0200 (CEST) Subject: r1539 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624094155.3B6311EC030@projects.linpro.no> Author: phk Date: 2007-06-24 11:41:55 +0200 (Sun, 24 Jun 2007) New Revision: 1539 Modified: trunk/varnish-cache/bin/varnishd/tcp.c Log: Remove unused #includes Modified: trunk/varnish-cache/bin/varnishd/tcp.c =================================================================== --- trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-24 09:40:22 UTC (rev 1538) +++ trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-24 09:41:55 UTC (rev 1539) @@ -44,14 +44,9 @@ #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif -#ifndef HAVE_STRNDUP -#include "compat/strndup.h" -#endif #include "heritage.h" #include "mgt.h" -#include "cli.h" -#include "cli_priv.h" /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Sun Jun 24 09:55:53 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 11:55:53 +0200 (CEST) Subject: r1540 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624095553.8F4EA1EC461@projects.linpro.no> Author: phk Date: 2007-06-24 11:55:53 +0200 (Sun, 24 Jun 2007) New Revision: 1540 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Dont free(3) stack variables. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-24 09:41:55 UTC (rev 1539) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-24 09:55:53 UTC (rev 1540) @@ -152,7 +152,6 @@ vsb_printf(sb, "Cannot open temporary source file \"%s\": %s\n", sf, strerror(errno)); - free(sf); return (NULL); } fs = fdopen(sfd, "r+"); From phk at projects.linpro.no Sun Jun 24 10:02:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:02:41 +0200 (CEST) Subject: r1541 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624100241.47FB91EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 12:02:41 +0200 (Sun, 24 Jun 2007) New Revision: 1541 Modified: trunk/varnish-cache/bin/varnishd/flint.lnt Log: Mark WS_Init() as custodial Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2007-06-24 09:55:53 UTC (rev 1540) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2007-06-24 10:02:41 UTC (rev 1541) @@ -10,6 +10,7 @@ -sem(lbv_assert, r_no) -sem(lbv_xxxassert, r_no) +-sem(WS_Init, custodial(2)) -ffc // No automatic custody From phk at projects.linpro.no Sun Jun 24 10:03:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:03:09 +0200 (CEST) Subject: r1542 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070624100309.D32061EC030@projects.linpro.no> Author: phk Date: 2007-06-24 12:03:09 +0200 (Sun, 24 Jun 2007) New Revision: 1542 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/syntax.txt trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl Log: Use C-unsigned for VCL-BOOL variables Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:02:41 UTC (rev 1541) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:03:09 UTC (rev 1542) @@ -217,8 +217,8 @@ return (sp->obj->field); \ } -VOBJ(double, valid, valid) -VOBJ(double, cacheable, cacheable) +VOBJ(unsigned, valid, valid) +VOBJ(unsigned, cacheable, cacheable) /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-06-24 10:02:41 UTC (rev 1541) +++ trunk/varnish-cache/include/vrt_obj.h 2007-06-24 10:03:09 UTC (rev 1542) @@ -28,10 +28,10 @@ void VRT_l_req_backend(struct sess *, struct backend *); const char * VRT_r_req_hash(struct sess *); void VRT_l_req_hash(struct sess *, const char *); -double VRT_r_obj_valid(struct sess *); -void VRT_l_obj_valid(struct sess *, double); -double VRT_r_obj_cacheable(struct sess *); -void VRT_l_obj_cacheable(struct sess *, double); +unsigned VRT_r_obj_valid(struct sess *); +void VRT_l_obj_valid(struct sess *, unsigned); +unsigned VRT_r_obj_cacheable(struct sess *); +void VRT_l_obj_cacheable(struct sess *, unsigned); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_req_http_(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/syntax.txt =================================================================== --- trunk/varnish-cache/lib/libvcl/syntax.txt 2007-06-24 10:02:41 UTC (rev 1541) +++ trunk/varnish-cache/lib/libvcl/syntax.txt 2007-06-24 10:03:09 UTC (rev 1542) @@ -154,6 +154,8 @@ var_float '-=' double var_float '=' double var_backend '=' ident + var_string '=' stringval + var_string '+=' stringval assign_int: '+=' cnum @@ -184,6 +186,10 @@ cstr '/' cnum '!' cstr +stringval: + cstr + var_string + cstr: (string constant) cnum: (numeric constant) Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-24 10:02:41 UTC (rev 1541) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-24 10:03:09 UTC (rev 1542) @@ -57,7 +57,7 @@ set tt(IP) "struct sockaddr *" set tt(STRING) "const char *" -set tt(BOOL) "double" +set tt(BOOL) "unsigned" set tt(BACKEND) "struct backend *" set tt(TIME) "double" set tt(HEADER) "const char *" From phk at projects.linpro.no Sun Jun 24 10:16:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:16:41 +0200 (CEST) Subject: r1543 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624101641.A5DB61EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 12:16:41 +0200 (Sun, 24 Jun 2007) New Revision: 1543 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Whitespace nit Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:03:09 UTC (rev 1542) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:16:41 UTC (rev 1543) @@ -256,6 +256,7 @@ struct sockaddr * VRT_r_client_ip(struct sess *sp) { + return ((struct sockaddr *)sp->sockaddr); } From phk at projects.linpro.no Sun Jun 24 10:17:04 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:17:04 +0200 (CEST) Subject: r1544 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624101704.1FFCD1EC3FC@projects.linpro.no> Author: phk Date: 2007-06-24 12:17:03 +0200 (Sun, 24 Jun 2007) New Revision: 1544 Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c Log: Explicitly cat to int: we mean it. Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-06-24 10:16:41 UTC (rev 1543) +++ trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-06-24 10:17:03 UTC (rev 1544) @@ -433,7 +433,7 @@ t = ev_now(); if (e->__when <= t) return (ev_sched_timeout(evb, e, t)); - tmo = (e->__when - t) * 1e3; + tmo = (int)((e->__when - t) * 1e3); if (tmo == 0) tmo = 1; } else From phk at projects.linpro.no Sun Jun 24 10:17:29 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:17:29 +0200 (CEST) Subject: r1545 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624101729.4ABB91EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 12:17:29 +0200 (Sun, 24 Jun 2007) New Revision: 1545 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Roll a couple of layers off these asserts Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-24 10:17:03 UTC (rev 1544) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-24 10:17:29 UTC (rev 1545) @@ -181,8 +181,8 @@ errx(1, "Could not fork child"); if (i == 0) { if (geteuid() == 0) { - XXXAZ(setgid(params->gid) == -1); - XXXAZ(setuid(params->uid) == -1); + XXXAZ(setgid(params->gid)); + XXXAZ(setuid(params->uid)); } /* Redirect stdin/out/err */ From phk at projects.linpro.no Sun Jun 24 10:42:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:42:08 +0200 (CEST) Subject: r1546 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624104208.88A5F1EC3FC@projects.linpro.no> Author: phk Date: 2007-06-24 12:42:08 +0200 (Sun, 24 Jun 2007) New Revision: 1546 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: strchr(const char *) returns a const char *. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-24 10:17:29 UTC (rev 1545) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-24 10:42:08 UTC (rev 1546) @@ -865,7 +865,8 @@ static void http_PutField(struct http *to, int field, const char *string) { - char *e, *p; + const char *e; + char *p; int l; CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); From phk at projects.linpro.no Sun Jun 24 10:43:16 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 24 Jun 2007 12:43:16 +0200 (CEST) Subject: r1547 - trunk/varnish-cache/bin/varnishd Message-ID: <20070624104316.0EA9B1EC2F2@projects.linpro.no> Author: phk Date: 2007-06-24 12:43:15 +0200 (Sun, 24 Jun 2007) New Revision: 1547 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/tcp.c Log: Further sockaddr/sockaddr_storage sanitation in order to quiet FlexeLint Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-24 10:43:15 UTC (rev 1547) @@ -276,10 +276,10 @@ struct worker *wrk; - unsigned sockaddrlen; - struct sockaddr_storage sockaddr[1]; - unsigned mysockaddrlen; - struct sockaddr_storage mysockaddr[1]; + socklen_t sockaddrlen; + socklen_t mysockaddrlen; + struct sockaddr *sockaddr; + struct sockaddr *mysockaddr; /* formatted ascii client address */ char addr[TCP_ADDRBUFSIZE]; Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -113,7 +113,7 @@ VCA_Prep(struct sess *sp) { - TCP_name((struct sockaddr *)sp->sockaddr, sp->sockaddrlen, + TCP_name(sp->sockaddr, sp->sockaddrlen, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port); sp->acct.first = sp->t_open.tv_sec; Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -67,6 +67,7 @@ struct http http; unsigned workspace; TAILQ_ENTRY(sessmem) list; + struct sockaddr_storage sockaddr[2]; }; static TAILQ_HEAD(,sessmem) ses_free_mem[2] = { @@ -255,6 +256,7 @@ SES_New(struct sockaddr *addr, unsigned len) { struct sessmem *sm; + struct sess *sp; volatile unsigned u; /* @@ -295,20 +297,26 @@ return (NULL); CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC); VSL_stats->n_sess++; - memset(&sm->sess, 0, sizeof sm->sess); - sm->sess.magic = SESS_MAGIC; - sm->sess.mem = sm; - sm->sess.http = &sm->http; + sp = &sm->sess; + memset(sp, 0, sizeof *sp); + sp->magic = SESS_MAGIC; + sp->mem = sm; + sp->http = &sm->http; + sp->sockaddr = (void*)(&sm->sockaddr[0]); + sp->sockaddrlen = sizeof(sm->sockaddr[0]); + sp->mysockaddr = (void*)(&sm->sockaddr[1]); + sp->mysockaddrlen = sizeof(sm->sockaddr[1]); + sp->sockaddr->sa_family = sp->mysockaddr->sa_family = PF_UNSPEC; - assert(len < sizeof(sm->sess.sockaddr)); + assert(len <= sp->sockaddrlen); if (addr != NULL) { - memcpy(sm->sess.sockaddr, addr, len); - sm->sess.sockaddrlen = len; + memcpy(sp->sockaddr, addr, len); + sp->sockaddrlen = len; } http_Setup(&sm->http, (void *)(sm + 1), sm->workspace); - return (&sm->sess); + return (sp); } void Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -257,22 +257,17 @@ VRT_r_client_ip(struct sess *sp) { - return ((struct sockaddr *)sp->sockaddr); + return (sp->sockaddr); } struct sockaddr * VRT_r_server_ip(struct sess *sp) { - socklen_t l; - if (sp->mysockaddrlen == 0) { - l = sizeof sp->mysockaddr; - AZ(getsockname(sp->fd, - (struct sockaddr*)sp->mysockaddr, &l)); - sp->mysockaddrlen = l; - } + if (sp->mysockaddr->sa_family == AF_UNSPEC) + AZ(getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen)); - return ((struct sockaddr*)sp->mysockaddr); + return (sp->mysockaddr); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -104,7 +104,7 @@ for (a1 = ap->priv; a1 != NULL; a1 = a1->ai_next) { /* only match the right family */ - if (a1->ai_family != sp->sockaddr->ss_family) + if (a1->ai_family != sp->sockaddr->sa_family) continue; if (a1->ai_family == AF_INET) { Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -380,7 +380,7 @@ (void)what; addrlen = sizeof addr; - i = accept(ev->fd, (struct sockaddr *)&addr, &addrlen); + i = accept(ev->fd, (void *)&addr, &addrlen); if (i < 0) return (0); Modified: trunk/varnish-cache/bin/varnishd/tcp.c =================================================================== --- trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-24 10:42:08 UTC (rev 1546) +++ trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-24 10:43:15 UTC (rev 1547) @@ -76,7 +76,8 @@ void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen) { - struct sockaddr addr[2]; /* XXX: IPv6 hack */ + struct sockaddr_storage addr_s; + struct sockaddr *addr = (void*)&addr_s; socklen_t l; l = sizeof addr; From phk at projects.linpro.no Mon Jun 25 06:14:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 08:14:41 +0200 (CEST) Subject: r1548 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070625061441.289621EC030@projects.linpro.no> Author: phk Date: 2007-06-25 08:14:40 +0200 (Mon, 25 Jun 2007) New Revision: 1548 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/vcl.h trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Add vcl_discard{} method, which can return discard or pass actions. This is for DES' work on LRU list. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-24 10:43:15 UTC (rev 1547) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 06:14:40 UTC (rev 1548) @@ -127,6 +127,9 @@ " }\n" " insert;\n" "}\n" + "sub vcl_discard {\n" + " discard;\n" + "}\n" "sub vcl_timeout {\n" " discard;\n" "}\n"; Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2007-06-24 10:43:15 UTC (rev 1547) +++ trunk/varnish-cache/include/vcl.h 2007-06-25 06:14:40 UTC (rev 1548) @@ -39,4 +39,5 @@ vcl_func_f *hit_func; vcl_func_f *fetch_func; vcl_func_f *timeout_func; + vcl_func_f *discard_func; }; Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2007-06-24 10:43:15 UTC (rev 1547) +++ trunk/varnish-cache/include/vcl_returns.h 2007-06-25 06:14:40 UTC (rev 1548) @@ -40,5 +40,6 @@ VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_INSERT)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) +VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_PASS)) #endif -#define N_METHODS 8 +#define N_METHODS 9 Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-24 10:43:15 UTC (rev 1547) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-25 06:14:40 UTC (rev 1548) @@ -350,6 +350,7 @@ vsb_cat(sb, " vcl_func_f *hit_func;\n"); vsb_cat(sb, " vcl_func_f *fetch_func;\n"); vsb_cat(sb, " vcl_func_f *timeout_func;\n"); + vsb_cat(sb, " vcl_func_f *discard_func;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "/*-\n"); vsb_cat(sb, " * Copyright (c) 2006 Verdens Gang AS\n"); @@ -470,10 +471,12 @@ vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); - vsb_cat(sb, "double VRT_r_obj_valid(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, double);\n"); - vsb_cat(sb, "double VRT_r_obj_cacheable(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, double);\n"); + vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); + vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); + vsb_cat(sb, "unsigned VRT_r_obj_cacheable(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-24 10:43:15 UTC (rev 1547) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-25 06:14:40 UTC (rev 1548) @@ -42,6 +42,7 @@ {hit {error pass deliver}} {fetch {error pass insert}} {timeout {fetch discard}} + {discard {discard pass}} } # These are the return actions From phk at projects.linpro.no Mon Jun 25 06:46:35 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 08:46:35 +0200 (CEST) Subject: r1549 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625064635.0A2C11EC294@projects.linpro.no> Author: phk Date: 2007-06-25 08:46:34 +0200 (Mon, 25 Jun 2007) New Revision: 1549 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Also tun the compiled VCL through cc(1) and try to load it into mgt process when -C is specified, this makes it easier to do completeness test on the VRT interface. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 06:14:40 UTC (rev 1548) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 06:46:34 UTC (rev 1549) @@ -237,26 +237,34 @@ /*--------------------------------------------------------------------*/ static char * -mgt_VccCompile(struct vsb *sb, const char *b, const char *e) +mgt_VccCompile(struct vsb *sb, const char *b, const char *e, int C_flag) { char *csrc, *vf = NULL; csrc = VCC_Compile(sb, b, e); if (csrc != NULL) { + if (C_flag) + fputs(csrc, stdout); vf = mgt_CallCc(csrc, sb); + if (C_flag && vf != NULL) + AZ(unlink(vf)); free(csrc); } return (vf); } static char * -mgt_VccCompileFile(struct vsb *sb, const char *fn) +mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag) { char *csrc, *vf = NULL; csrc = VCC_CompileFile(sb, fn); if (csrc != NULL) { + if (C_flag) + fputs(csrc, stdout); vf = mgt_CallCc(csrc, sb); + if (C_flag && vf != NULL) + AZ(unlink(vf)); free(csrc); } return (vf); @@ -308,7 +316,7 @@ int mgt_vcc_default(const char *b_arg, const char *f_arg, int C_flag) { - char *addr, *port, *csrc; + char *addr, *port; char *buf, *vf; struct vsb *sb; struct vclprog *vp; @@ -338,20 +346,10 @@ free(addr); free(port); AN(buf); - if (C_flag) { - csrc = VCC_Compile(sb, buf, NULL); - if (csrc != NULL) - fputs(csrc, stdout); - } - vf = mgt_VccCompile(sb, buf, NULL); + vf = mgt_VccCompile(sb, buf, NULL, C_flag); free(buf); - } else if (C_flag) { - csrc = VCC_CompileFile(sb, f_arg); - if (csrc != NULL) - fputs(csrc, stdout); - vf = NULL; } else { - vf = mgt_VccCompileFile(sb, f_arg); + vf = mgt_VccCompileFile(sb, f_arg, C_flag); } vsb_finish(sb); if (vsb_len(sb) > 0) { @@ -432,7 +430,7 @@ sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); XXXAN(sb); - vf = mgt_VccCompile(sb, av[3], NULL); + vf = mgt_VccCompile(sb, av[3], NULL, 0); vsb_finish(sb); if (vsb_len(sb) > 0) { cli_out(cli, "%s", vsb_data(sb)); @@ -463,7 +461,7 @@ sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); XXXAN(sb); - vf = mgt_VccCompileFile(sb, av[3]); + vf = mgt_VccCompileFile(sb, av[3], 0); vsb_finish(sb); if (vsb_len(sb) > 0) { cli_out(cli, "%s", vsb_data(sb)); From phk at phk.freebsd.dk Mon Jun 25 06:57:54 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 25 Jun 2007 06:57:54 +0000 Subject: r1549 - trunk/varnish-cache/bin/varnishd In-Reply-To: Your message of "Mon, 25 Jun 2007 08:46:35 +0200." <20070625064635.0A2C11EC294@projects.linpro.no> Message-ID: <57393.1182754674@critter.freebsd.dk> In message <20070625064635.0A2C11EC294 at projects.linpro.no>, phk at projects.linpro .no writes: >Author: phk >Date: 2007-06-25 08:46:34 +0200 (Mon, 25 Jun 2007) >New Revision: 1549 > >Modified: > trunk/varnish-cache/bin/varnishd/mgt_vcc.c >Log: >Also tun the compiled VCL through cc(1) and try to load it into mgt process s/tun/run/ obviously -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From phk at projects.linpro.no Mon Jun 25 07:04:13 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 09:04:13 +0200 (CEST) Subject: r1550 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070625070413.ADE591EC294@projects.linpro.no> Author: phk Date: 2007-06-25 09:04:13 +0200 (Mon, 25 Jun 2007) New Revision: 1550 Modified: trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Add VCL_MET_${METHOD} bitmap defines Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2007-06-25 06:46:34 UTC (rev 1549) +++ trunk/varnish-cache/include/vcl_returns.h 2007-06-25 07:04:13 UTC (rev 1550) @@ -41,5 +41,15 @@ VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_INSERT)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_PASS)) +#else +#define VCL_MET_RECV (1 << 0) +#define VCL_MET_PIPE (1 << 1) +#define VCL_MET_PASS (1 << 2) +#define VCL_MET_HASH (1 << 3) +#define VCL_MET_MISS (1 << 4) +#define VCL_MET_HIT (1 << 5) +#define VCL_MET_FETCH (1 << 6) +#define VCL_MET_TIMEOUT (1 << 7) +#define VCL_MET_DISCARD (1 << 8) #endif #define N_METHODS 9 Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-25 06:46:34 UTC (rev 1549) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-25 07:04:13 UTC (rev 1550) @@ -192,6 +192,12 @@ puts $for ")" incr u } +puts $for "#else" +set u 0 +foreach m $methods { + puts $for "#define VCL_MET_[string toupper [lindex $m 0]]\t(1 << $u)" + incr u +} puts $for "#endif" puts $for "#define N_METHODS $u" close $for From phk at projects.linpro.no Mon Jun 25 07:14:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 09:14:08 +0200 (CEST) Subject: r1551 - trunk/varnish-cache/lib/libvcl Message-ID: <20070625071408.69D861EC030@projects.linpro.no> Author: phk Date: 2007-06-25 09:14:08 +0200 (Mon, 25 Jun 2007) New Revision: 1551 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Add bitmap of methods where they are valid to all objects. Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 07:04:13 UTC (rev 1550) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 07:14:08 UTC (rev 1551) @@ -121,6 +121,7 @@ const char *rname; const char *lname; unsigned has_string; + unsigned methods; }; struct method { Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 07:04:13 UTC (rev 1550) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 07:14:08 UTC (rev 1551) @@ -40,19 +40,45 @@ # Objects which operate on sessions set spobj { - { client.ip IP 1} - { server.ip IP 1} - { req.request STRING 1} - { req.host STRING 1} - { req.url STRING 1} - { req.proto STRING 1} - { req.backend BACKEND 0} - { req.hash HASH 0} - { obj.valid BOOL 0} - { obj.cacheable BOOL 0} - { obj.ttl TIME 0} - { req.http. HEADER 1} - { resp.http. HEADER 1} + { client.ip IP 1 + {recv pipe pass hash miss hit fetch} + } + { server.ip IP 1 + {recv pipe pass hash miss hit fetch} + } + { req.request STRING 1 + {recv pipe pass hash miss hit fetch} + } + { req.host STRING 1 + {recv pipe pass hash miss hit fetch} + } + { req.url STRING 1 + {recv pipe pass hash miss hit fetch} + } + { req.proto STRING 1 + {recv pipe pass hash miss hit fetch} + } + { req.backend BACKEND 0 + {recv pipe pass hash miss hit fetch} + } + { req.http. HEADER 1 + {recv pipe pass hash miss hit fetch} + } + { req.hash HASH 0 + {hash} + } + { obj.valid BOOL 0 + {hit fetch} + } + { obj.cacheable BOOL 0 + {hit fetch} + } + { obj.ttl TIME 0 + {hit fetch} + } + { resp.http. HEADER 1 + {fetch} + } } set tt(IP) "struct sockaddr *" @@ -85,6 +111,16 @@ set fp [open ../../include/vrt_obj.h w] warns $fp +proc method_map {m} { + + set l "" + foreach i $m { + append l " | " + append l VCL_MET_[string toupper $i] + } + return [string range $l 3 end] +} + proc vars {v ty pa} { global tt fo fp @@ -95,7 +131,8 @@ puts $fo "\t\{ \"$n\", $t, [string length $n]," puts $fo "\t \"VRT_r_${m}($pa)\"," puts $fo "\t \"VRT_l_${m}($pa, \"," - puts $fo "\t [lindex $v 2]" + puts $fo "\t [lindex $v 2], " + puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," puts $fp "$tt($t) VRT_r_${m}($ty);" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 07:04:13 UTC (rev 1550) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 07:14:08 UTC (rev 1551) @@ -13,17 +13,20 @@ { "backend.host", HOSTNAME, 12, "VRT_r_backend_host(backend)", "VRT_l_backend_host(backend, ", - 0 + 0, + }, { "backend.port", PORTNAME, 12, "VRT_r_backend_port(backend)", "VRT_l_backend_port(backend, ", - 0 + 0, + }, { "backend.dnsttl", TIME, 14, "VRT_r_backend_dnsttl(backend)", "VRT_l_backend_dnsttl(backend, ", - 0 + 0, + }, { NULL } }; @@ -32,67 +35,80 @@ { "client.ip", IP, 9, "VRT_r_client_ip(sp)", "VRT_l_client_ip(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", "VRT_l_server_ip(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", "VRT_l_req_request(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.host", STRING, 8, "VRT_r_req_host(sp)", "VRT_l_req_host(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", "VRT_l_req_url(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", "VRT_l_req_proto(sp, ", - 1 + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", - 0 + 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, + { "req.http.", HEADER, 9, + "VRT_r_req_http_(sp)", + "VRT_l_req_http_(sp, ", + 1, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + }, { "req.hash", HASH, 8, "VRT_r_req_hash(sp)", "VRT_l_req_hash(sp, ", - 0 + 0, + VCL_MET_HASH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", - 0 + 0, + VCL_MET_HIT | VCL_MET_FETCH }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", - 0 + 0, + VCL_MET_HIT | VCL_MET_FETCH }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", - 0 + 0, + VCL_MET_HIT | VCL_MET_FETCH }, - { "req.http.", HEADER, 9, - "VRT_r_req_http_(sp)", - "VRT_l_req_http_(sp, ", - 1 - }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", - 1 + 1, + VCL_MET_FETCH }, { NULL } }; From phk at projects.linpro.no Mon Jun 25 08:17:26 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 10:17:26 +0200 (CEST) Subject: r1552 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070625081726.269AA1EC294@projects.linpro.no> Author: phk Date: 2007-06-25 10:17:25 +0200 (Mon, 25 Jun 2007) New Revision: 1552 Modified: trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: Make the VCL compiler complain about attempts to access variables outside their scope. One example of this is the "req.hash" variable which only exists in the vcl_hash method. Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-06-25 07:14:08 UTC (rev 1551) +++ trunk/varnish-cache/include/vrt_obj.h 2007-06-25 08:17:25 UTC (rev 1552) @@ -26,6 +26,8 @@ void VRT_l_req_proto(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); +const char * VRT_r_req_http_(struct sess *); +void VRT_l_req_http_(struct sess *, const char *); const char * VRT_r_req_hash(struct sess *); void VRT_l_req_hash(struct sess *, const char *); unsigned VRT_r_obj_valid(struct sess *); @@ -34,7 +36,5 @@ void VRT_l_obj_cacheable(struct sess *, unsigned); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); -const char * VRT_r_req_http_(struct sess *); -void VRT_l_req_http_(struct sess *, const char *); const char * VRT_r_resp_http_(struct sess *); void VRT_l_resp_http_(struct sess *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 07:14:08 UTC (rev 1551) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 08:17:25 UTC (rev 1552) @@ -82,7 +82,7 @@ struct method method_tab[] = { #define VCL_RET_MAC(l,U,b,n) -#define VCL_MET_MAC(l,U,m) { "vcl_"#l, m }, +#define VCL_MET_MAC(l,U,m) { "vcl_"#l, m, VCL_MET_##U }, #include "vcl_returns.h" #undef VCL_MET_MAC #undef VCL_RET_MAC @@ -278,6 +278,7 @@ continue; if (memcmp(t->b, v->name, v->len)) continue; + vcc_AddUses(tl, v); if (v->fmt != HEADER) return (v); return (HeaderVar(tl, t, v)); @@ -645,6 +646,11 @@ if (tl->err) return (vcc_DestroyTokenList(tl, NULL)); + /* Check that all variable uses are legal */ + vcc_CheckUses(tl); + if (tl->err) + return (vcc_DestroyTokenList(tl, NULL)); + Ff(tl, 0, "\tVRT_free_backends(&VCL_conf);\n"); /* Emit method functions */ Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 07:14:08 UTC (rev 1551) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:17:25 UTC (rev 1552) @@ -127,10 +127,9 @@ struct method { const char *name; unsigned returns; + unsigned bitval; }; -struct proc; - /*--------------------------------------------------------------------*/ /* vcc_acl.c */ @@ -180,7 +179,7 @@ void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e); void vcc_FreeToken(struct token *t); -/* vcc_expr.c */ +/* vcc_xref.c */ void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type); void vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type); int vcc_CheckReferences(struct tokenlist *tl); @@ -189,6 +188,8 @@ struct proc *vcc_AddProc(struct tokenlist *tl, struct token *t); void vcc_ProcAction(struct proc *p, unsigned action, struct token *t); int vcc_CheckAction(struct tokenlist *tl); +void vcc_AddUses(struct tokenlist *tl, struct var *v); +int vcc_CheckUses(struct tokenlist *tl); #define ERRCHK(tl) do { if ((tl)->err) return; } while (0) #define ErrInternal(tl) vcc__ErrInternal(tl, __func__, __LINE__) Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 07:14:08 UTC (rev 1551) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 08:17:25 UTC (rev 1552) @@ -545,6 +545,7 @@ tl->indent -= INDENT; Fb(tl, 0, "\n"); tl->fb = NULL; + tl->curproc = NULL; } /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-06-25 07:14:08 UTC (rev 1551) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-06-25 08:17:25 UTC (rev 1552) @@ -55,9 +55,16 @@ struct token *t; }; +struct procuse { + TAILQ_ENTRY(procuse) list; + struct token *t; + struct var *v; +}; + struct proc { TAILQ_ENTRY(proc) list; TAILQ_HEAD(,proccall) calls; + TAILQ_HEAD(,procuse) uses; struct token *name; unsigned returns; unsigned exists; @@ -180,6 +187,7 @@ p = TlAlloc(tl, sizeof *p); assert(p != NULL); TAILQ_INIT(&p->calls); + TAILQ_INIT(&p->uses); TAILQ_INSERT_TAIL(&tl->procs, p, list); p->name = t; return (p); @@ -197,6 +205,20 @@ } void +vcc_AddUses(struct tokenlist *tl, struct var *v) +{ + struct procuse *pu; + + if (tl->curproc == NULL) /* backend */ + return; + pu = TlAlloc(tl, sizeof *pu); + assert(pu != NULL); + pu->v = v; + pu->t = tl->t; + TAILQ_INSERT_TAIL(&tl->curproc->uses, pu, list); +} + +void vcc_AddCall(struct tokenlist *tl, struct token *t) { struct proccall *pc; @@ -305,3 +327,73 @@ return (0); } +static struct procuse * +vcc_FindIllegalUse(struct proc *p, struct method *m) +{ + struct procuse *pu; + + TAILQ_FOREACH(pu, &p->uses, list) + if (!(pu->v->methods & m->bitval)) + return (pu); + return (NULL); +} + +static int +vcc_CheckUseRecurse(struct tokenlist *tl, struct proc *p, struct method *m) +{ + struct proccall *pc; + struct procuse *pu; + + pu = vcc_FindIllegalUse(p, m); + if (pu != NULL) { + vsb_printf(tl->sb, + "Variable \"%.*s\" is not available in %s\n", + PF(pu->t), m->name); + vcc_ErrWhere(tl, pu->t); + vsb_printf(tl->sb, "\n...in function \"%.*s\"\n", + PF(p->name)); + vcc_ErrWhere(tl, p->name); + return (1); + } + TAILQ_FOREACH(pc, &p->calls, list) { + if (vcc_CheckUseRecurse(tl, pc->p, m)) { + vsb_printf(tl->sb, "\n...called from \"%.*s\"\n", + PF(p->name)); + vcc_ErrWhere(tl, pc->t); + return (1); + } + } + return (0); +} + +int +vcc_CheckUses(struct tokenlist *tl) +{ + struct proc *p; + struct method *m; + struct procuse *pu; + int i; + + TAILQ_FOREACH(p, &tl->procs, list) { + i = IsMethod(p->name); + if (i < 0) + continue; + m = method_tab + i; + pu = vcc_FindIllegalUse(p, m); + if (pu != NULL) { + vsb_printf(tl->sb, + "Variable '%.*s' not accessible in method '%.*s'.", + PF(pu->t), PF(p->name)); + vsb_cat(tl->sb, "\nAt: "); + vcc_ErrWhere(tl, pu->t); + return (1); + } + if (vcc_CheckUseRecurse(tl, p, m)) { + vsb_printf(tl->sb, + "\n...which is the \"%s\" method\n", m->name); + return (1); + } + } + return (0); +} + From phk at projects.linpro.no Mon Jun 25 08:57:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 10:57:09 +0200 (CEST) Subject: r1553 - trunk/varnish-cache/lib/libvcl Message-ID: <20070625085709.5C3CC1EC2EE@projects.linpro.no> Author: phk Date: 2007-06-25 10:57:09 +0200 (Mon, 25 Jun 2007) New Revision: 1553 Added: trunk/varnish-cache/lib/libvcl/vcc_var.c Modified: trunk/varnish-cache/lib/libvcl/Makefile.am trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_parse.c Log: Move variable related stuff to vcc_var.c Modified: trunk/varnish-cache/lib/libvcl/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvcl/Makefile.am 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/Makefile.am 2007-06-25 08:57:09 UTC (rev 1553) @@ -17,6 +17,7 @@ vcc_fixed_token.c \ vcc_obj.c \ vcc_token.c \ + vcc_var.c \ vcc_xref.c libvcl_la_CFLAGS = -include config.h Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-25 08:57:09 UTC (rev 1553) @@ -39,44 +39,6 @@ /*--------------------------------------------------------------------*/ -static void -StringVal(struct tokenlist *tl) -{ - struct var *vp; - struct token *vt; - - if (tl->t->tok == CSTR) { - EncToken(tl->fb, tl->t); - vcc_NextToken(tl); - return; - } - ExpectErr(tl, VAR); - ERRCHK(tl); - vt = tl->t; - vp = FindVar(tl, tl->t, vcc_vars); - ERRCHK(tl); - if (!vp->has_string) { - vsb_printf(tl->sb, - "No string representation of '%s'\n", vp->name); - vcc_ErrWhere(tl, tl->t); - return; - } - switch (vp->fmt) { - case STRING: - Fb(tl, 0, "%s", vp->rname); - break; - default: - vsb_printf(tl->sb, - "String representation of '%s' not implemented yet.\n", - vp->name); - vcc_ErrWhere(tl, tl->t); - return; - } - vcc_NextToken(tl); -} - -/*--------------------------------------------------------------------*/ - #define VCL_RET_MAC(l,u,b,i) \ static void \ parse_##l(struct tokenlist *tl) \ @@ -140,7 +102,7 @@ vcc_NextToken(tl); ExpectErr(tl, VAR); vt = tl->t; - vp = FindVar(tl, tl->t, vcc_vars); + vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); Fb(tl, 1, "%s", vp->lname); @@ -222,7 +184,7 @@ case HASH: ExpectErr(tl, T_INCR); vcc_NextToken(tl); - StringVal(tl); + vcc_StringVal(tl); Fb(tl, 0, ");\n"); return; default: Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-25 08:57:09 UTC (rev 1553) @@ -100,7 +100,7 @@ } vcc_NextToken(tl); ExpectErr(tl, VAR); - vp = FindVar(tl, tl->t, vcc_be_vars); + vp = vcc_FindVar(tl, tl->t, vcc_be_vars); ERRCHK(tl); assert(vp != NULL); vcc_NextToken(tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 08:57:09 UTC (rev 1553) @@ -232,64 +232,6 @@ EncString(sb, t->dec, NULL, 0); } -/*--------------------------------------------------------------------*/ - -static struct var * -HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) -{ - char *p; - struct var *v; - int i, w; - - (void)tl; - - v = TlAlloc(tl, sizeof *v); - assert(v != NULL); - i = t->e - t->b; - p = TlAlloc(tl, i + 1); - assert(p != NULL); - memcpy(p, t->b, i); - p[i] = '\0'; - v->name = p; - v->fmt = STRING; - v->has_string = vh->has_string; - if (!memcmp(vh->name, "req.", 4)) - w = 1; - else - w = 2; - asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w, - (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); - assert(p != NULL); - v->rname = p; - return (v); -} - -/*--------------------------------------------------------------------*/ - -struct var * -FindVar(struct tokenlist *tl, const struct token *t, struct var *vl) -{ - struct var *v; - - for (v = vl; v->name != NULL; v++) { - if (v->fmt == HEADER && (t->e - t->b) <= v->len) - continue; - if (v->fmt != HEADER && t->e - t->b != v->len) - continue; - if (memcmp(t->b, v->name, v->len)) - continue; - vcc_AddUses(tl, v); - if (v->fmt != HEADER) - return (v); - return (HeaderVar(tl, t, v)); - } - vsb_printf(tl->sb, "Unknown variable "); - vcc_ErrToken(tl, t); - vsb_cat(tl->sb, "\nAt: "); - vcc_ErrWhere(tl, t); - return (NULL); -} - /*-------------------------------------------------------------------- * Output the location/profiling table. For each counted token, we * record source+line+charpos for the first character in the token. Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:57:09 UTC (rev 1553) @@ -151,7 +151,6 @@ void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...); void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...); void EncToken(struct vsb *sb, const struct token *t); -struct var *FindVar(struct tokenlist *tl, const struct token *t, struct var *vl); int IsMethod(const struct token *t); void *TlAlloc(struct tokenlist *tl, unsigned len); @@ -179,6 +178,10 @@ void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e); void vcc_FreeToken(struct token *t); +/* vcc_var.c */ +void vcc_StringVal(struct tokenlist *tl); +struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl); + /* vcc_xref.c */ void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type); void vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type); Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 08:17:25 UTC (rev 1552) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 08:57:09 UTC (rev 1553) @@ -348,7 +348,7 @@ ExpectErr(tl, ')'); vcc_NextToken(tl); } else if (tl->t->tok == VAR) { - vp = FindVar(tl, tl->t, vcc_vars); + vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); vcc_NextToken(tl); Added: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c (rev 0) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-25 08:57:09 UTC (rev 1553) @@ -0,0 +1,136 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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. + * + * $Id$ + */ + +#include +#include + +#include "vsb.h" + +#include "vcc_priv.h" +#include "vcc_compile.h" +#include "libvarnish.h" + +/*--------------------------------------------------------------------*/ + +void +vcc_StringVal(struct tokenlist *tl) +{ + struct var *vp; + struct token *vt; + + if (tl->t->tok == CSTR) { + EncToken(tl->fb, tl->t); + vcc_NextToken(tl); + return; + } + ExpectErr(tl, VAR); + ERRCHK(tl); + vt = tl->t; + vp = vcc_FindVar(tl, tl->t, vcc_vars); + ERRCHK(tl); + if (!vp->has_string) { + vsb_printf(tl->sb, + "No string representation of '%s'\n", vp->name); + vcc_ErrWhere(tl, tl->t); + return; + } + switch (vp->fmt) { + case STRING: + Fb(tl, 0, "%s", vp->rname); + break; + default: + vsb_printf(tl->sb, + "String representation of '%s' not implemented yet.\n", + vp->name); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_NextToken(tl); +} + +/*--------------------------------------------------------------------*/ + +static struct var * +HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) +{ + char *p; + struct var *v; + int i, w; + + (void)tl; + + v = TlAlloc(tl, sizeof *v); + assert(v != NULL); + i = t->e - t->b; + p = TlAlloc(tl, i + 1); + assert(p != NULL); + memcpy(p, t->b, i); + p[i] = '\0'; + v->name = p; + v->fmt = STRING; + v->has_string = vh->has_string; + if (!memcmp(vh->name, "req.", 4)) + w = 1; + else + w = 2; + asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w, + (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); + assert(p != NULL); + v->rname = p; + return (v); +} + +/*--------------------------------------------------------------------*/ + +struct var * +vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl) +{ + struct var *v; + + for (v = vl; v->name != NULL; v++) { + if (v->fmt == HEADER && (t->e - t->b) <= v->len) + continue; + if (v->fmt != HEADER && t->e - t->b != v->len) + continue; + if (memcmp(t->b, v->name, v->len)) + continue; + vcc_AddUses(tl, v); + if (v->fmt != HEADER) + return (v); + return (HeaderVar(tl, t, v)); + } + vsb_printf(tl->sb, "Unknown variable "); + vcc_ErrToken(tl, t); + vsb_cat(tl->sb, "\nAt: "); + vcc_ErrWhere(tl, t); + return (NULL); +} + From phk at projects.linpro.no Mon Jun 25 09:10:20 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 11:10:20 +0200 (CEST) Subject: r1554 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070625091020.4FEE31EC405@projects.linpro.no> Author: phk Date: 2007-06-25 11:10:20 +0200 (Mon, 25 Jun 2007) New Revision: 1554 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Use an enum instead of magic '1' and '2' values to VRT_GetHdr. Remove bogus "has_string" variable marking, it can be derived from the type. Make obj.* variables valid in vcl_timeout() and vcl_discard() Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-25 09:10:20 UTC (rev 1554) @@ -71,17 +71,17 @@ /*--------------------------------------------------------------------*/ char * -VRT_GetHdr(struct sess *sp, int where, const char *n) +VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) { char *p; struct http *hp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); switch (where) { - case 1: + case HDR_REQ: hp = sp->http; break; - case 2: + case HDR_RESP: hp = &sp->obj->http; break; default: Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/include/vrt.h 2007-06-25 09:10:20 UTC (rev 1554) @@ -74,7 +74,8 @@ void VRT_error(struct sess *, unsigned, const char *); int VRT_switch_config(const char *); -char *VRT_GetHdr(struct sess *, int where, const char *); +enum gethdr_e { HDR_REQ, HDR_RESP }; +char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 09:10:20 UTC (rev 1554) @@ -120,7 +120,6 @@ unsigned len; const char *rname; const char *lname; - unsigned has_string; unsigned methods; }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-25 09:10:20 UTC (rev 1554) @@ -428,7 +428,8 @@ vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); vsb_cat(sb, "int VRT_switch_config(const char *);\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, "char *VRT_GetHdr(struct sess *, int where, const char *);\n"); + vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP };\n"); + vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); @@ -471,6 +472,8 @@ vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); + vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); @@ -479,8 +482,6 @@ vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); - vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 09:10:20 UTC (rev 1554) @@ -32,53 +32,27 @@ # Objects which operate on backends set beobj { - { backend.host HOSTNAME 0 } - { backend.port PORTNAME 0 } - { backend.dnsttl TIME 0 } + { backend.host HOSTNAME } + { backend.port PORTNAME } + { backend.dnsttl TIME } } # Objects which operate on sessions set spobj { - { client.ip IP 1 - {recv pipe pass hash miss hit fetch} - } - { server.ip IP 1 - {recv pipe pass hash miss hit fetch} - } - { req.request STRING 1 - {recv pipe pass hash miss hit fetch} - } - { req.host STRING 1 - {recv pipe pass hash miss hit fetch} - } - { req.url STRING 1 - {recv pipe pass hash miss hit fetch} - } - { req.proto STRING 1 - {recv pipe pass hash miss hit fetch} - } - { req.backend BACKEND 0 - {recv pipe pass hash miss hit fetch} - } - { req.http. HEADER 1 - {recv pipe pass hash miss hit fetch} - } - { req.hash HASH 0 - {hash} - } - { obj.valid BOOL 0 - {hit fetch} - } - { obj.cacheable BOOL 0 - {hit fetch} - } - { obj.ttl TIME 0 - {hit fetch} - } - { resp.http. HEADER 1 - {fetch} - } + { client.ip IP {recv pipe pass hash miss hit fetch } } + { server.ip IP {recv pipe pass hash miss hit fetch } } + { req.request STRING {recv pipe pass hash miss hit fetch } } + { req.host STRING {recv pipe pass hash miss hit fetch } } + { req.url STRING {recv pipe pass hash miss hit fetch } } + { req.proto STRING {recv pipe pass hash miss hit fetch } } + { req.backend BACKEND {recv pipe pass hash miss hit fetch } } + { req.http. HEADER {recv pipe pass hash miss hit fetch } } + { req.hash HASH { hash } } + { obj.valid BOOL { hit fetch discard timeout} } + { obj.cacheable BOOL { hit fetch discard timeout} } + { obj.ttl TIME { hit fetch discard timeout} } + { resp.http. HEADER { fetch } } } set tt(IP) "struct sockaddr *" @@ -131,8 +105,7 @@ puts $fo "\t\{ \"$n\", $t, [string length $n]," puts $fo "\t \"VRT_r_${m}($pa)\"," puts $fo "\t \"VRT_l_${m}($pa, \"," - puts $fo "\t [lindex $v 2], " - puts $fo "\t [method_map [lindex $v 3]]" + puts $fo "\t [method_map [lindex $v 2]]" puts $fo "\t\}," puts $fp "$tt($t) VRT_r_${m}($ty);" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 09:10:20 UTC (rev 1554) @@ -13,19 +13,16 @@ { "backend.host", HOSTNAME, 12, "VRT_r_backend_host(backend)", "VRT_l_backend_host(backend, ", - 0, }, { "backend.port", PORTNAME, 12, "VRT_r_backend_port(backend)", "VRT_l_backend_port(backend, ", - 0, }, { "backend.dnsttl", TIME, 14, "VRT_r_backend_dnsttl(backend)", "VRT_l_backend_dnsttl(backend, ", - 0, }, { NULL } @@ -35,79 +32,66 @@ { "client.ip", IP, 9, "VRT_r_client_ip(sp)", "VRT_l_client_ip(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", "VRT_l_server_ip(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", "VRT_l_req_request(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.host", STRING, 8, "VRT_r_req_host(sp)", "VRT_l_req_host(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", "VRT_l_req_url(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", "VRT_l_req_proto(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", - 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", - 1, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, "VRT_r_req_hash(sp)", "VRT_l_req_hash(sp, ", - 0, VCL_MET_HASH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", - 0, - VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", - 0, - VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", - 0, - VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", - 1, VCL_MET_FETCH }, { NULL } Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-25 08:57:09 UTC (rev 1553) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-25 09:10:20 UTC (rev 1554) @@ -56,12 +56,6 @@ vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); - if (!vp->has_string) { - vsb_printf(tl->sb, - "No string representation of '%s'\n", vp->name); - vcc_ErrWhere(tl, tl->t); - return; - } switch (vp->fmt) { case STRING: Fb(tl, 0, "%s", vp->rname); @@ -82,8 +76,9 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) { char *p; + const char *wh; struct var *v; - int i, w; + int i; (void)tl; @@ -96,12 +91,14 @@ p[i] = '\0'; v->name = p; v->fmt = STRING; - v->has_string = vh->has_string; + v->methods = vh->methods; if (!memcmp(vh->name, "req.", 4)) - w = 1; + wh = "HDR_REQ"; + else if (!memcmp(vh->name, "resp.", 5)) + wh = "HDR_RESP"; else - w = 2; - asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w, + assert(0 == 1); + asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); assert(p != NULL); v->rname = p; From phk at projects.linpro.no Mon Jun 25 09:20:02 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 11:20:02 +0200 (CEST) Subject: r1555 - trunk/varnish-cache/include Message-ID: <20070625092002.B3A0A1EC405@projects.linpro.no> Author: phk Date: 2007-06-25 11:20:02 +0200 (Mon, 25 Jun 2007) New Revision: 1555 Modified: trunk/varnish-cache/include/shmlog_tags.h Log: A friendly reminder Modified: trunk/varnish-cache/include/shmlog_tags.h =================================================================== --- trunk/varnish-cache/include/shmlog_tags.h 2007-06-25 09:10:20 UTC (rev 1554) +++ trunk/varnish-cache/include/shmlog_tags.h 2007-06-25 09:20:02 UTC (rev 1555) @@ -33,6 +33,9 @@ * * REMEMBER to update the documentation (especially the varnishlog(1) man * page) whenever this list changes. + * + * XXX: Please add new entries a the end to not break saved log-segments. + * XXX: we can resort them when we have a major release. */ SLTM(Debug) From phk at projects.linpro.no Mon Jun 25 09:23:14 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 11:23:14 +0200 (CEST) Subject: r1556 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625092314.5EF6C1EC030@projects.linpro.no> Author: phk Date: 2007-06-25 11:23:14 +0200 (Mon, 25 Jun 2007) New Revision: 1556 Modified: trunk/varnish-cache/bin/varnishd/tcp.c Log: Use the correct target of sizeof(). Modified: trunk/varnish-cache/bin/varnishd/tcp.c =================================================================== --- trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-25 09:20:02 UTC (rev 1555) +++ trunk/varnish-cache/bin/varnishd/tcp.c 2007-06-25 09:23:14 UTC (rev 1556) @@ -80,7 +80,7 @@ struct sockaddr *addr = (void*)&addr_s; socklen_t l; - l = sizeof addr; + l = sizeof addr_s; AZ(getsockname(sock, addr, &l)); TCP_name(addr, l, abuf, alen, pbuf, plen); } From phk at projects.linpro.no Mon Jun 25 09:44:55 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 11:44:55 +0200 (CEST) Subject: r1557 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625094455.704EA1EC2EE@projects.linpro.no> Author: phk Date: 2007-06-25 11:44:54 +0200 (Mon, 25 Jun 2007) New Revision: 1557 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c Log: Add -F flag, to force varnishd to run in the foreground. Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 09:23:14 UTC (rev 1556) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 09:44:54 UTC (rev 1557) @@ -169,6 +169,7 @@ " -b ':'"); fprintf(stderr, " %-28s # %s\n", "-d", "debug"); fprintf(stderr, " %-28s # %s\n", "-f file", "VCL script"); + fprintf(stderr, " %-28s # %s\n", "-F", "Run in foreground"); fprintf(stderr, " %-28s # %s\n", "-h kind[,hashoptions]", "Hash specification"); fprintf(stderr, " %-28s # %s\n", "", @@ -399,14 +400,15 @@ main(int argc, char *argv[]) { int o; + unsigned C_flag = 0; unsigned d_flag = 0; + unsigned F_flag = 0; const char *b_arg = NULL; const char *f_arg = NULL; const char *h_arg = "classic"; const char *P_arg = NULL; const char *s_arg = "file"; const char *T_arg = NULL; - unsigned C_flag = 0; char *p; struct cli cli[1]; struct pidfh *pfh = NULL; @@ -425,7 +427,7 @@ MCF_ParamInit(cli); cli_check(cli); - while ((o = getopt(argc, argv, "a:b:Cdf:g:h:n:P:p:s:T:t:u:Vw:")) != -1) + while ((o = getopt(argc, argv, "a:b:Cdf:Fg:h:n:P:p:s:T:t:u:Vw:")) != -1) switch (o) { case 'a': MCF_ParamSet(cli, "listen_address", optarg); @@ -435,7 +437,7 @@ b_arg = optarg; break; case 'C': - C_flag = 1; + C_flag = 1 - C_flag; break; case 'd': d_flag++; @@ -443,6 +445,9 @@ case 'f': f_arg = optarg; break; + case 'F': + F_flag = 1 - F_flag; + break; case 'g': MCF_ParamSet(cli, "group", optarg); break; @@ -527,7 +532,7 @@ if (d_flag == 1) DebugStunt(); - if (d_flag < 2) + if (d_flag < 2 && !F_flag) daemon(d_flag, d_flag); if (d_flag == 1) printf("%d\n", getpid()); From phk at projects.linpro.no Mon Jun 25 09:46:30 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 11:46:30 +0200 (CEST) Subject: r1558 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625094630.7C8061EC030@projects.linpro.no> Author: phk Date: 2007-06-25 11:46:30 +0200 (Mon, 25 Jun 2007) New Revision: 1558 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c Log: Make sure that -F and -d are exclusive. Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 09:44:54 UTC (rev 1557) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 09:46:30 UTC (rev 1558) @@ -506,6 +506,11 @@ exit(1); } + if (d_flag && F_flag) { + fprintf(stderr, "Only one of -d or -F can be specified\n"); + usage(); + } + if (b_arg != NULL && f_arg != NULL) { fprintf(stderr, "Only one of -b or -f can be specified\n"); usage(); From phk at projects.linpro.no Mon Jun 25 10:22:44 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 12:22:44 +0200 (CEST) Subject: r1559 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625102244.6D25C1EC428@projects.linpro.no> Author: phk Date: 2007-06-25 12:22:44 +0200 (Mon, 25 Jun 2007) New Revision: 1559 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Discard any listen sockets that fail to bind(). This can happen if you get an IPv6 address for the -a argument, but runs without IPv6 enabled in your kernel. Typically happens only for localhost. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-25 09:46:30 UTC (rev 1558) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-25 10:22:44 UTC (rev 1559) @@ -126,16 +126,23 @@ static int open_sockets(void) { - struct listen_sock *ls; + struct listen_sock *ls, *ls2; + int good = 0; - TAILQ_FOREACH(ls, &heritage.socks, list) { + TAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) { if (ls->sock >= 0) continue; ls->sock = VSS_listen(ls->addr, params->listen_depth); + if (ls->sock < 0) { + TAILQ_REMOVE(&heritage.socks, ls, list); + free(ls); + continue; + } TCP_filter_http(ls->sock); - if (ls->sock < 0) - return (1); + good++; } + if (!good) + return (1); return (0); } From phk at projects.linpro.no Mon Jun 25 10:37:12 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 12:37:12 +0200 (CEST) Subject: r1560 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070625103712.2F2C11EC294@projects.linpro.no> Author: phk Date: 2007-06-25 12:37:11 +0200 (Mon, 25 Jun 2007) New Revision: 1560 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Implement resp.proto resp.status and resp.response. Visible from vcl_fetch() only. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-25 10:22:44 UTC (rev 1559) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-25 10:37:11 UTC (rev 1560) @@ -253,6 +253,32 @@ /*--------------------------------------------------------------------*/ +const char * +VRT_r_resp_proto(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + return (sp->obj->http.hd[HTTP_HDR_PROTO].b); +} + +const char * +VRT_r_resp_response(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + return (sp->obj->http.hd[HTTP_HDR_RESPONSE].b); +} + +int +VRT_r_resp_status(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + return (atoi(sp->obj->http.hd[HTTP_HDR_STATUS].b)); +} + +/*--------------------------------------------------------------------*/ + struct sockaddr * VRT_r_client_ip(struct sess *sp) { Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-06-25 10:22:44 UTC (rev 1559) +++ trunk/varnish-cache/include/vrt_obj.h 2007-06-25 10:37:11 UTC (rev 1560) @@ -36,5 +36,11 @@ void VRT_l_obj_cacheable(struct sess *, unsigned); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); +const char * VRT_r_resp_proto(struct sess *); +void VRT_l_resp_proto(struct sess *, const char *); +int VRT_r_resp_status(struct sess *); +void VRT_l_resp_status(struct sess *, int); +const char * VRT_r_resp_response(struct sess *); +void VRT_l_resp_response(struct sess *, const char *); const char * VRT_r_resp_http_(struct sess *); void VRT_l_resp_http_(struct sess *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 10:22:44 UTC (rev 1559) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-25 10:37:11 UTC (rev 1560) @@ -52,6 +52,9 @@ { obj.valid BOOL { hit fetch discard timeout} } { obj.cacheable BOOL { hit fetch discard timeout} } { obj.ttl TIME { hit fetch discard timeout} } + { resp.proto STRING { fetch } } + { resp.status INT { fetch } } + { resp.response STRING { fetch } } { resp.http. HEADER { fetch } } } @@ -60,6 +63,7 @@ set tt(BOOL) "unsigned" set tt(BACKEND) "struct backend *" set tt(TIME) "double" +set tt(INT) "int" set tt(HEADER) "const char *" set tt(HOSTNAME) "const char *" set tt(PORTNAME) "const char *" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 10:22:44 UTC (rev 1559) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-25 10:37:11 UTC (rev 1560) @@ -89,6 +89,21 @@ "VRT_l_obj_ttl(sp, ", VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, + { "resp.proto", STRING, 10, + "VRT_r_resp_proto(sp)", + "VRT_l_resp_proto(sp, ", + VCL_MET_FETCH + }, + { "resp.status", INT, 11, + "VRT_r_resp_status(sp)", + "VRT_l_resp_status(sp, ", + VCL_MET_FETCH + }, + { "resp.response", STRING, 13, + "VRT_r_resp_response(sp)", + "VRT_l_resp_response(sp, ", + VCL_MET_FETCH + }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", From des at linpro.no Mon Jun 25 11:53:16 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon, 25 Jun 2007 13:53:16 +0200 Subject: r1548 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <20070625061441.289621EC030@projects.linpro.no> (phk@projects.linpro.no's message of "Mon\, 25 Jun 2007 08\:14\:41 +0200 \(CEST\)") References: <20070625061441.289621EC030@projects.linpro.no> Message-ID: <87vedc1c9f.fsf@des.linpro.no> phk at projects.linpro.no writes: > Log: > Add vcl_discard{} method, which can return discard or pass actions. > > This is for DES' work on LRU list. > [...] > +VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_PASS)) > [...] > + {discard {discard pass}} Thanks! I have one question, though: what do you intend "pass" to mean in the context of vcl_discard()? Perhaps we should add a "keep" keyword instead? DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From phk at phk.freebsd.dk Mon Jun 25 12:02:02 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 25 Jun 2007 12:02:02 +0000 Subject: r1548 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: Your message of "Mon, 25 Jun 2007 13:53:16 +0200." <87vedc1c9f.fsf@des.linpro.no> Message-ID: <30922.1182772922@critter.freebsd.dk> In message <87vedc1c9f.fsf at des.linpro.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= writes: >phk at projects.linpro.no writes: >> Log: >> Add vcl_discard{} method, which can return discard or pass actions. >> >> This is for DES' work on LRU list. >> [...] >> +VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_PASS)) >> [...] >> + {discard {discard pass}} > >Thanks! I have one question, though: what do you intend "pass" to mean >in the context of vcl_discard()? Perhaps we should add a "keep" keyword >instead? "pass on this one": ie: don't discard. If people think "keep" is more intuitive I'll change it. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at linpro.no Mon Jun 25 12:35:12 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon, 25 Jun 2007 14:35:12 +0200 Subject: r1548 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <30922.1182772922@critter.freebsd.dk> (Poul-Henning Kamp's message of "Mon\, 25 Jun 2007 12\:02\:02 +0000") References: <30922.1182772922@critter.freebsd.dk> Message-ID: <87r6o01abj.fsf@des.linpro.no> "Poul-Henning Kamp" writes: > Dag-Erling Sm?rgrav writes: > > Thanks! I have one question, though: what do you intend "pass" to > > mean in the context of vcl_discard()? Perhaps we should add a > > "keep" keyword instead? > "pass on this one": ie: don't discard. > > If people think "keep" is more intuitive I'll change it. I think "keep" would be better, since "pass" has a well-defined meaning in other VCL contexts. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From phk at projects.linpro.no Mon Jun 25 12:38:20 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 14:38:20 +0200 (CEST) Subject: r1561 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070625123820.E3BA31EC294@projects.linpro.no> Author: phk Date: 2007-06-25 14:38:20 +0200 (Mon, 25 Jun 2007) New Revision: 1561 Modified: trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Give vcl_discard() valid return-actions "keep" and "discard". Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2007-06-25 10:37:11 UTC (rev 1560) +++ trunk/varnish-cache/include/vcl_returns.h 2007-06-25 12:38:20 UTC (rev 1561) @@ -18,6 +18,7 @@ VCL_RET_MAC(insert, INSERT, (1 << 6), 6) VCL_RET_MAC(deliver, DELIVER, (1 << 7), 7) VCL_RET_MAC(discard, DISCARD, (1 << 8), 8) +VCL_RET_MAC(keep, KEEP, (1 << 9), 9) #else #define VCL_RET_ERROR (1 << 0) #define VCL_RET_LOOKUP (1 << 1) @@ -28,7 +29,8 @@ #define VCL_RET_INSERT (1 << 6) #define VCL_RET_DELIVER (1 << 7) #define VCL_RET_DISCARD (1 << 8) -#define VCL_RET_MAX 9 +#define VCL_RET_KEEP (1 << 9) +#define VCL_RET_MAX 10 #endif #ifdef VCL_MET_MAC @@ -40,7 +42,7 @@ VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_INSERT)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) -VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_PASS)) +VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_KEEP)) #else #define VCL_MET_RECV (1 << 0) #define VCL_MET_PIPE (1 << 1) Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-25 10:37:11 UTC (rev 1560) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-06-25 12:38:20 UTC (rev 1561) @@ -309,6 +309,7 @@ vsb_cat(sb, "#define VCL_RET_INSERT (1 << 6)\n"); vsb_cat(sb, "#define VCL_RET_DELIVER (1 << 7)\n"); vsb_cat(sb, "#define VCL_RET_DISCARD (1 << 8)\n"); + vsb_cat(sb, "#define VCL_RET_KEEP (1 << 9)\n"); vsb_cat(sb, "/*\n"); vsb_cat(sb, " * $Id$\n"); vsb_cat(sb, " *\n"); @@ -482,6 +483,12 @@ vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); + vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); + vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-25 10:37:11 UTC (rev 1560) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-06-25 12:38:20 UTC (rev 1561) @@ -42,7 +42,7 @@ {hit {error pass deliver}} {fetch {error pass insert}} {timeout {fetch discard}} - {discard {discard pass}} + {discard {discard keep}} } # These are the return actions @@ -57,6 +57,7 @@ insert deliver discard + keep } # Language keywords From phk at phk.freebsd.dk Mon Jun 25 12:38:29 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 25 Jun 2007 12:38:29 +0000 Subject: r1548 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: Your message of "Mon, 25 Jun 2007 14:35:12 +0200." <87r6o01abj.fsf@des.linpro.no> Message-ID: <33689.1182775109@critter.freebsd.dk> In message <87r6o01abj.fsf at des.linpro.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= writes: >"Poul-Henning Kamp" writes: >> Dag-Erling Sm=C3=B8rgrav writes: >> > Thanks! I have one question, though: what do you intend "pass" to >> > mean in the context of vcl_discard()? Perhaps we should add a >> > "keep" keyword instead? >> "pass on this one": ie: don't discard. >> >> If people think "keep" is more intuitive I'll change it. > >I think "keep" would be better, since "pass" has a well-defined meaning >in other VCL contexts. Done. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From phk at projects.linpro.no Mon Jun 25 14:10:34 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 16:10:34 +0200 (CEST) Subject: r1562 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625141034.7D2181EC030@projects.linpro.no> Author: phk Date: 2007-06-25 16:10:34 +0200 (Mon, 25 Jun 2007) New Revision: 1562 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Fix a NULL pointer deref in the Vary code. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 12:38:20 UTC (rev 1561) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 14:10:34 UTC (rev 1562) @@ -158,7 +158,7 @@ o->ttl = 0; VSL(SLT_ExpBan, 0, "%u was banned", o->xid); EXP_TTLchange(o); - } else if (VRY_Match(sp, o->vary)) + } else if (o->vary != NULL && VRY_Match(sp, o->vary)) break; o->refcnt--; } From phk at projects.linpro.no Mon Jun 25 14:12:54 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 16:12:54 +0200 (CEST) Subject: r1563 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625141254.484511EC467@projects.linpro.no> Author: phk Date: 2007-06-25 16:12:54 +0200 (Mon, 25 Jun 2007) New Revision: 1563 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Actually get the logic right here, if there is no Vary string, the object is acceptable to all clients. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 14:10:34 UTC (rev 1562) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 14:12:54 UTC (rev 1563) @@ -158,7 +158,7 @@ o->ttl = 0; VSL(SLT_ExpBan, 0, "%u was banned", o->xid); EXP_TTLchange(o); - } else if (o->vary != NULL && VRY_Match(sp, o->vary)) + } else if (o->vary == NULL || VRY_Match(sp, o->vary)) break; o->refcnt--; } From des at projects.linpro.no Mon Jun 25 14:15:52 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 16:15:52 +0200 (CEST) Subject: r1564 - trunk/varnish-cache/include Message-ID: <20070625141552.41B421EC030@projects.linpro.no> Author: des Date: 2007-06-25 16:15:52 +0200 (Mon, 25 Jun 2007) New Revision: 1564 Modified: trunk/varnish-cache/include/stat_field.h Log: Add fields for storage manager statistics. Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2007-06-25 14:12:54 UTC (rev 1563) +++ trunk/varnish-cache/include/stat_field.h 2007-06-25 14:15:52 UTC (rev 1564) @@ -84,3 +84,8 @@ MAC_STAT(shm_records, uint64_t, "u", "SHM records") MAC_STAT(shm_writes, uint64_t, "u", "SHM writes") MAC_STAT(shm_cont, uint64_t, "u", "SHM MTX contention") + +MAC_STAT(sm_nreq, uint64_t, "u", "allocator requests") +MAC_STAT(sm_nobj, uint64_t, "u", "outstanding allocations") +MAC_STAT(sm_balloc, uint64_t, "u", "bytes allocated") +MAC_STAT(sm_bfree, uint64_t, "u", "bytes free") From des at projects.linpro.no Mon Jun 25 14:24:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 16:24:09 +0200 (CEST) Subject: r1565 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625142409.66ABA1EC294@projects.linpro.no> Author: des Date: 2007-06-25 16:24:09 +0200 (Mon, 25 Jun 2007) New Revision: 1565 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c Log: Maintain statistics about the number of allocations made and the amount of allocated and free space. Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-25 14:15:52 UTC (rev 1564) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-25 14:24:09 UTC (rev 1565) @@ -442,7 +442,7 @@ } /*-------------------------------------------------------------------- - * Free a range. Attemt merge forward and backward, then sort into + * Free a range. Attempt merge forward and backward, then sort into * free list according to age. */ @@ -613,6 +613,8 @@ if (sum < MINPAGES * (uintmax_t)getpagesize()) exit (2); MTX_INIT(&sc->mtx); + + VSL_stats->sm_bfree += sc->filesize; } /*--------------------------------------------------------------------*/ @@ -627,8 +629,12 @@ size += (sc->pagesize - 1); size &= ~(sc->pagesize - 1); LOCK(&sc->mtx); + VSL_stats->sm_nreq++; smf = alloc_smf(sc, size); CHECK_OBJ_NOTNULL(smf, SMF_MAGIC); + VSL_stats->sm_nobj++; + VSL_stats->sm_balloc += smf->size; + VSL_stats->sm_bfree -= smf->size; UNLOCK(&sc->mtx); XXXAN(smf); assert(smf->size == size); @@ -662,6 +668,8 @@ size &= ~(sc->pagesize - 1); if (smf->size > size) { LOCK(&sc->mtx); + VSL_stats->sm_balloc -= (smf->size - size); + VSL_stats->sm_bfree += (smf->size - size); trim_smf(smf, size); assert(smf->size == size); UNLOCK(&sc->mtx); @@ -681,6 +689,9 @@ CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC); sc = smf->sc; LOCK(&sc->mtx); + VSL_stats->sm_nobj--; + VSL_stats->sm_balloc -= smf->size; + VSL_stats->sm_bfree += smf->size; free_smf(smf); UNLOCK(&sc->mtx); } Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-25 14:15:52 UTC (rev 1564) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-25 14:24:09 UTC (rev 1565) @@ -35,6 +35,7 @@ #include +#include "shmlog.h" #include "cache.h" struct sma { @@ -46,6 +47,7 @@ { struct sma *sma; + VSL_stats->sm_nreq++; sma = calloc(sizeof *sma, 1); XXXAN(sma); sma->s.priv = sma; @@ -56,6 +58,8 @@ 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); } @@ -65,6 +69,8 @@ struct sma *sma; sma = s->priv; + VSL_stats->sm_nobj--; + VSL_stats->sm_balloc -= sma->s.space; free(sma->s.ptr); free(sma); } From des at projects.linpro.no Mon Jun 25 14:24:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 16:24:50 +0200 (CEST) Subject: r1566 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625142450.027F41EC030@projects.linpro.no> Author: des Date: 2007-06-25 16:24:49 +0200 (Mon, 25 Jun 2007) New Revision: 1566 Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c Log: Whitespace nits. Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vary.c 2007-06-25 14:24:09 UTC (rev 1565) +++ trunk/varnish-cache/bin/varnishd/cache_vary.c 2007-06-25 14:24:49 UTC (rev 1566) @@ -110,8 +110,8 @@ /* Mark as "not present" */ vsb_printf(sb, "%c%c", 0xff, 0xff); } - - while (isspace(*q)) + + while (isspace(*q)) q++; if (*q == '\0') break; From des at projects.linpro.no Mon Jun 25 15:54:22 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 17:54:22 +0200 (CEST) Subject: r1567 - trunk/varnish-cache/man Message-ID: <20070625155422.E4E101EC294@projects.linpro.no> Author: des Date: 2007-06-25 17:54:22 +0200 (Mon, 25 Jun 2007) New Revision: 1567 Modified: trunk/varnish-cache/man/vcl.7 Log: Document vcl_discard(). Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-06-25 14:24:49 UTC (rev 1566) +++ trunk/varnish-cache/man/vcl.7 2007-06-25 15:54:22 UTC (rev 1567) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd March 28, 2007 +.Dd June 25, 2007 .Dt VCL 7 .Os .Sh NAME @@ -285,8 +285,8 @@ .El .\" vcl_timeout .It Cm vcl_timeout -Called by the reaper thread when a cached document has reached its -expiry time. +Called by the reaper thread shortly before a cached document reaches +its expiry time. .Pp The .Cm vcl_timeout @@ -297,7 +297,22 @@ .It Cm discard Discard the object. .El +.\" vcl_discard +.It Cm vcl_discard +Called by the reaper thread when a cached document is about to be +discarded, either because it has expired or because space is running +low. +.Pp +The +.Cm vcl_discard +subroutine may terminate with one of the following keywords: +.Bl -tag -width "discard" +.It Cm discard +Discard the object. +.It Cm keep +Keep the object in cache. .El +.El .Pp If one of these subroutines is left undefined or terminates without reaching a handling decision, control will be handed over to the @@ -408,6 +423,10 @@ insert; } +sub vcl_discard { + discard; +} + sub vcl_timeout { discard; } From des at projects.linpro.no Mon Jun 25 16:24:18 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 18:24:18 +0200 (CEST) Subject: r1568 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625162418.83A5C1EC030@projects.linpro.no> Author: des Date: 2007-06-25 18:24:18 +0200 (Mon, 25 Jun 2007) New Revision: 1568 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Avoid an assertion failure by not calling EXP_TTLChange() for objects which are not on the expiry heap. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 15:54:22 UTC (rev 1567) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 16:24:18 UTC (rev 1568) @@ -157,7 +157,8 @@ } else if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b)) { o->ttl = 0; VSL(SLT_ExpBan, 0, "%u was banned", o->xid); - EXP_TTLchange(o); + if (o->heap_idx != 0) + EXP_TTLchange(o); } else if (o->vary == NULL || VRY_Match(sp, o->vary)) break; o->refcnt--; From des at projects.linpro.no Mon Jun 25 16:25:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 18:25:29 +0200 (CEST) Subject: r1569 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625162529.37BB01EC294@projects.linpro.no> Author: des Date: 2007-06-25 18:25:29 +0200 (Mon, 25 Jun 2007) New Revision: 1569 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Use FREE_OBJ() instead of just free() when freeing miniobjs. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 16:24:18 UTC (rev 1568) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 16:25:29 UTC (rev 1569) @@ -258,7 +258,7 @@ free(o->vary); HSH_Freestore(o); - free(o); + FREE_OBJ(o); VSL_stats->n_object--; if (oh == NULL) @@ -269,7 +269,7 @@ assert(TAILQ_EMPTY(&oh->objects)); MTX_DESTROY(&oh->mtx); VSL_stats->n_objecthead--; - free(oh); + FREE_OBJ(oh); } void From des at projects.linpro.no Mon Jun 25 17:04:10 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 25 Jun 2007 19:04:10 +0200 (CEST) Subject: r1570 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625170410.22CAD1EC294@projects.linpro.no> Author: des Date: 2007-06-25 19:04:09 +0200 (Mon, 25 Jun 2007) New Revision: 1570 Added: trunk/varnish-cache/bin/varnishd/cache_lru.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c Log: First step in implementing early retirement of objects when the cache fills up: implement a "sloppy" LRU list. An object is placed on the list (or moved to the head of the list if it's already on it and hasn't moved recently) by calling LRU_Enter(), and removed by calling LRU_Remove(). LRU_DiscardSpace() will iterate through the LRU list, starting at the back, and retire objects (by adding them to the deathrow list) until the sum of the length of the retired objects reaches a certain number. Similarly, LRU_DiscardTime() will retire objects which haven't moved since a specified cutoff date. In both cases, vcl_discard() will be given a chance to inspect the object and veto its retirement. Currently, LRU_Enter() and LRU_Remove() are called from HSH_Lookup() and HSH_Deref() respectively. There may be better alternatives. Neither LRU_DiscardSpace() nor LRU_DiscardTime() is currently called from anywhere. There are a number of issues to consider: for instance, even if LRU_DiscardSpace() is called when a high-water mark is reached, there is still a possibility that the cache might fill up before it has had a chance to finish and the hangman has had a chance to process the deathrow list. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-25 16:25:29 UTC (rev 1569) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-25 17:04:09 UTC (rev 1570) @@ -19,6 +19,7 @@ cache_fetch.c \ cache_hash.c \ cache_http.c \ + cache_lru.c \ cache_main.c \ cache_pool.c \ cache_pipe.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-25 16:25:29 UTC (rev 1569) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-25 17:04:09 UTC (rev 1570) @@ -254,6 +254,9 @@ TAILQ_HEAD(, storage) store; TAILQ_HEAD(, sess) waitinglist; + + time_t lru_stamp; + TAILQ_ENTRY(object) lru; }; struct objhead { @@ -372,6 +375,7 @@ void EXP_Insert(struct object *o); void EXP_Init(void); void EXP_TTLchange(struct object *o); +void EXP_Retire(struct object *o); /* cache_fetch.c */ int Fetch(struct sess *sp); @@ -473,6 +477,12 @@ void VCL_Rel(struct VCL_conf **vcc); void VCL_Get(struct VCL_conf **vcc); +/* cache_lru.c */ +void LRU_Enter(struct object *o, time_t stamp); +void LRU_Remove(struct object *o); +void LRU_DiscardSpace(struct sess *sp, uint64_t quota); +void LRU_DiscardTime(struct sess *sp, time_t cutoff); + #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); #include "vcl_returns.h" Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-25 16:25:29 UTC (rev 1569) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-25 17:04:09 UTC (rev 1570) @@ -74,6 +74,15 @@ UNLOCK(&exp_mtx); } +void +EXP_Retire(struct object *o) +{ + LOCK(&exp_mtx); + TAILQ_INSERT_TAIL(&exp_deathrow, o, deathrow); + VSL_stats->n_deathrow++; + UNLOCK(&exp_mtx); +} + /*-------------------------------------------------------------------- * This thread monitors deathrow and kills objects when they time out. */ @@ -174,10 +183,7 @@ VCL_timeout_method(sp); if (sp->handling == VCL_RET_DISCARD) { - LOCK(&exp_mtx); - TAILQ_INSERT_TAIL(&exp_deathrow, o, deathrow); - VSL_stats->n_deathrow++; - UNLOCK(&exp_mtx); + EXP_Retire(o); continue; } assert(sp->handling == VCL_RET_DISCARD); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 16:25:29 UTC (rev 1569) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-25 17:04:09 UTC (rev 1570) @@ -166,6 +166,7 @@ if (o != NULL) { UNLOCK(&oh->mtx); (void)hash->deref(oh); + LRU_Enter(o, sp->t_req.tv_sec); return (o); } @@ -177,6 +178,7 @@ /* NB: do not deref objhead the new object inherits our reference */ UNLOCK(&oh->mtx); BAN_NewObj(o); + LRU_Enter(o, sp->t_req.tv_sec); return (o); } @@ -258,6 +260,7 @@ free(o->vary); HSH_Freestore(o); + LRU_Remove(o); FREE_OBJ(o); VSL_stats->n_object--; Added: trunk/varnish-cache/bin/varnishd/cache_lru.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_lru.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-06-25 17:04:09 UTC (rev 1570) @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 2007 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Sm?rgav + * + * 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. + * + * $Id$ + */ + +#include "shmlog.h" +#include "cache.h" +#include "queue.h" + +/* + * For performance reasons, objects are only moved to the head of the LRU + * list when they've been in their current position for at least LRU_DELAY + * seconds, rather than on every access. This should probably be a + * run-time parameter. + */ +#define LRU_DELAY 2 + +static pthread_mutex_t lru_mtx = PTHREAD_MUTEX_INITIALIZER; +static TAILQ_HEAD(lru_head, object) lru_list; + +/* + * Enter an object into the LRU list, or move it to the head of the list + * if it's already in it and hasn't moved in a while. + */ +void +LRU_Enter(struct object *o, time_t stamp) +{ + + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + assert(stamp > 0); + if (o->lru_stamp < stamp - LRU_DELAY && o != lru_list.tqh_first) { + // VSL(SLT_LRU_enter, 0, "%u %u %u", o->xid, o->lru_stamp, stamp); + pthread_mutex_lock(&lru_mtx); + if (o->lru_stamp != 0) + TAILQ_REMOVE(&lru_list, o, lru); + TAILQ_INSERT_HEAD(&lru_list, o, lru); + o->lru_stamp = stamp; + pthread_mutex_unlock(&lru_mtx); + } +} + +/* + * Remove an object from the LRU list. + */ +void +LRU_Remove(struct object *o) +{ + + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + if (o->lru_stamp != 0) { + // VSL(SLT_LRU_remove, 0, "%u", o->xid); + pthread_mutex_lock(&lru_mtx); + TAILQ_REMOVE(&lru_list, o, lru); + pthread_mutex_unlock(&lru_mtx); + } +} + +/* + * Walk through the LRU list, starting at the back, and retire objects + * until our quota is reached or we run out of objects to retire. + */ +void +LRU_DiscardSpace(struct sess *sp, uint64_t quota) +{ + struct object *o, *so; + + pthread_mutex_lock(&lru_mtx); + while ((o = TAILQ_LAST(&lru_list, lru_head))) { + TAILQ_REMOVE(&lru_list, o, lru); + so = sp->obj; + sp->obj = o; + VCL_discard_method(sp); + sp->obj = so; + if (sp->handling == VCL_RET_DISCARD) { + /* discard: place on deathrow */ + EXP_Retire(o); + o->lru_stamp = 0; + if (o->len > quota) + break; + quota -= o->len; + } else { + /* keep: move to front of list */ + if ((so = TAILQ_FIRST(&lru_list))) + o->lru_stamp = so->lru_stamp; + TAILQ_INSERT_HEAD(&lru_list, o, lru); + } + } + pthread_mutex_unlock(&lru_mtx); +} + +/* + * Walk through the LRU list, starting at the back, and retire objects + * that haven't been accessed since the specified cutoff date. + */ +void +LRU_DiscardTime(struct sess *sp, time_t cutoff) +{ + struct object *o, *so; + + pthread_mutex_lock(&lru_mtx); + while ((o = TAILQ_LAST(&lru_list, lru_head))) { + if (o->lru_stamp >= cutoff) + break; + TAILQ_REMOVE(&lru_list, o, lru); + so = sp->obj; + sp->obj = o; + VCL_discard_method(sp); + sp->obj = so; + if (sp->handling == VCL_RET_DISCARD) { + /* discard: place on deathrow */ + EXP_Retire(o); + } else { + /* keep: move to front of list */ + if ((so = TAILQ_FIRST(&lru_list)) && so->lru_stamp > cutoff) + o->lru_stamp = so->lru_stamp; + else + o->lru_stamp = cutoff; + TAILQ_INSERT_HEAD(&lru_list, o, lru); + } + } + pthread_mutex_unlock(&lru_mtx); +} Property changes on: trunk/varnish-cache/bin/varnishd/cache_lru.c ___________________________________________________________________ Name: svn:keywords + Id From phk at projects.linpro.no Mon Jun 25 20:44:06 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 22:44:06 +0200 (CEST) Subject: r1571 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070625204406.C8FF51EC030@projects.linpro.no> Author: phk Date: 2007-06-25 22:44:06 +0200 (Mon, 25 Jun 2007) New Revision: 1571 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/libvcl.h trunk/varnish-cache/lib/libvcl/vcc_compile.c Log: Make it possible to pass a filedescriptor to VCC_CompileFile() if the file is already open. The filedescriptor will be closed. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 17:04:09 UTC (rev 1570) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 20:44:06 UTC (rev 1571) @@ -258,7 +258,7 @@ { char *csrc, *vf = NULL; - csrc = VCC_CompileFile(sb, fn); + csrc = VCC_CompileFile(sb, fn, -1); if (csrc != NULL) { if (C_flag) fputs(csrc, stdout); Modified: trunk/varnish-cache/include/libvcl.h =================================================================== --- trunk/varnish-cache/include/libvcl.h 2007-06-25 17:04:09 UTC (rev 1570) +++ trunk/varnish-cache/include/libvcl.h 2007-06-25 20:44:06 UTC (rev 1571) @@ -30,7 +30,7 @@ */ char *VCC_Compile(struct vsb *sb, const char *b, const char *e); -char *VCC_CompileFile(struct vsb *sb, const char *fn); +char *VCC_CompileFile(struct vsb *sb, const char *fn, int fd); void VCC_InitCompile(const char *default_vcl); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 17:04:09 UTC (rev 1570) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 20:44:06 UTC (rev 1571) @@ -377,17 +377,19 @@ /*--------------------------------------------------------------------*/ static struct source * -vcc_file_source(struct vsb *sb, const char *fn) +vcc_file_source(struct vsb *sb, const char *fn, int fd) { char *f; - int fd, i; + int i; struct stat st; - fd = open(fn, O_RDONLY); if (fd < 0) { - vsb_printf(sb, "Cannot open file '%s': %s\n", - fn, strerror(errno)); - return (NULL); + fd = open(fn, O_RDONLY); + if (fd < 0) { + vsb_printf(sb, "Cannot open file '%s': %s\n", + fn, strerror(errno)); + return (NULL); + } } assert(0 == fstat(fd, &st)); f = malloc(st.st_size + 1); @@ -429,7 +431,7 @@ } assert(t2 != NULL); - sp = vcc_file_source(tl->sb, t1->dec); + sp = vcc_file_source(tl->sb, t1->dec, -1); if (sp == NULL) { vcc_ErrWhere(tl, t1); return; @@ -653,12 +655,12 @@ */ char * -VCC_CompileFile(struct vsb *sb, const char *fn) +VCC_CompileFile(struct vsb *sb, const char *fn, int fd) { struct source *sp; char *r; - sp = vcc_file_source(sb, fn); + sp = vcc_file_source(sb, fn, fd); if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp); From phk at projects.linpro.no Mon Jun 25 21:12:18 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 23:12:18 +0200 (CEST) Subject: r1572 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625211218.32A391EC520@projects.linpro.no> Author: phk Date: 2007-06-25 23:12:17 +0200 (Mon, 25 Jun 2007) New Revision: 1572 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Redo the -n argument code, it had too many problems: We need to process -P and -f arguments before we change directory. (ticket 120) (XXX: what about storage and hash arguments ??) The daemon(3) call should not change our directory subsequently. (ticket 121) There is no need to enforce a hostname style format on the argument, a directory nam makes much more sense, since that is what we need. Defaulting to /tmp instead of our hostname makes more sense (ticket 119). This also allows the admin to use a different directory if /tmp is mounted noexec (ticket 111) Put the directoryname used in the proctitle (via heritage) XXX: for docs: vcl.load CLI commands will work relative to the -n directory. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-25 21:12:17 UTC (rev 1572) @@ -62,6 +62,8 @@ /* Hash method */ struct hash_slinger *hash; + + const char *n_arg; }; struct params { Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2007-06-25 21:12:17 UTC (rev 1572) @@ -58,7 +58,7 @@ /* mgt_vcc.c */ void mgt_vcc_init(void); -int mgt_vcc_default(const char *bflag, const char *fflag, int Cflag); +int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); #include "stevedore.h" Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-25 21:12:17 UTC (rev 1572) @@ -204,7 +204,7 @@ AZ(close(heritage.fds[0])); AZ(close(heritage.fds[3])); - setproctitle("Varnish-Chld"); + setproctitle("Varnish-Chld %s", heritage.n_arg); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); @@ -408,7 +408,7 @@ e->name = "mgt_sigchild"; AZ(ev_add(mgt_evb, e)); - setproctitle("Varnish-Mgr"); + setproctitle("Varnish-Mgr %s", heritage.n_arg); sac.sa_handler = SIG_IGN; sac.sa_flags = SA_RESTART; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-25 21:12:17 UTC (rev 1572) @@ -499,72 +499,6 @@ /*--------------------------------------------------------------------*/ -#define NAME_RE "^([0-9A-Za-z-]+)(\\.[0-9A-Za-z-]+)*$" -static regex_t *name_re; - -static void -tweak_name(struct cli *cli, struct parspec *par, const char *arg) -{ - char hostname[1024], path[1024]; - int error; - - (void)par; - - if (arg == NULL) { - cli_out(cli, "\"%s\"", master.name); - return; - } - - /* empty string -> hostname */ - if (*arg == '\0') { - if (gethostname(hostname, sizeof hostname) == 0) - arg = hostname; - else - arg = "localhost"; - } - - /* check that the new name follows hostname convention */ - if (name_re == NULL) { - name_re = malloc(sizeof *name_re); - AN(name_re); - AZ(regcomp(name_re, NAME_RE, REG_EXTENDED|REG_NOSUB)); - } - if (regexec(name_re, arg, 0, NULL, 0) != 0) { - cli_out(cli, "Invalid instance name"); - cli_result(cli, CLIS_PARAM); - return; - } - - error = 0; - snprintf(path, sizeof path, "/tmp/%s", arg); /* XXX overflow */ - if (master.name && *master.name) { - struct stat old_st; - char old_path[1024]; - - /* rename old directory */ - snprintf(old_path, sizeof old_path, "/tmp/%s", master.name); /* XXX overflow */ - if (stat(old_path, &old_st) == 0 && S_ISDIR(old_st.st_mode)) { - error = rename(old_path, path); - } else { - error = (mkdir(path, 0755) != 0 && errno != EEXIST); - } - } else { - error = (mkdir(path, 0755) != 0 && errno != EEXIST); - } - - if (error || chdir(path) != 0) { - cli_out(cli, "could not create %s: %s", path, strerror(errno)); - cli_result(cli, CLIS_CANT); - return; - } - - /* Everything is fine, store the (new) name */ - master.name = strdup(arg); - XXXAN(master.name); -} - -/*--------------------------------------------------------------------*/ - /* * Make sure to end all lines with either a space or newline of the * formatting will go haywire. @@ -738,12 +672,6 @@ "it possible to attach a debugger to the child.\n" MUST_RESTART, "3", "seconds" }, - { "name", tweak_name, - "Name of varnishd instance. Must follow hostname " - "naming conventions. Makes it possible to run " - "multiple varnishd instances on one server.\n" - EXPERIMENTAL, - "" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-06-25 21:12:17 UTC (rev 1572) @@ -254,11 +254,11 @@ } static char * -mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag) +mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag, int fd) { char *csrc, *vf = NULL; - csrc = VCC_CompileFile(sb, fn, -1); + csrc = VCC_CompileFile(sb, fn, fd); if (csrc != NULL) { if (C_flag) fputs(csrc, stdout); @@ -314,7 +314,7 @@ /*--------------------------------------------------------------------*/ int -mgt_vcc_default(const char *b_arg, const char *f_arg, int C_flag) +mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag) { char *addr, *port; char *buf, *vf; @@ -349,7 +349,7 @@ vf = mgt_VccCompile(sb, buf, NULL, C_flag); free(buf); } else { - vf = mgt_VccCompileFile(sb, f_arg, C_flag); + vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd); } vsb_finish(sb); if (vsb_len(sb) > 0) { @@ -461,7 +461,7 @@ sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); XXXAN(sb); - vf = mgt_VccCompileFile(sb, av[3], 0); + vf = mgt_VccCompileFile(sb, av[3], 0, -1); vsb_finish(sb); if (vsb_len(sb) > 0) { cli_out(cli, "%s", vsb_data(sb)); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 20:44:06 UTC (rev 1571) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-25 21:12:17 UTC (rev 1572) @@ -44,6 +44,7 @@ #include #include #include +#include #ifndef HAVE_DAEMON #include "compat/daemon.h" @@ -178,7 +179,8 @@ " -h classic [default]"); fprintf(stderr, " %-28s # %s\n", "", " -h classic,"); - fprintf(stderr, " %-28s # %s\n", "-n name", "varnishd instance name"); + fprintf(stderr, " %-28s # %s\n", "-n dir", + "varnishd working directory"); fprintf(stderr, " %-28s # %s\n", "-P file", "PID file"); fprintf(stderr, " %-28s # %s\n", "-p param=value", "set parameter"); @@ -405,7 +407,9 @@ unsigned F_flag = 0; const char *b_arg = NULL; const char *f_arg = NULL; + int f_fd = -1; const char *h_arg = "classic"; + const char *n_arg = "/tmp"; const char *P_arg = NULL; const char *s_arg = "file"; const char *T_arg = NULL; @@ -455,7 +459,7 @@ h_arg = optarg; break; case 'n': - MCF_ParamSet(cli, "name", optarg); + n_arg = optarg; break; case 'P': P_arg = optarg; @@ -499,6 +503,7 @@ usage(); } + /* XXX: we can have multiple CLI actions above, is this enough ? */ if (cli[0].result != CLIS_OK) { fprintf(stderr, "Parameter errors:\n"); vsb_finish(cli[0].sb); @@ -519,14 +524,39 @@ fprintf(stderr, "One of -b or -f must be specified\n"); usage(); } + + if (f_arg != NULL) { + f_fd = open(f_arg, O_RDONLY); + if (f_fd < 0) { + fprintf(stderr, "Cannot open '%s': %s\n", + f_arg, strerror(errno)); + exit(1); + } + } + if (mkdir(n_arg, 0755) < 0 && errno != EEXIST) { + fprintf(stderr, "Cannot create working directory '%s': %s\n", + n_arg, strerror(errno)); + exit(1); + } + + if (chdir(n_arg) < 0) { + fprintf(stderr, "Cannot change to working directory '%s': %s\n", + n_arg, strerror(errno)); + exit(1); + } + + heritage.n_arg = n_arg; + + /* XXX: should this be relative to the -n arg ? */ 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)) + if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag)) exit (2); + if (C_flag) exit (0); @@ -538,7 +568,7 @@ if (d_flag == 1) DebugStunt(); if (d_flag < 2 && !F_flag) - daemon(d_flag, d_flag); + daemon(1, d_flag); if (d_flag == 1) printf("%d\n", getpid()); From phk at projects.linpro.no Mon Jun 25 21:24:28 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 25 Jun 2007 23:24:28 +0200 (CEST) Subject: r1573 - trunk/varnish-cache/bin/varnishd Message-ID: <20070625212428.3FA321EC294@projects.linpro.no> Author: phk Date: 2007-06-25 23:24:27 +0200 (Mon, 25 Jun 2007) New Revision: 1573 Modified: trunk/varnish-cache/bin/varnishd/heritage.h Log: remove "name" from the parameters, it isn't one. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-25 21:12:17 UTC (rev 1572) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-25 21:24:27 UTC (rev 1573) @@ -122,8 +122,6 @@ /* Ping interval */ unsigned ping_interval; - /* Varnishd name */ - char *name; }; extern volatile struct params *params; From cecilihf at projects.linpro.no Tue Jun 26 06:56:03 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Tue, 26 Jun 2007 08:56:03 +0200 (CEST) Subject: r1574 - in trunk/varnish-cache: . bin bin/varnishreplay Message-ID: <20070626065603.8393B1EC030@projects.linpro.no> Author: cecilihf Date: 2007-06-26 08:56:03 +0200 (Tue, 26 Jun 2007) New Revision: 1574 Added: trunk/varnish-cache/bin/varnishreplay/ trunk/varnish-cache/bin/varnishreplay/Makefile.am trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Modified: trunk/varnish-cache/bin/Makefile.am trunk/varnish-cache/configure.ac Log: Traffic replay tool. Parses varnish logs and attempts to recreate the traffic Modified: trunk/varnish-cache/bin/Makefile.am =================================================================== --- trunk/varnish-cache/bin/Makefile.am 2007-06-25 21:24:27 UTC (rev 1573) +++ trunk/varnish-cache/bin/Makefile.am 2007-06-26 06:56:03 UTC (rev 1574) @@ -1,3 +1,3 @@ # $Id$ -SUBDIRS = varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop +SUBDIRS = varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop varnishreplay Added: trunk/varnish-cache/bin/varnishreplay/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishreplay/Makefile.am (rev 0) +++ trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-06-26 06:56:03 UTC (rev 1574) @@ -0,0 +1,17 @@ +# $Id: Makefile.am 1507 2007-06-10 11:46:05Z des $ + +INCLUDES = -I$(top_srcdir)/include + +bin_PROGRAMS = varnishreplay + +dist_man_MANS = varnishreplay.1 + +varnishreplay_SOURCES = \ + varnishreplay.c + +varnishreplay_CFLAGS = -include config.h + +varnishreplay_LDADD = \ + $(top_builddir)/lib/libvarnish/libvarnish.la \ + $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Added: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 (rev 0) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 2007-06-26 06:56:03 UTC (rev 1574) @@ -0,0 +1,68 @@ +.\"- +.\" Copyright (c) 2006 Verdens Gang AS +.\" Copyright (c) 2006-2007 Linpro AS +.\" All rights reserved. +.\" +.\" Author: Cecilie Fritzvold +.\" +.\" 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. +.\" +.\" $Id$ +.\" +.Dd June 25, 2007 +.Dt VARNISHREPLAY 1 +.Os +.Sh NAME +.Nm varnishreplay +.Sh SYNOPSIS +.Nm +.Fl a Ar address:port +.Fl r Ar file +.Op Fl D +.Sh DESCRIPTION +The +.Nm +utility parses varnish logs and attempts to reproduce the traffic. +.Pp +The following options are available: +.Bl -tag -width Fl +.It Fl a Ar address:port +Send the traffic over tcp to this address and port. +This option is mandatory. +.It Fl r Ar file +Parse logs from this file. This option is mandatory. +.It Fl D +Turn on debugging mode. +.Sh SEE ALSO +.Xr varnishd 1 , +.Xr varnishhist 1 , +.Xr varnishncsa 1 , +.Xr varnishstat 1 , +.Xr varnishtop 1 +.Sh HISTORY +The +.Nm +utility was developed by +.An Cecilie Fritzvold Aq cecilihf at linpro.no . + +This manual page was written by +.An Cecilie Fritzvold Aq cecilihf at linpro.no . Added: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c (rev 0) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-26 06:56:03 UTC (rev 1574) @@ -0,0 +1,555 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Cecilie Fritzvold + * + * 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. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "libvarnish.h" +#include "varnishapi.h" +#include "vss.h" + +static struct request { + char *df_H; /* %H, Protocol version */ + char *df_Host; /* %{Host}i */ + char *df_Uq; /* %U%q, URL path and query string */ + char *df_m; /* %m, Request method*/ + char *df_c; /* Connection info (keep-alive, close) */ + int bogus; /* bogus request */ +} **req; + +static size_t nreq; + +static struct vss_addr *adr_info; +static int sock; +static int reopen; +static int debug; + +static int +isprefix(const char *str, const char *prefix, const char *end, const char **next) +{ + + while (str < end && *str && *prefix && + tolower((int)*str) == tolower((int)*prefix)) + ++str, ++prefix; + if (*str && *str != ' ') + return (0); + if (next) { + while (str < end && *str && *str == ' ') + ++str; + *next = str; + } + return (1); +} + +static int +isequal(const char *str, const char *reference, const char *end) +{ + + while (str < end && *str && *reference && + tolower((int)*str) == tolower((int)*reference)) + ++str, ++reference; + if (str != end || *reference) + return (0); + return (1); +} + +/* + * Returns a copy of the entire string with leading and trailing spaces + * trimmed. + */ +static char * +trimline(const char *str, const char *end) +{ + size_t len; + char *p; + + /* skip leading space */ + while (str < end && *str && *str == ' ') + ++str; + + /* seek to end of string */ + for (len = 0; &str[len] < end && str[len]; ++len) + /* nothing */ ; + + /* trim trailing space */ + while (len && str[len - 1] == ' ') + --len; + + /* copy and return */ + p = malloc(len + 1); + assert(p != NULL); + memcpy(p, str, len); + p[len] = '\0'; + return (p); +} + +/* Initiate a connection to
by resolving the + * hostname and returning a struct with necessary + * connection info. + */ +static struct vss_addr* +init_connection(const char* address) +{ + struct vss_addr **ta; + struct vss_addr *tap; + char *addr, *port; + int i, n; + + XXXAZ(VSS_parse(address, &addr, &port)); + XXXAN(n = VSS_resolve(addr, port, &ta)); + free(addr); + free(port); + if (n == 0) { + fprintf(stderr, "Could not open TELNET port\n"); + exit(2); + } + for (i = 1; i < n; ++i) { + free(ta[i]); + ta[i] = NULL; + } + tap = ta[0]; + free(ta); + + return tap; +} + +/* Read a line from the socket and return the number of bytes read. + * After returning, line will point to the read bytes in memory. + * A line is terminated by \r\n + */ +static int +read_line(char **line) +{ + char *buf; + unsigned nbuf, lbuf; + int i; + + lbuf = 4096; + buf = malloc(lbuf); + XXXAN(buf); + nbuf = 0; + while (1) { + if ((nbuf + 2) >= lbuf) { + lbuf += lbuf; + buf = realloc(buf, lbuf); + XXXAN(buf); + } + //fprintf(stderr, "start reading\n"); + i = read(sock, buf + nbuf, 1); + if (i <= 0) { + perror("error in reading\n"); + free(buf); + exit(1); + } + nbuf += i; + if (buf[nbuf-2] == '\r' && buf[nbuf-1] == '\n') + break; + + } + buf[nbuf] = '\0'; + *line = buf; + return nbuf+1; +} + +/* Read a block of data from the socket, and do nothing with it. + * length says how many bytes to read, and the function returns + * the number of bytes read. + */ +static int +read_block(int length) +{ + char *buf; + int n, nbuf; + + buf = malloc(length); + nbuf = 0; + while (nbuf < length) { + n = read(sock, buf + nbuf, + (2048 < length - nbuf ? 2048 : length - nbuf)); + if (n <= 0) { + perror("failed reading the block\n"); + break; + } + nbuf += n; + } + free(buf); + return nbuf; +} + +/* Receive the response after sending a request. + */ +static int +receive_response(void) +{ + char *line, *end; + const char *next; + int line_len; + long content_length = -1; + int chunked = 0; + int close_connection = 0; + int req_failed = 1; + int n; + long block_len; + int status; + + /* Read header */ + while (1) { + line_len = read_line(&line); + end = line + line_len; + + if (*line == '\r' && *(line + 1) == '\n') { + free(line); + break; + } + + if (strncmp(line, "HTTP", 4) == 0) { + sscanf(line, "%*s %d %*s\r\n", &status); + req_failed = (status != 200); + } else if (isprefix(line, "content-length:", end, &next)) + content_length = strtol(next, &end, 10); + else if (isprefix(line, "encoding:", end, &next) || + isprefix(line, "transfer-encoding:", end, &next)) + chunked = (strstr(next, "chunked") != NULL); + else if (isprefix(line, "connection:", end, &next)) + close_connection = (strstr(next, "close") != NULL); + + free(line); + } + + if (debug) + fprintf(stderr, "status: %d\n", status); + + + /* Read body */ + if (content_length > 0 && !chunked) { + /* Fixed body size, read content_length bytes */ + if (debug) + fprintf(stderr, "fixed length\n"); + n = read_block(content_length); + if (debug) { + fprintf(stderr, "size of body: %d\n", (int)content_length); + fprintf(stderr, "bytes read: %d\n", n); + } + } else if (chunked) { + /* Chunked encoding, read size and bytes until no more */ + if (debug) + fprintf(stderr, "chunked encoding\n"); + while (1) { + line_len = read_line(&line); + end = line + line_len; + block_len = strtol(line, &end, 16); + if (block_len == 0) { + break; + } + n = read_block(block_len); + if (debug) { + fprintf(stderr, "size of body: %d\n", (int)block_len); + fprintf(stderr, "bytes read: %d\n", n); + } + free(line); + n = read_line(&line); + free(line); + } + n = read_line(&line); + free(line); + } else if ((content_length <= 0 && !chunked) || req_failed) { + /* No body --> stop reading. */ + if (debug) + fprintf(stderr, "no body\n"); + } else { + /* Unhandled case. */ + fprintf(stderr, "An error occured\n"); + exit(1); + } + if (debug) + fprintf(stderr, "\n"); + + return close_connection; +} + + +static int +gen_traffic(void *priv, enum shmlogtag tag, unsigned fd, + unsigned len, unsigned spec, const char *ptr) +{ + const char *end, *next; + FILE *fo; + struct request *rp; + + end = ptr + len; + + if (!(spec & VSL_S_CLIENT)) + return (0); + + if (fd >= nreq) { + struct request **newreq = req; + size_t newnreq = nreq; + + while (fd >= newnreq) + newnreq += newnreq + 1; + newreq = realloc(newreq, newnreq * sizeof *newreq); + assert(newreq != NULL); + memset(newreq + nreq, 0, (newnreq - nreq) * sizeof *newreq); + req = newreq; + nreq = newnreq; + } + if (req[fd] == NULL) { + req[fd] = calloc(sizeof *req[fd], 1); + assert(req[fd] != NULL); + } + rp = req[fd]; + + switch (tag) { + case SLT_RxRequest: + if (tag == SLT_RxRequest && (spec & VSL_S_BACKEND)) + break; + + if (rp->df_m != NULL) + rp->bogus = 1; + else + rp->df_m = trimline(ptr, end); + break; + + case SLT_RxURL: + if (tag == SLT_RxURL && (spec & VSL_S_BACKEND)) + break; + + if (rp->df_Uq != NULL) + rp->bogus = 1; + else + rp->df_Uq = trimline(ptr, end); + break; + + case SLT_RxProtocol: + if (tag == SLT_RxProtocol && (spec & VSL_S_BACKEND)) + break; + + if (rp->df_H != NULL) + rp->bogus = 1; + else + rp->df_H = trimline(ptr, end); + break; + + case SLT_RxHeader: + if (isprefix(ptr, "host:", end, &next)) + rp->df_Host = trimline(next, end); + if (isprefix(ptr, "connection:", end, &next)) + rp->df_c = trimline(next, end); + break; + + default: + break; + } + + if ((spec & VSL_S_CLIENT) && tag != SLT_ReqEnd) + return (0); + + if (!rp->bogus) { + fo = priv; + + /* If the method is supported (GET or HEAD), send the request out + * on the socket. If the socket needs reopening, reopen it first. + * When the request is sent, call the function for receiving + * the answer. + */ + if (!(strncmp(rp->df_m, "GET", 3) && strncmp(rp->df_m, "HEAD", 4))) { + if (reopen) + sock = VSS_connect(adr_info); + reopen = 0; + + if (debug) { + fprintf(fo, "%s ", rp->df_m); + fprintf(fo, "%s ", rp->df_Uq); + fprintf(fo, "%s ", rp->df_H); + fprintf(fo, "\n"); + fprintf(fo, "Host: "); + } + write(sock, rp->df_m, strlen(rp->df_m)); + write(sock, " ", 1); + write(sock, rp->df_Uq, strlen(rp->df_Uq)); + write(sock, " ", 1); + write(sock, rp->df_H, strlen(rp->df_H)); + write(sock, " ", 1); + write(sock, "\r\n", 2); + + if (strncmp(rp->df_H, "HTTP/1.0", 8)) + reopen = 1; + + write(sock, "Host: ", 6); + if (rp->df_Host) { + if (debug) + fprintf(fo, rp->df_Host); + write(sock, rp->df_Host, strlen(rp->df_Host)); + } + if (debug) + fprintf(fo, "\n"); + write(sock, "\r\n", 2); + if (rp->df_c) { + if (debug) + fprintf(fo, "Connection: %s\n", rp->df_c); + write(sock, "Connection: ", 12); + write(sock, rp->df_c, strlen(rp->df_c)); + write(sock, "\r\n", 2); + if (isequal(rp->df_c, "keep-alive", rp->df_c + strlen(rp->df_c))) + reopen = 0; + } + if (debug) + fprintf(fo, "\n"); + write(sock, "\r\n", 2); + if (!reopen) + reopen = receive_response(); + if (reopen) + close(sock); + } + } + + /* clean up */ +#define freez(x) do { if (x) free(x); x = NULL; } while (0); + freez(rp->df_H); + freez(rp->df_Host); + freez(rp->df_Uq); + freez(rp->df_m); + freez(rp->df_c); +#undef freez + rp->bogus = 0; + + return (0); +} + +/* This function is for testing only, and only sends + * the raw data from the file to the address. + * The receive function is called for each blank line. + */ +static void +send_test_request(char *file, const char *address) +{ + int fd = open(file, O_RDONLY); + char buf[2]; + char last = ' '; + adr_info = init_connection(address); + sock = VSS_connect(adr_info); + while (read(fd, buf, 1)) { + write(sock, buf, 1); + fprintf(stderr, "%s", buf); + if (*buf == '\n' && last == '\n'){ + fprintf(stderr, "receive\n"); + reopen = receive_response(); + } + last = *buf; + } + close(sock); + +} + +/*--------------------------------------------------------------------*/ + +static void +usage(void) +{ + + fprintf(stderr, "usage: varnishreplay -a address:port -r logfile [-D]\n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + int i, c; + struct VSL_data *vd; + const char *ofn = NULL; + const char *address = NULL; + FILE *of; + + char *test_file = NULL; + + vd = VSL_New(); + debug = 0; + + while ((c = getopt(argc, argv, "a:Dr:t:")) != -1) { + i = VSL_Arg(vd, c, optarg); + if (i < 0) + exit (1); + if (i > 0) + continue; + switch (c) { + case 'a': + address = optarg; + break; + case 'D': + debug = 1; + break; + case 't': + /* This option is for testing only. The test file must contain + * a sequence of valid HTTP-requests that can be sent + * unchanged to the adress given with -a + */ + test_file = optarg; + break; + default: + if (VSL_Arg(vd, c, optarg) > 0) + break; + usage(); + } + } + + if (test_file != NULL) { + send_test_request(test_file, address); + exit(0); + } + + if (address == NULL) { + usage(); + } + + if (VSL_OpenLog(vd, NULL)) + exit(1); + + ofn = "stdout"; + of = stdout; + + adr_info = init_connection(address); + reopen = 1; + + while (VSL_Dispatch(vd, gen_traffic, of) == 0) { + if (fflush(of) != 0) { + perror(ofn); + exit(1); + } + } + + exit(0); +} + Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-25 21:24:27 UTC (rev 1573) +++ trunk/varnish-cache/configure.ac 2007-06-26 06:56:03 UTC (rev 1574) @@ -138,6 +138,7 @@ bin/varnishncsa/Makefile bin/varnishstat/Makefile bin/varnishtop/Makefile + bin/varnishreplay/Makefile doc/Makefile etc/Makefile include/Makefile From phk at projects.linpro.no Tue Jun 26 09:37:18 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 26 Jun 2007 11:37:18 +0200 (CEST) Subject: r1575 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish Message-ID: <20070626093718.99EF91EC40F@projects.linpro.no> Author: phk Date: 2007-06-26 11:37:18 +0200 (Tue, 26 Jun 2007) New Revision: 1575 Modified: trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/crc32.c Log: Retire the crc32_2s() function. Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-26 06:56:03 UTC (rev 1574) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-06-26 09:37:18 UTC (rev 1575) @@ -127,7 +127,7 @@ return; } AZ(sp->srcaddr); - u = crc32_2s(sp->addr, ""); + u = crc32_l(sp->addr, strlen(sp->addr)); v = u % nsrchash; ch = &srchash[v]; CHECK_OBJ(ch, SRCADDRHEAD_MAGIC); Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2007-06-26 06:56:03 UTC (rev 1574) +++ trunk/varnish-cache/include/libvarnish.h 2007-06-26 09:37:18 UTC (rev 1575) @@ -42,7 +42,6 @@ char **ParseArgv(const char *s, int comment); /* from libvarnish/crc32.c */ -uint32_t crc32_2s(const char *p1, const char *p2); uint32_t crc32_l(const void *p1, unsigned l); /* from libvarnish/time.c */ Modified: trunk/varnish-cache/lib/libvarnish/crc32.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/crc32.c 2007-06-26 06:56:03 UTC (rev 1574) +++ trunk/varnish-cache/lib/libvarnish/crc32.c 2007-06-26 09:37:18 UTC (rev 1575) @@ -82,22 +82,6 @@ }; uint32_t -crc32_2s(const char *p1, const char *p2) -{ - const unsigned char *p; - uint32_t crc; - - crc = ~0U; - - for (p = (const unsigned char*)p1; *p != '\0'; p++) - crc = (crc >> 8) ^ crc32bits[(crc ^ *p) & 0xff]; - for (p = (const unsigned char*)p2; *p != '\0'; p++) - crc = (crc >> 8) ^ crc32bits[(crc ^ *p) & 0xff]; - - return (crc ^ ~0U); -} - -uint32_t crc32_l(const void *p1, unsigned l) { const unsigned char *p; From phk at projects.linpro.no Tue Jun 26 10:01:49 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 26 Jun 2007 12:01:49 +0200 (CEST) Subject: r1576 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070626100149.750A91EC28F@projects.linpro.no> Author: phk Date: 2007-06-26 12:01:49 +0200 (Tue, 26 Jun 2007) New Revision: 1576 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Markup all VCL variables as RO, WO or RW and generate and check code accordingly. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-06-26 10:01:49 UTC (rev 1576) @@ -152,13 +152,6 @@ CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \ be->field = a; \ } \ - \ -type \ -VRT_r_backend_##onm(struct backend *be) \ -{ \ - CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \ - return (be->field); \ -} VBACKEND(const char *, host, hostname) VBACKEND(const char *, port, portname) Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/include/vrt_obj.h 2007-06-26 10:01:49 UTC (rev 1576) @@ -6,29 +6,17 @@ * Edit vcc_gen_obj.tcl instead */ -const char * VRT_r_backend_host(struct backend *); void VRT_l_backend_host(struct backend *, const char *); -const char * VRT_r_backend_port(struct backend *); void VRT_l_backend_port(struct backend *, const char *); -double VRT_r_backend_dnsttl(struct backend *); void VRT_l_backend_dnsttl(struct backend *, double); struct sockaddr * VRT_r_client_ip(struct sess *); -void VRT_l_client_ip(struct sess *, struct sockaddr *); struct sockaddr * VRT_r_server_ip(struct sess *); -void VRT_l_server_ip(struct sess *, struct sockaddr *); const char * VRT_r_req_request(struct sess *); -void VRT_l_req_request(struct sess *, const char *); -const char * VRT_r_req_host(struct sess *); -void VRT_l_req_host(struct sess *, const char *); const char * VRT_r_req_url(struct sess *); -void VRT_l_req_url(struct sess *, const char *); const char * VRT_r_req_proto(struct sess *); -void VRT_l_req_proto(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); const char * VRT_r_req_http_(struct sess *); -void VRT_l_req_http_(struct sess *, const char *); -const char * VRT_r_req_hash(struct sess *); void VRT_l_req_hash(struct sess *, const char *); unsigned VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, unsigned); @@ -37,10 +25,6 @@ double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_resp_proto(struct sess *); -void VRT_l_resp_proto(struct sess *, const char *); int VRT_r_resp_status(struct sess *); -void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); -void VRT_l_resp_response(struct sess *, const char *); const char * VRT_r_resp_http_(struct sess *); -void VRT_l_resp_http_(struct sess *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-26 10:01:49 UTC (rev 1576) @@ -105,6 +105,12 @@ vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); + if (vp->access != V_RW && vp->access != V_WO) { + vsb_printf(tl->sb, "Variable %.*s cannot be written.\n", + PF(vt)); + vcc_ErrWhere(tl, vt); + return; + } Fb(tl, 1, "%s", vp->lname); vcc_NextToken(tl); switch (vp->fmt) { Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-26 10:01:49 UTC (rev 1576) @@ -120,6 +120,7 @@ unsigned len; const char *rname; const char *lname; + enum {V_RO, V_RW, V_WO} access; unsigned methods; }; Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-06-26 10:01:49 UTC (rev 1576) @@ -32,30 +32,74 @@ # Objects which operate on backends set beobj { - { backend.host HOSTNAME } - { backend.port PORTNAME } - { backend.dnsttl TIME } + { backend.host WO HOSTNAME } + { backend.port WO PORTNAME } + { backend.dnsttl WO TIME } } # Objects which operate on sessions set spobj { - { client.ip IP {recv pipe pass hash miss hit fetch } } - { server.ip IP {recv pipe pass hash miss hit fetch } } - { req.request STRING {recv pipe pass hash miss hit fetch } } - { req.host STRING {recv pipe pass hash miss hit fetch } } - { req.url STRING {recv pipe pass hash miss hit fetch } } - { req.proto STRING {recv pipe pass hash miss hit fetch } } - { req.backend BACKEND {recv pipe pass hash miss hit fetch } } - { req.http. HEADER {recv pipe pass hash miss hit fetch } } - { req.hash HASH { hash } } - { obj.valid BOOL { hit fetch discard timeout} } - { obj.cacheable BOOL { hit fetch discard timeout} } - { obj.ttl TIME { hit fetch discard timeout} } - { resp.proto STRING { fetch } } - { resp.status INT { fetch } } - { resp.response STRING { fetch } } - { resp.http. HEADER { fetch } } + { client.ip + RO IP + {recv pipe pass hash miss hit fetch } + } + { server.ip + RO IP + {recv pipe pass hash miss hit fetch } + } + { req.request + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.url + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.proto + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.backend + RW BACKEND + {recv pipe pass hash miss hit fetch } + } + { req.http. + RO HEADER + {recv pipe pass hash miss hit fetch } + } + { req.hash + WO HASH + { hash } + } + { obj.valid + RW BOOL + { hit fetch discard timeout} + } + { obj.cacheable + RW BOOL + { hit fetch discard timeout} + } + { obj.ttl + RW TIME + { hit fetch discard timeout} + } + { resp.proto + RO STRING + { fetch } + } + { resp.status + RO INT + { fetch } + } + { resp.response + RO STRING + { fetch } + } + { resp.http. + RO HEADER + { fetch } + } } set tt(IP) "struct sockaddr *" @@ -105,15 +149,25 @@ foreach v $v { set n [lindex $v 0] regsub -all {[.]} $n "_" m - set t [lindex $v 1] + set a [lindex $v 1] + set t [lindex $v 2] puts $fo "\t\{ \"$n\", $t, [string length $n]," - puts $fo "\t \"VRT_r_${m}($pa)\"," - puts $fo "\t \"VRT_l_${m}($pa, \"," - puts $fo "\t [method_map [lindex $v 2]]" + if {$a == "RO" || $a == "RW"} { + puts $fo "\t \"VRT_r_${m}($pa)\"," + puts $fp "$tt($t) VRT_r_${m}($ty);" + } else { + puts $fo "\t NULL," + } + if {$a == "WO" || $a == "RW"} { + puts $fo "\t \"VRT_l_${m}($pa, \"," + puts $fp "void VRT_l_${m}($ty, $tt($t));" + } else { + puts $fo "\t NULL," + } + puts $fo "\t V_$a," + puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," - puts $fp "$tt($t) VRT_r_${m}($ty);" - puts $fp "void VRT_l_${m}($ty, $tt($t));" } puts $fo "\t{ NULL }" } Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-06-26 10:01:49 UTC (rev 1576) @@ -11,18 +11,21 @@ struct var vcc_be_vars[] = { { "backend.host", HOSTNAME, 12, - "VRT_r_backend_host(backend)", + NULL, "VRT_l_backend_host(backend, ", + V_WO, }, { "backend.port", PORTNAME, 12, - "VRT_r_backend_port(backend)", + NULL, "VRT_l_backend_port(backend, ", + V_WO, }, { "backend.dnsttl", TIME, 14, - "VRT_r_backend_dnsttl(backend)", + NULL, "VRT_l_backend_dnsttl(backend, ", + V_WO, }, { NULL } @@ -31,82 +34,92 @@ struct var vcc_vars[] = { { "client.ip", IP, 9, "VRT_r_client_ip(sp)", - "VRT_l_client_ip(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", - "VRT_l_server_ip(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", - "VRT_l_req_request(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, - { "req.host", STRING, 8, - "VRT_r_req_host(sp)", - "VRT_l_req_host(sp, ", - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH - }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", - "VRT_l_req_url(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", - "VRT_l_req_proto(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", + V_RW, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", - "VRT_l_req_http_(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, - "VRT_r_req_hash(sp)", + NULL, "VRT_l_req_hash(sp, ", + V_WO, VCL_MET_HASH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", - "VRT_l_resp_proto(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.status", INT, 11, "VRT_r_resp_status(sp)", - "VRT_l_resp_status(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.response", STRING, 13, "VRT_r_resp_response(sp)", - "VRT_l_resp_response(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", - "VRT_l_resp_http_(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { NULL } Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-26 09:37:18 UTC (rev 1575) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-26 10:01:49 UTC (rev 1576) @@ -44,7 +44,6 @@ vcc_StringVal(struct tokenlist *tl) { struct var *vp; - struct token *vt; if (tl->t->tok == CSTR) { EncToken(tl->fb, tl->t); @@ -53,7 +52,6 @@ } ExpectErr(tl, VAR); ERRCHK(tl); - vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); switch (vp->fmt) { From des at projects.linpro.no Tue Jun 26 11:36:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 13:36:37 +0200 (CEST) Subject: r1577 - in trunk/varnish-cache: . bin bin/varnishreplay Message-ID: <20070626113637.292321EC294@projects.linpro.no> Author: des Date: 2007-06-26 13:36:36 +0200 (Tue, 26 Jun 2007) New Revision: 1577 Modified: trunk/varnish-cache/bin/Makefile.am trunk/varnish-cache/bin/varnishreplay/Makefile.am trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/configure.ac Log: Reorder, expand tags Modified: trunk/varnish-cache/bin/Makefile.am =================================================================== --- trunk/varnish-cache/bin/Makefile.am 2007-06-26 10:01:49 UTC (rev 1576) +++ trunk/varnish-cache/bin/Makefile.am 2007-06-26 11:36:36 UTC (rev 1577) @@ -1,3 +1,4 @@ # $Id$ -SUBDIRS = varnishadm varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop varnishreplay +SUBDIRS = varnishadm varnishd varnishhist varnishlog varnishncsa \ + varnishreplay varnishstat varnishtop Modified: trunk/varnish-cache/bin/varnishreplay/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-06-26 10:01:49 UTC (rev 1576) +++ trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-06-26 11:36:36 UTC (rev 1577) @@ -1,4 +1,4 @@ -# $Id: Makefile.am 1507 2007-06-10 11:46:05Z des $ +# $Id$ INCLUDES = -I$(top_srcdir)/include Property changes on: trunk/varnish-cache/bin/varnishreplay/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-26 10:01:49 UTC (rev 1576) +++ trunk/varnish-cache/configure.ac 2007-06-26 11:36:36 UTC (rev 1577) @@ -136,9 +136,9 @@ bin/varnishlog/Makefile bin/varnishhist/Makefile bin/varnishncsa/Makefile + bin/varnishreplay/Makefile bin/varnishstat/Makefile bin/varnishtop/Makefile - bin/varnishreplay/Makefile doc/Makefile etc/Makefile include/Makefile From des at projects.linpro.no Tue Jun 26 11:37:34 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 13:37:34 +0200 (CEST) Subject: r1578 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070626113734.BB3C61EC28F@projects.linpro.no> Author: des Date: 2007-06-26 13:37:34 +0200 (Tue, 26 Jun 2007) New Revision: 1578 Modified: trunk/varnish-cache/bin/varnishreplay/ Log: Ignore generated files Property changes on: trunk/varnish-cache/bin/varnishreplay ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile Makefile.in varnishreplay From des at projects.linpro.no Tue Jun 26 11:41:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 13:41:24 +0200 (CEST) Subject: r1579 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070626114124.1896D1EC294@projects.linpro.no> Author: des Date: 2007-06-26 13:41:23 +0200 (Tue, 26 Jun 2007) New Revision: 1579 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Correct copyright + some style nits Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 2007-06-26 11:37:34 UTC (rev 1578) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 2007-06-26 11:41:23 UTC (rev 1579) @@ -1,6 +1,5 @@ .\"- -.\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006-2007 Linpro AS +.\" Copyright (c) 2007 Linpro AS .\" All rights reserved. .\" .\" Author: Cecilie Fritzvold @@ -35,9 +34,9 @@ .Nm varnishreplay .Sh SYNOPSIS .Nm +.Op Fl D .Fl a Ar address:port .Fl r Ar file -.Op Fl D .Sh DESCRIPTION The .Nm @@ -48,21 +47,16 @@ .It Fl a Ar address:port Send the traffic over tcp to this address and port. This option is mandatory. -.It Fl r Ar file -Parse logs from this file. This option is mandatory. .It Fl D Turn on debugging mode. +.It Fl r Ar file +Parse logs from this file. +This option is mandatory. .Sh SEE ALSO .Xr varnishd 1 , -.Xr varnishhist 1 , -.Xr varnishncsa 1 , -.Xr varnishstat 1 , -.Xr varnishtop 1 +.Xr varnishlog 1 .Sh HISTORY The .Nm -utility was developed by +utility and this manual page were written by .An Cecilie Fritzvold Aq cecilihf at linpro.no . - -This manual page was written by -.An Cecilie Fritzvold Aq cecilihf at linpro.no . Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-26 11:37:34 UTC (rev 1578) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-26 11:41:23 UTC (rev 1579) @@ -1,6 +1,5 @@ /*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS + * Copyright (c) 2006 Linpro AS * All rights reserved. * * Author: Cecilie Fritzvold From des at projects.linpro.no Tue Jun 26 11:42:30 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 13:42:30 +0200 (CEST) Subject: r1580 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070626114230.AD3201EC28F@projects.linpro.no> Author: des Date: 2007-06-26 13:42:30 +0200 (Tue, 26 Jun 2007) New Revision: 1580 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 Log: Add missing Nd Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 2007-06-26 11:41:23 UTC (rev 1579) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.1 2007-06-26 11:42:30 UTC (rev 1580) @@ -32,6 +32,7 @@ .Os .Sh NAME .Nm varnishreplay +.Nd HTTP traffic replay tool .Sh SYNOPSIS .Nm .Op Fl D From des at projects.linpro.no Tue Jun 26 11:52:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 13:52:25 +0200 (CEST) Subject: r1581 - in trunk/varnish-cache: . bin/varnishd include lib/libvarnishapi Message-ID: <20070626115225.CB86C1EC294@projects.linpro.no> Author: des Date: 2007-06-26 13:52:25 +0200 (Tue, 26 Jun 2007) New Revision: 1581 Added: trunk/varnish-cache/bin/varnishd/instance.c trunk/varnish-cache/lib/libvarnishapi/instance.c Modified: trunk/varnish-cache/INSTALL trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/varnishd.1 trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/configure.ac trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/shmlog.c Log: Further refine -n handling. The argument to -n is now either an absolute path, or a path relative to $localstatedir/varnish. By default, it is set to the host name, which results in $localstatedir/varnish/$hostname. This logic is centralized in instance.c, which is compiled into both varnishd and libvarnishapi, with prototypes in varnishapi.h and heritage.h. Modified: trunk/varnish-cache/INSTALL =================================================================== --- trunk/varnish-cache/INSTALL 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/INSTALL 2007-06-26 11:52:25 UTC (rev 1581) @@ -5,10 +5,13 @@ and 'make install'. If you obtained the sources directly from the Subversion repository, -you will need to run autogen.sh first to create the 'configure' script. +you will need to run autogen.sh first to create the configure script. -Additional 'configure' options of interest: +Varnish will store run-time state in $localstatedir/varnish; you may +want to tune this using configure's --localstatedir parameter. +Additional configure options of interest: + --enable-developer-warnings enable strict warnings (default is NO) --enable-debugging-symbols Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-26 11:52:25 UTC (rev 1581) @@ -34,6 +34,7 @@ cache_ws.c \ hash_simple_list.c \ hash_classic.c \ + instance.c \ mgt_child.c \ mgt_cli.c \ mgt_event.c \ Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-26 11:52:25 UTC (rev 1581) @@ -63,7 +63,7 @@ /* Hash method */ struct hash_slinger *hash; - const char *n_arg; + char name[1024]; }; struct params { @@ -128,3 +128,5 @@ extern struct heritage heritage; void child_main(void); + +int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen); Added: trunk/varnish-cache/bin/varnishd/instance.c =================================================================== --- trunk/varnish-cache/bin/varnishd/instance.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/instance.c 2007-06-26 11:52:25 UTC (rev 1581) @@ -0,0 +1 @@ +link ../../lib/libvarnishapi/instance.c \ No newline at end of file Property changes on: trunk/varnish-cache/bin/varnishd/instance.c ___________________________________________________________________ Name: svn:special + * Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-26 11:52:25 UTC (rev 1581) @@ -204,7 +204,7 @@ AZ(close(heritage.fds[0])); AZ(close(heritage.fds[3])); - setproctitle("Varnish-Chld %s", heritage.n_arg); + setproctitle("Varnish-Chld %s", heritage.name); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); @@ -408,7 +408,7 @@ e->name = "mgt_sigchild"; AZ(ev_add(mgt_evb, e)); - setproctitle("Varnish-Mgr %s", heritage.n_arg); + setproctitle("Varnish-Mgr %s", heritage.name); sac.sa_handler = SIG_IGN; sac.sa_flags = SA_RESTART; Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-26 11:52:25 UTC (rev 1581) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 15, 2007 +.Dd June 26, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -130,9 +130,13 @@ for a list of supported algorithms. .It Fl n Specify a name for this instance. -This is a shortcut for specifying the -.Va name -run-time parameter. +Amonst other things, this name is used to construct the name of the +directory in which +.Nm +keeps temporary files and persistent state. +If the specified name begins with a forward slash, it is interpreted +as the absolute path to the directory which should be used for this +purpose. .It Fl P Ar file Write the process's PID to the specified .Ar file . @@ -402,14 +406,6 @@ The depth of the TCP listen queue. .Pp The default is 512. -.It Va name -The name of this -.Nm -instance. -All temporary files are stored in -.Pa /tmp/ Ns Va name . -.Pp -The default is the hostname. .It Va overflow_max The maximum depth of the overflow queue as a percentage of .Va thread_pool_max . Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-26 11:52:25 UTC (rev 1581) @@ -50,6 +50,10 @@ #include "compat/daemon.h" #endif +#ifndef HAVE_STRLCPY +#include "compat/strlcpy.h" +#endif + #include "vsb.h" #include "vpf.h" @@ -409,13 +413,14 @@ const char *f_arg = NULL; int f_fd = -1; const char *h_arg = "classic"; - const char *n_arg = "/tmp"; + const char *n_arg = NULL; const char *P_arg = NULL; const char *s_arg = "file"; const char *T_arg = NULL; char *p; struct cli cli[1]; struct pidfh *pfh = NULL; + char dirname[1024]; setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -524,7 +529,7 @@ fprintf(stderr, "One of -b or -f must be specified\n"); usage(); } - + if (f_arg != NULL) { f_fd = open(f_arg, O_RDONLY); if (f_fd < 0) { @@ -534,20 +539,25 @@ } } - if (mkdir(n_arg, 0755) < 0 && errno != EEXIST) { + if (varnish_instance(n_arg, heritage.name, sizeof heritage.name, + dirname, sizeof dirname) != 0) { + fprintf(stderr, "Invalid instance name: %s\n", + strerror(errno)); + exit(1); + } + + if (mkdir(dirname, 0755) < 0 && errno != EEXIST) { fprintf(stderr, "Cannot create working directory '%s': %s\n", - n_arg, strerror(errno)); + dirname, strerror(errno)); exit(1); } - if (chdir(n_arg) < 0) { + if (chdir(dirname) < 0) { fprintf(stderr, "Cannot change to working directory '%s': %s\n", - n_arg, strerror(errno)); + dirname, strerror(errno)); exit(1); } - heritage.n_arg = n_arg; - /* XXX: should this be relative to the -n arg ? */ if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) { perror(P_arg); Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/configure.ac 2007-06-26 11:52:25 UTC (rev 1581) @@ -102,6 +102,11 @@ AC_CHECK_FUNCS([epoll_ctl]) AC_CHECK_FUNCS([poll]) +# Run-time directory +VARNISH_STATE_DIR=`eval "echo $localstatedir/varnish"` +AC_DEFINE_UNQUOTED(VARNISH_STATE_DIR, "$VARNISH_STATE_DIR", + [Base directory for run-time state]) + # 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 Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/include/varnishapi.h 2007-06-26 11:52:25 UTC (rev 1581) @@ -58,21 +58,7 @@ struct varnish_stats *VSL_OpenStats(const char *varnish_name); extern const char *VSL_tags[256]; -/* varnish_debug.c */ -void vdb_panic(const char *, ...) V_DEAD; +/* instance.c */ +int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen); -/* varnish_log.c */ -typedef struct vlo_buffer vlo_buffer_t; -vlo_buffer_t *vlo_open(const char *, size_t, int); -ssize_t vlo_write(vlo_buffer_t *, const void *, size_t); -vlo_buffer_t *vlo_attach(const char *); -ssize_t vlo_read(vlo_buffer_t *, const void *, size_t); -#if 0 -uuid_t vlo_get_uuid(vlo_buffer_t *); #endif -int vlo_close(vlo_buffer_t *); - -/* varnish_util.c */ -int vut_open_lock(const char *, int, int, int); - -#endif Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2007-06-26 11:52:25 UTC (rev 1581) @@ -6,6 +6,7 @@ libvarnishapi_la_SOURCES = \ base64.c \ + instance.c \ shmlog.c libvarnishapi_la_CFLAGS = -include config.h Added: trunk/varnish-cache/lib/libvarnishapi/instance.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/instance.c (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/instance.c 2007-06-26 11:52:25 UTC (rev 1581) @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2007 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Sm?rgrav + * + * 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. + * + * $Id$ + */ + +#include +#include +#include + +#include "varnishapi.h" + +int +varnish_instance(const char *n_arg, + char *name, size_t namelen, + char *dir, size_t dirlen) +{ + size_t len; + + if (n_arg == NULL) { + if (gethostname(name, namelen) != 0) + return (-1); + } else { + len = snprintf(name, namelen, "%s", n_arg); + if (len >= namelen) { + errno = ENAMETOOLONG; + return (-1); + } + } + + if (*name == '/') + len = snprintf(dir, dirlen, "%s", name); + else + len = snprintf(dir, dirlen, "%s/%s", VARNISH_STATE_DIR, name); + + if (len >= dirlen) { + errno = ENAMETOOLONG; + return (-1); + } + return (0); +} Property changes on: trunk/varnish-cache/lib/libvarnishapi/instance.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-26 11:42:30 UTC (rev 1580) +++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-26 11:52:25 UTC (rev 1581) @@ -29,16 +29,18 @@ * $Id$ */ +#include + +#include +#include +#include +#include +#include +#include #include -#include -#include +#include #include -#include #include -#include -#include -#include -#include #include "shmlog.h" #include "miniobj.h" @@ -106,28 +108,36 @@ { int i; struct shmloghead slh; - char buf[BUFSIZ]; + char name[PATH_MAX], dirname[PATH_MAX], logname[PATH_MAX]; if (vsl_lh != NULL) return (0); - sprintf(buf, "/tmp/%s/%s", varnish_name, SHMLOG_FILENAME); + if (varnish_instance(varnish_name, name, + sizeof name, dirname, sizeof dirname) != 0) { + fprintf(stderr, "Invalid instance name: %s\n", + strerror(errno)); + return (1); + } - vsl_fd = open(buf, O_RDONLY); + /* XXX check overflow */ + snprintf(logname, sizeof logname, "%s/%s", dirname, SHMLOG_FILENAME); + + vsl_fd = open(logname, O_RDONLY); if (vsl_fd < 0) { fprintf(stderr, "Cannot open %s: %s\n", - buf, strerror(errno)); + logname, strerror(errno)); return (1); } i = read(vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { fprintf(stderr, "Cannot read %s: %s\n", - buf, strerror(errno)); + logname, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { fprintf(stderr, "Wrong magic number in file %s\n", - buf); + logname); return (1); } @@ -135,7 +145,7 @@ PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0); if (vsl_lh == MAP_FAILED) { fprintf(stderr, "Cannot mmap %s: %s\n", - buf, strerror(errno)); + logname, strerror(errno)); return (1); } return (0); @@ -172,17 +182,12 @@ int VSL_OpenLog(struct VSL_data *vd, const char *varnish_name) { - char hostname[1024]; unsigned char *p; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->fi != NULL) return (0); - if (varnish_name == NULL) { - gethostname(hostname, sizeof hostname); - varnish_name = hostname; - } if (vsl_shmem_map(varnish_name)) return (-1); From des at projects.linpro.no Tue Jun 26 12:18:01 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 26 Jun 2007 14:18:01 +0200 (CEST) Subject: r1582 - trunk/varnish-cache Message-ID: <20070626121801.645D41EC28F@projects.linpro.no> Author: des Date: 2007-06-26 14:18:01 +0200 (Tue, 26 Jun 2007) New Revision: 1582 Modified: trunk/varnish-cache/Makefile.am Log: Create $(localstatedir)/varnish at install time. Modified: trunk/varnish-cache/Makefile.am =================================================================== --- trunk/varnish-cache/Makefile.am 2007-06-26 11:52:25 UTC (rev 1581) +++ trunk/varnish-cache/Makefile.am 2007-06-26 12:18:01 UTC (rev 1582) @@ -5,3 +5,6 @@ SUBDIRS += debian redhat EXTRA_DIST = LICENSE autogen.sh + +install-data-local: + $(install_sh) -d -m 0755 $(localstatedir)/varnish From cecilihf at projects.linpro.no Wed Jun 27 12:21:59 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Wed, 27 Jun 2007 14:21:59 +0200 (CEST) Subject: r1583 - in trunk/varnish-tools: . munin Message-ID: <20070627122159.791FC1EC294@projects.linpro.no> Author: cecilihf Date: 2007-06-27 14:21:58 +0200 (Wed, 27 Jun 2007) New Revision: 1583 Added: trunk/varnish-tools/munin/ trunk/varnish-tools/munin/README trunk/varnish-tools/munin/varnish_cachehitratio trunk/varnish-tools/munin/varnish_hitrate trunk/varnish-tools/munin/varnish_varnishstat_ Log: Added munin plugins. Added: trunk/varnish-tools/munin/README =================================================================== --- trunk/varnish-tools/munin/README (rev 0) +++ trunk/varnish-tools/munin/README 2007-06-27 12:21:58 UTC (rev 1583) @@ -0,0 +1,23 @@ +The scripts in this directory are munin plugins for monitoring varnish. +varnish_cachehitratio and varnish_hitrate are written by Anders +Nordby, while varnish_varnishstat_ is written by Bj?rn +Ruberg. All three scripts uses varnishstat to acquire information. + +* varnish_cachehitratio shows the cache hit/miss ratio. +* varnish_hitrate shows the rate of requests. +* varnish_varnishstat_ shows the cache usage. + +To work with named varnish instances, these scripts will have to be modified +so they can call varnishstat with the appropriate parameter. As of today, +the scripts only call 'varnishstat -1', and thus, will only work if varnishd +was started without the -n parameter. A solution to this problem could be to +let the scripts read a filename from an environment variable (this must then +be set in the munin-plugin configuration), and have this file contain the +name (or names?) to the varnish server(s) to monitor. If the environment +variable is not set, varnishstat will be called without the -n parameter, +and work with the default name. + +Dependencies: +* varnish_cachehitration needs the CPAN module Date::Format +* varnish_varnishstart_ needs the CPAN module Net::Telnet +(but does it really? It doesn't seem to use it for anything.) Added: trunk/varnish-tools/munin/varnish_cachehitratio =================================================================== --- trunk/varnish-tools/munin/varnish_cachehitratio (rev 0) +++ trunk/varnish-tools/munin/varnish_cachehitratio 2007-06-27 12:21:58 UTC (rev 1583) @@ -0,0 +1,124 @@ +#! /usr/bin/perl +# Varnish cache hit ratio logger/plugin +# anders at aftenposten.no, 2007-05-07 + +# Log/data file +# These must be created with write permission to the user the plugin runs as +# On FreeBSD, that is nobody +# Comment $mylog out to skip logging + +$mydat = "/var/tmp/varnish_cachehitratio.dat"; +#$mylog = "/var/log/varnish_cachehitratio.log"; + +%stat = (); +$ENV{PATH} = "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"; + +use Date::Format; + +sub popstat { + foreach $line (`varnishstat -1`) { + chomp($line); + if ($line =~ /^\s+(\d+)\s+(.*)$/) { + $val = $1; + $key = $2; + $key =~ s@\s at _@g; + $key =~ tr at A-Z@a-z@; + + $stat{"$key"} = $val; + } + } +} + +sub printconfig { + print "graph_title Cache hit/miss ratio\n"; + print "graph_args --upper-limit 100 -l 0\n"; + print "graph_vlabel % of requests\n"; + print "graph_category varnish\n"; + print "graph_info This graph shows the ratio of requests found in the cache and not\n"; + print "graph_order hitratio missratio unknownratio\n"; + print "graph_scale no\n"; + + print "hitratio.label hits\n"; + print "hitratio.type GAUGE\n"; + print "hitratio.graph yes\n"; + print "hitratio.min 0\n"; + print "hitratio.max 100\n"; + print "hitratio.draw AREA\n"; + + print "missratio.label misses\n"; + print "missratio.type GAUGE\n"; + print "missratio.graph yes\n"; + print "missratio.min 0\n"; + print "missratio.max 100\n"; + print "missratio.draw STACK\n"; + + print "unknownratio.label unknown\n"; + print "unknownratio.type GAUGE\n"; + print "unknownratio.graph yes\n"; + print "unknownratio.min 0\n"; + print "unknownratio.max 100\n"; + print "unknownratio.draw STACK\n"; +} + +sub findvalues { + $nrequests = $stat{"client_requests_received"}; + $nhits = $stat{"cache_hits"}; + $nmisses = $stat{"cache_misses"}; + + open(OVAL, $mydat); + $tmpstr = ; + close(OVAL); + chomp($tmpstr); + + ($orequests,$ohits,$omisses) = split(/ /, $tmpstr, 3); + + $hits = $nhits - $ohits; + $requests = $nrequests - $orequests; + $misses = $nmisses - $omisses; +} + +sub printvalues { + if ($requests > 0) { + $hitratio = sprintf("%.2f", $hits / $requests * 100); + $missratio = sprintf("%.2f", $misses / $requests * 100); + } else { + # Assume cache hit ratio = 100% if requests < 0 + $hitratio = sprintf("%.2f", 100); + $missratio = sprintf("%.2f", 0); + } + + if (($hitratio + $missratio) > 100) { + # Rounding foo, hit+miss ratio is higher than 100 + $missratio = sprintf("%.2f", 100 - $hitratio); + $unknownratio = sprintf("%.2f", 0); + } else { + # Unknown = rest, hit+miss ratio is upto or 100 + $unknownratio = sprintf("%.2f", 100 - ($hitratio + $missratio)); + } + + print "hitratio.value $hitratio\n"; + print "missratio.value $missratio\n"; + print "unknownratio.value $unknownratio\n"; + if ($mylog ne "") { + open(LOG, ">>$mylog"); + print LOG "hitratio=$hitratio missratio=$missratio unknown=$unknownratio hits=$hits misses=$misses requests=$requests [" . time2str("%Y-%m-%d %H:%M:%S", time) . "]\n"; + close(LOG); + } +} + +sub writevalues { + open(OVAL, ">$mydat"); + print OVAL "$nrequests $nhits $nmisses\n"; + close(OVAL); +} + +if ($ARGV[0] eq "autoconf") { + print "yes\n"; +} elsif ($ARGV[0] eq "config") { + printconfig; +} else { + popstat; + findvalues; + printvalues; + writevalues; +} Added: trunk/varnish-tools/munin/varnish_hitrate =================================================================== --- trunk/varnish-tools/munin/varnish_hitrate (rev 0) +++ trunk/varnish-tools/munin/varnish_hitrate 2007-06-27 12:21:58 UTC (rev 1583) @@ -0,0 +1,29 @@ +#! /bin/sh +# anders at aftenposten.no, 2007-05-07 +# Shows the rate of requests (per second) for Varnish + +PATH="$PATH:/usr/local/bin" +export PATH + +pvstat() { + # $1: vname $2: grabstat + printf "$1.value " + varnishstat -1 | egrep "$2" | awk '{print $1}' +} + +case $1 in +autoconf) echo yes;; +config) + echo 'graph_title Hitrate' + echo 'graph_vlabel hits per second' + echo 'graph_category varnish' + echo 'graph_info This graph shows the rate of requests, hits per second' + + echo 'requests.label requests' + echo 'requests.type COUNTER' + echo 'requests.graph yes' + ;; +*) + pvstat requests 'Client requests received$' + ;; +esac Added: trunk/varnish-tools/munin/varnish_varnishstat_ =================================================================== --- trunk/varnish-tools/munin/varnish_varnishstat_ (rev 0) +++ trunk/varnish-tools/munin/varnish_varnishstat_ 2007-06-27 12:21:58 UTC (rev 1583) @@ -0,0 +1,71 @@ +#!/usr/bin/perl +use Net::Telnet (); +use Data::Dumper; + +$arg = shift @ARGV; + +%aspects = ( + 'cache' => 'Cache', + 'backend' => 'Backend', + 'shm' => 'SHM' + ); + +(my $whut = $0) =~ s/^.*\_//; + +# Hvis $whut IKKE fins, men $arg fins OG er noe annet enn blabla +# s?? skal den trigge + +if (!$whut && $arg && $arg !~ /^(suggest|autoconf)$/) { + print "Only 'suggest' and 'autoconf' may be used w/o symlinked name\n"; + exit 2; +} elsif (!$whut && !$arg) { + print "Uh. Bugger.\n"; + exit 2; +} + +if ($arg eq 'autoconf') { + print "Autoconf starting...\n"; + exit 0; +} elsif ($arg eq 'suggest') { + print "Suggest starting...\n"; + exit 0; +} elsif ($arg eq 'config') { + $config = 1; +} + +$grepfor = $aspects{$whut}; +# print "Looking for $grepfor\n"; + +if ($config) { + print "graph_title Varnish $grepfor usage\n"; + print "graph_args --base 1000\n"; + print "graph_vlabel Activity / \${graph_period}\n"; + print "graph_category Varnish\n"; +} + +$i = 0; +foreach $line (`varnishstat -1`) { + chomp $line; + if ($line =~ /^\s+(\d+)\s+($grepfor.*)$/) { + $val = $1; + $key = $2; + ($printkey = lc ($key)) =~ s/\s/_/g; + if ($config) { + print "$printkey\.label $key\n"; + print "$printkey\.type DERIVE\n"; + print "$printkey\.min 0\n"; + print "$printkey\.draw "; + if ($i == 0) { + print "AREA\n"; + } else { + print "STACK\n"; + } + $i++; + } else { + print "$printkey\.value $val\n"; + } + } +} + +exit; + From phk at projects.linpro.no Wed Jun 27 12:37:34 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 27 Jun 2007 14:37:34 +0200 (CEST) Subject: r1584 - trunk/varnish-cache/bin/varnishd Message-ID: <20070627123734.D1CE61EC28F@projects.linpro.no> Author: phk Date: 2007-06-27 14:37:34 +0200 (Wed, 27 Jun 2007) New Revision: 1584 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Make sure to reset the workspaces of the backend connection between requests, otherwise we end up filling it up with Content-Length: headers if we manage to keep the backend busy. Also make the snapshot of the preferred workspace-size volatile to ensure that we are consistent. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-06-27 12:21:58 UTC (rev 1583) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-06-27 12:37:34 UTC (rev 1584) @@ -81,7 +81,7 @@ { struct vbe_conn *vbc; unsigned char *p; - unsigned space; + volatile unsigned space; space = params->mem_workspace; vbc = calloc(sizeof *vbc + space * 2, 1); @@ -353,6 +353,8 @@ assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); + WS_Reset(vc->http->ws); + WS_Reset(vc->http2->ws); LOCK(&vbemtx); VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); From phk at projects.linpro.no Wed Jun 27 12:43:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 27 Jun 2007 14:43:09 +0200 (CEST) Subject: r1585 - trunk/varnish-cache/bin/varnishd Message-ID: <20070627124309.383DA1EC294@projects.linpro.no> Author: phk Date: 2007-06-27 14:43:08 +0200 (Wed, 27 Jun 2007) New Revision: 1585 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Don't fill the entire workspace with read-ahead data. Eventually we need to separate the "max http header size" from the workspace size, but that will take a bit of pondering. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-27 12:37:34 UTC (rev 1584) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-06-27 12:43:08 UTC (rev 1585) @@ -631,6 +631,7 @@ int i; l = (hp->ws->e - hp->rx_e) - 1; + l /= 2; /* Don't fill all of workspace with read-ahead */ if (l <= 1) { VSL(SLT_HttpError, fd, "Received too much"); VSLR(SLT_HttpGarbage, fd, hp->rx_s, hp->rx_e); From des at projects.linpro.no Wed Jun 27 12:56:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 27 Jun 2007 14:56:04 +0200 (CEST) Subject: r1586 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20070627125604.B96A91EC28F@projects.linpro.no> Author: des Date: 2007-06-27 14:56:04 +0200 (Wed, 27 Jun 2007) New Revision: 1586 Added: trunk/varnish-cache/bin/varnishd/stevedore.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_lru.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/include/shmlog_tags.h Log: Mostly finish the LRU code and its integration: - Wrap the storage code so we don't need to duplicate the "toss out some old crap and try again" logic everywhere. This will also help when / if we decide to add support for multiple concurrent storage arenas. - While I'm at it, implement sma_trim(). - Rework the interaction between the LRU and expiry code. Instead of placing objects retired by the LRU on death row, immediately terminate them. - Give the LRU code its own fake session and worker so we don't have to pass it a session pointer. - Rework the LRU API, and add LRU_DiscardOne() which discards a single object. This is what the stevedore code uses. Known or suspected issues: - The LRU and expiry code should use the same mutex, and / or the possiblity for races between them should be examined closely. - LRU_Init() needs to be looked at and possibly moved. - LRU_DiscardSpace() and LRU_DiscardTime() are unused and quite possibly useless. - Logging and statistics related to the LRU need more attention. - The stevedore API can probably be improved. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-27 12:56:04 UTC (rev 1586) @@ -42,6 +42,7 @@ mgt_vcc.c \ rfc2616.c \ shmlog.c \ + stevedore.c \ storage_file.c \ storage_malloc.c \ tcp.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-06-27 12:56:04 UTC (rev 1586) @@ -375,7 +375,7 @@ void EXP_Insert(struct object *o); void EXP_Init(void); void EXP_TTLchange(struct object *o); -void EXP_Retire(struct object *o); +void EXP_Terminate(struct object *o); /* cache_fetch.c */ int Fetch(struct sess *sp); @@ -478,10 +478,12 @@ void VCL_Get(struct VCL_conf **vcc); /* cache_lru.c */ +// void LRU_Init(void); void LRU_Enter(struct object *o, time_t stamp); void LRU_Remove(struct object *o); -void LRU_DiscardSpace(struct sess *sp, uint64_t quota); -void LRU_DiscardTime(struct sess *sp, time_t cutoff); +int LRU_DiscardOne(void); +int LRU_DiscardSpace(int64_t quota); +int LRU_DiscardTime(time_t cutoff); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -74,13 +74,25 @@ UNLOCK(&exp_mtx); } +/* + * Immediately destroy an object. Do not wait for it to expire or trickle + * through death row; yank it + */ void -EXP_Retire(struct object *o) +EXP_Terminate(struct object *o) { LOCK(&exp_mtx); - TAILQ_INSERT_TAIL(&exp_deathrow, o, deathrow); - VSL_stats->n_deathrow++; + if (o->lru_stamp) + LRU_Remove(o); + if (o->heap_idx) + binheap_delete(exp_heap, o->heap_idx); + if (o->deathrow.tqe_next) { + TAILQ_REMOVE(&exp_deathrow, o, deathrow); + VSL_stats->n_deathrow--; + } UNLOCK(&exp_mtx); + VSL(SLT_Terminate, 0, "%u", o->xid); + HSH_Deref(o); } /*-------------------------------------------------------------------- @@ -183,7 +195,10 @@ VCL_timeout_method(sp); if (sp->handling == VCL_RET_DISCARD) { - EXP_Retire(o); + LOCK(&exp_mtx); + TAILQ_INSERT_TAIL(&exp_deathrow, o, deathrow); + VSL_stats->n_deathrow++; + UNLOCK(&exp_mtx); continue; } assert(sp->handling == VCL_RET_DISCARD); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -59,8 +59,7 @@ if (cl == 0) return (0); - st = stevedore->alloc(stevedore, cl); - XXXAN(st->stevedore); + st = STV_alloc(cl); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); st->len = cl; sp->obj->len = cl; @@ -147,11 +146,9 @@ /* Get some storage if we don't have any */ if (st == NULL || st->len == st->space) { v = u; - if (u < params->fetch_chunksize * 1024 && - stevedore->trim != NULL) + if (u < params->fetch_chunksize * 1024) v = params->fetch_chunksize * 1024; - st = stevedore->alloc(stevedore, v); - XXXAN(st->stevedore); + st = STV_alloc(v); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); } v = st->space - st->len; @@ -198,9 +195,9 @@ if (st != NULL && st->len == 0) { TAILQ_REMOVE(&sp->obj->store, st, list); - stevedore->free(st); - } else if (st != NULL && stevedore->trim != NULL) - stevedore->trim(st, st->len); + STV_free(st); + } else if (st != NULL) + STV_trim(st, st->len); return (0); } @@ -226,9 +223,7 @@ st = NULL; while (1) { if (v == 0) { - st = stevedore->alloc(stevedore, - params->fetch_chunksize * 1024); - XXXAN(st->stevedore); + st = STV_alloc(params->fetch_chunksize * 1024); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); p = st->ptr + st->len; v = st->space - st->len; @@ -248,9 +243,9 @@ if (st->len == 0) { TAILQ_REMOVE(&sp->obj->store, st, list); - stevedore->free(st); - } else if (stevedore->trim != NULL) - stevedore->trim(st, st->len); + STV_free(st); + } else + STV_trim(st, st->len); return (1); } @@ -345,7 +340,7 @@ while (!TAILQ_EMPTY(&sp->obj->store)) { st = TAILQ_FIRST(&sp->obj->store); TAILQ_REMOVE(&sp->obj->store, st, list); - stevedore->free(st); + STV_free(st); } close(vc->fd); VBE_ClosedFd(sp->wrk, vc, 1); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -104,7 +104,7 @@ TAILQ_FOREACH_SAFE(st, &o->store, list, stn) { CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); TAILQ_REMOVE(&o->store, st, list); - st->stevedore->free(st); + STV_free(st); } } @@ -260,7 +260,6 @@ free(o->vary); HSH_Freestore(o); - LRU_Remove(o); FREE_OBJ(o); VSL_stats->n_object--; Modified: trunk/varnish-cache/bin/varnishd/cache_lru.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -40,10 +40,33 @@ */ #define LRU_DELAY 2 +TAILQ_HEAD(lru_head, object); + +static struct lru_head lru_list = TAILQ_HEAD_INITIALIZER(lru_list); static pthread_mutex_t lru_mtx = PTHREAD_MUTEX_INITIALIZER; -static TAILQ_HEAD(lru_head, object) lru_list; +static struct sess *lru_session; +static struct worker lru_worker; /* + * Initialize the LRU data structures. + */ +static inline void +LRU_Init(void) +{ + if (lru_session == NULL) { + lru_session = SES_New(NULL, 0); + XXXAN(lru_session); + lru_session->wrk = &lru_worker; + lru_worker.magic = WORKER_MAGIC; + lru_worker.wlp = lru_worker.wlog; + lru_worker.wle = lru_worker.wlog + sizeof lru_worker.wlog; + VCL_Get(&lru_session->vcl); + } else { + VCL_Refresh(&lru_session->vcl); + } +} + +/* * Enter an object into the LRU list, or move it to the head of the list * if it's already in it and hasn't moved in a while. */ @@ -55,12 +78,12 @@ assert(stamp > 0); if (o->lru_stamp < stamp - LRU_DELAY && o != lru_list.tqh_first) { // VSL(SLT_LRU_enter, 0, "%u %u %u", o->xid, o->lru_stamp, stamp); - pthread_mutex_lock(&lru_mtx); + LOCK(&lru_mtx); if (o->lru_stamp != 0) TAILQ_REMOVE(&lru_list, o, lru); TAILQ_INSERT_HEAD(&lru_list, o, lru); o->lru_stamp = stamp; - pthread_mutex_unlock(&lru_mtx); + UNLOCK(&lru_mtx); } } @@ -74,74 +97,123 @@ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); if (o->lru_stamp != 0) { // VSL(SLT_LRU_remove, 0, "%u", o->xid); - pthread_mutex_lock(&lru_mtx); + LOCK(&lru_mtx); TAILQ_REMOVE(&lru_list, o, lru); - pthread_mutex_unlock(&lru_mtx); + UNLOCK(&lru_mtx); } } /* + * With the LRU lock held, call VCL_discard(). Depending on the result, + * either insert the object at the head of the list or dereference it. + */ +static int +LRU_DiscardLocked(struct object *o) +{ + struct object *so; + + if (o->busy) + return (0); + + /* XXX this is a really bad place to do this */ + LRU_Init(); + + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + TAILQ_REMOVE(&lru_list, o, lru); + + lru_session->obj = o; + VCL_discard_method(lru_session); + + if (lru_session->handling == VCL_RET_DISCARD) { + /* discard: release object */ + VSL(SLT_ExpKill, 0, "%u %d", o->xid, o->lru_stamp); + o->lru_stamp = 0; + EXP_Terminate(o); + return (1); + } else { + /* keep: move to front of list */ + if ((so = TAILQ_FIRST(&lru_list))) + o->lru_stamp = so->lru_stamp; + TAILQ_INSERT_HEAD(&lru_list, o, lru); + return (0); + } +} + +/* + * Walk through the LRU list, starting at the back, and check each object + * until we find one that can be retired. Return the number of objects + * that were discarded. + */ +int +LRU_DiscardOne(void) +{ + struct object *first = TAILQ_FIRST(&lru_list); + struct object *o; + int count = 0; + + LOCK(&lru_mtx); + while (!count && (o = TAILQ_LAST(&lru_list, lru_head))) { + if (LRU_DiscardLocked(o)) + ++count; + if (o == first) { + /* full circle */ + break; + } + } + UNLOCK(&lru_mtx); + return (0); +} + +/* * Walk through the LRU list, starting at the back, and retire objects - * until our quota is reached or we run out of objects to retire. + * until our quota is reached or we run out of objects to retire. Return + * the number of objects that were discarded. */ -void -LRU_DiscardSpace(struct sess *sp, uint64_t quota) +int +LRU_DiscardSpace(int64_t quota) { - struct object *o, *so; + struct object *first = TAILQ_FIRST(&lru_list); + struct object *o; + unsigned int len; + int count = 0; - pthread_mutex_lock(&lru_mtx); - while ((o = TAILQ_LAST(&lru_list, lru_head))) { - TAILQ_REMOVE(&lru_list, o, lru); - so = sp->obj; - sp->obj = o; - VCL_discard_method(sp); - sp->obj = so; - if (sp->handling == VCL_RET_DISCARD) { - /* discard: place on deathrow */ - EXP_Retire(o); - o->lru_stamp = 0; - if (o->len > quota) - break; - quota -= o->len; - } else { - /* keep: move to front of list */ - if ((so = TAILQ_FIRST(&lru_list))) - o->lru_stamp = so->lru_stamp; - TAILQ_INSERT_HEAD(&lru_list, o, lru); + LOCK(&lru_mtx); + while (quota > 0 && (o = TAILQ_LAST(&lru_list, lru_head))) { + len = o->len; + if (LRU_DiscardLocked(o)) { + quota -= len; + ++count; } + if (o == first) { + /* full circle */ + break; + } } - pthread_mutex_unlock(&lru_mtx); + UNLOCK(&lru_mtx); + return (count); } /* * Walk through the LRU list, starting at the back, and retire objects - * that haven't been accessed since the specified cutoff date. + * that haven't been accessed since the specified cutoff date. Return the + * number of objects that were discarded. */ -void -LRU_DiscardTime(struct sess *sp, time_t cutoff) +int +LRU_DiscardTime(time_t cutoff) { - struct object *o, *so; + struct object *first = TAILQ_FIRST(&lru_list); + struct object *o; + int count = 0; - pthread_mutex_lock(&lru_mtx); - while ((o = TAILQ_LAST(&lru_list, lru_head))) { - if (o->lru_stamp >= cutoff) + LOCK(&lru_mtx); + while ((o = TAILQ_LAST(&lru_list, lru_head)) && o->lru_stamp <= cutoff) { + if (LRU_DiscardLocked(o)) + ++count; + if (o == first) { + /* full circle */ break; - TAILQ_REMOVE(&lru_list, o, lru); - so = sp->obj; - sp->obj = o; - VCL_discard_method(sp); - sp->obj = so; - if (sp->handling == VCL_RET_DISCARD) { - /* discard: place on deathrow */ - EXP_Retire(o); - } else { - /* keep: move to front of list */ - if ((so = TAILQ_FIRST(&lru_list)) && so->lru_stamp > cutoff) - o->lru_stamp = so->lru_stamp; - else - o->lru_stamp = cutoff; - TAILQ_INSERT_HEAD(&lru_list, o, lru); } } - pthread_mutex_unlock(&lru_mtx); + UNLOCK(&lru_mtx); + return (count); } Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -90,7 +90,7 @@ /* allocate space for body */ /* XXX what if the object already has a body? */ - st = stevedore->alloc(stevedore, 1024); + st = STV_alloc(1024); XXXAN(st->stevedore); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); Added: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2007 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Sm?rgav + * + * 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. + * + * $Id$ + */ + +#include "cache.h" + +struct storage * +STV_alloc(size_t size) +{ + struct storage *st; + + AN(stevedore); + AN(stevedore->alloc); + do { + if ((st = stevedore->alloc(stevedore, size)) == NULL) + LRU_DiscardOne(); + } while (st == NULL); + return (st); +} + +void +STV_trim(struct storage *st, size_t size) +{ + + AN(st->stevedore); + if (st->stevedore->trim) + st->stevedore->trim(st, size); +} + +void +STV_free(struct storage *st) +{ + + AN(st->stevedore); + AN(stevedore->free); + st->stevedore->free(st); +} Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-06-27 12:56:04 UTC (rev 1586) @@ -50,3 +50,7 @@ /* private fields */ void *priv; }; + +struct storage *STV_alloc(size_t size); +void STV_trim(struct storage *st, size_t size); +void STV_free(struct storage *st); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -631,6 +631,10 @@ LOCK(&sc->mtx); VSL_stats->sm_nreq++; smf = alloc_smf(sc, size); + if (smf == NULL) { + UNLOCK(&sc->mtx); + return (NULL); + } CHECK_OBJ_NOTNULL(smf, SMF_MAGIC); VSL_stats->sm_nobj++; VSL_stats->sm_balloc += smf->size; Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-27 12:56:04 UTC (rev 1586) @@ -49,7 +49,8 @@ VSL_stats->sm_nreq++; sma = calloc(sizeof *sma, 1); - XXXAN(sma); + if (sma == NULL) + return (NULL); sma->s.priv = sma; sma->s.ptr = malloc(size); XXXAN(sma->s.ptr); @@ -68,6 +69,7 @@ { struct sma *sma; + CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); sma = s->priv; VSL_stats->sm_nobj--; VSL_stats->sm_balloc -= sma->s.space; @@ -75,8 +77,25 @@ free(sma); } +static void +sma_trim(struct storage *s, size_t size) +{ + struct sma *sma; + 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; + } +} + struct stevedore sma_stevedore = { .name = "malloc", .alloc = sma_alloc, - .free = sma_free + .free = sma_free, + .trim = sma_trim, }; Modified: trunk/varnish-cache/include/shmlog_tags.h =================================================================== --- trunk/varnish-cache/include/shmlog_tags.h 2007-06-27 12:43:08 UTC (rev 1585) +++ trunk/varnish-cache/include/shmlog_tags.h 2007-06-27 12:56:04 UTC (rev 1586) @@ -92,3 +92,4 @@ SLTM(ExpPick) SLTM(ExpKill) SLTM(WorkThread) +SLTM(Terminate) From des at projects.linpro.no Thu Jun 28 09:35:56 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 11:35:56 +0200 (CEST) Subject: r1587 - in trunk/varnish-cache: bin/varnishd bin/varnishstat include Message-ID: <20070628093556.EEA021EC294@projects.linpro.no> Author: des Date: 2007-06-28 11:35:56 +0200 (Thu, 28 Jun 2007) New Revision: 1587 Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/include/stat_field.h Log: Some of the statistics we gather are accumulated totals, while others are instantaneous measurements. For instance, we report the total number of allocator requests made over the child's lifetime, but we also report the amount of storage in use at any particular moment. The difference is important, because accumulated totals can be averaged over the program's lifetime (or over the last N seconds), but instantaneous measurements can't. Recycle the format field in MAC_STAT() (it was never used anyway) into a single-character flag indicating whether each item is an accumulated total ('a') or an instantaneous measure ('i'). Use this in varnishstat to skip averaging non-averageable numbers. Also rework varnishstat's "once" mode to show 1) each statistic's symbolic name, 2) its current value, 3) if appropriate, its value averaged over the process lifetime, and 4) its description. The reason for displaying the symbolic name is to simplify scripting, and to serve as a reference for looking up symbolic names to pass to e.g. the upcoming Nagios plugin. Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-27 12:56:04 UTC (rev 1586) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-06-28 09:35:56 UTC (rev 1587) @@ -68,8 +68,8 @@ (void)priv; AN(VSL_stats); -#define MAC_STAT(n,t,f,d) \ - cli_out(cli, "%12ju " d "\n", (VSL_stats->n)); +#define MAC_STAT(n, t, f, d) \ + cli_out(cli, "%12ju %s\n", (VSL_stats->n), d); #include "stat_field.h" #undef MAC_STAT } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-27 12:56:04 UTC (rev 1586) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 09:35:56 UTC (rev 1587) @@ -115,11 +115,17 @@ printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3); printw("\n"); -#define MAC_STAT(n,t,f,d) \ +#define MAC_STAT(n, t, f, d) \ + do { \ ju = VSL_stats->n; \ - printw("%12ju %12.2f %12.2f " d "\n", \ - ju, (ju - (intmax_t)copy.n)/lt, ju / up); \ - copy.n = ju; + if (f == 'a') { \ + printw("%12ju %12.2f %12.2f %s\n", \ + ju, (ju - (intmax_t)copy.n)/lt, ju / up, d); \ + copy.n = ju; \ + } else { \ + printw("%12ju %12s %12s %s\n", ju, ". ", ". ", d); \ + } \ + } while (0); #include "stat_field.h" #undef MAC_STAT lt = tt; @@ -129,6 +135,27 @@ } static void +do_once(struct varnish_stats *VSL_stats) +{ + struct timespec ts; + double up; + + clock_gettime(CLOCK_REALTIME, &ts); + up = ts.tv_sec - VSL_stats->start_time; + +#define MAC_STAT(n, t, f, d) \ + do { \ + intmax_t ju = VSL_stats->n; \ + if (f == 'a') \ + printf("%-16s %12ju %12.2f %s\n", #n, ju, ju / up, d); \ + else \ + printf("%-16s %12ju %12s %s\n", #n, ju, ". ", d); \ + } while (0); +#include "stat_field.h" +#undef MAC_STAT +} + +static void usage(void) { fprintf(stderr, "usage: varnishstat [-1V] [-n varnish_name] [-w delay]\n"); @@ -165,15 +192,10 @@ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); - if (!once) { + if (once) + do_once(VSL_stats); + else do_curses(VSL_stats, delay); - } else { -#define MAC_STAT(n,t,f,d) \ - printf("%12ju " d "\n", (VSL_stats->n)); -#include "stat_field.h" -#undef MAC_STAT - } - exit(0); } Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2007-06-27 12:56:04 UTC (rev 1586) +++ trunk/varnish-cache/include/stat_field.h 2007-06-28 09:35:56 UTC (rev 1587) @@ -29,63 +29,63 @@ * $Id$ */ -MAC_STAT(client_conn, uint64_t, "u", "Client connections accepted") -MAC_STAT(client_req, uint64_t, "u", "Client requests received") +MAC_STAT(client_conn, uint64_t, 'a', "Client connections accepted") +MAC_STAT(client_req, uint64_t, 'a', "Client requests received") -MAC_STAT(cache_hit, uint64_t, "u", "Cache hits") -MAC_STAT(cache_hitpass, uint64_t, "u", "Cache hits for pass") -MAC_STAT(cache_miss, uint64_t, "u", "Cache misses") +MAC_STAT(cache_hit, uint64_t, 'a', "Cache hits") +MAC_STAT(cache_hitpass, uint64_t, 'a', "Cache hits for pass") +MAC_STAT(cache_miss, uint64_t, 'a', "Cache misses") -MAC_STAT(backend_conn, uint64_t, "u", "Backend connections success") -MAC_STAT(backend_fail, uint64_t, "u", "Backend connections failures") -MAC_STAT(backend_reuse, uint64_t, "u", "Backend connections reuses") -MAC_STAT(backend_recycle, uint64_t, "u", "Backend connections recycles") -MAC_STAT(backend_unused, uint64_t, "u", "Backend connections unused") +MAC_STAT(backend_conn, uint64_t, 'a', "Backend connections success") +MAC_STAT(backend_fail, uint64_t, 'a', "Backend connections failures") +MAC_STAT(backend_reuse, uint64_t, 'a', "Backend connections reuses") +MAC_STAT(backend_recycle, uint64_t, 'a', "Backend connections recycles") +MAC_STAT(backend_unused, uint64_t, 'a', "Backend connections unused") -MAC_STAT(n_srcaddr, uint64_t, "u", "N struct srcaddr") -MAC_STAT(n_srcaddr_act, uint64_t, "u", "N active struct srcaddr") -MAC_STAT(n_sess_mem, uint64_t, "u", "N struct sess_mem") -MAC_STAT(n_sess, uint64_t, "u", "N struct sess") -MAC_STAT(n_object, uint64_t, "u", "N struct object") -MAC_STAT(n_objecthead, uint64_t, "u", "N struct objecthead") -MAC_STAT(n_smf, uint64_t, "u", "N struct smf") -MAC_STAT(n_smf_frag, uint64_t, "u", "N small free smf") -MAC_STAT(n_smf_large, uint64_t, "u", "N large free smf") -MAC_STAT(n_vbe_conn, uint64_t, "u", "N struct vbe_conn") -MAC_STAT(n_wrk, uint64_t, "u", "N worker threads") -MAC_STAT(n_wrk_create, uint64_t, "u", "N worker threads created") -MAC_STAT(n_wrk_failed, uint64_t, "u", "N worker threads not created") -MAC_STAT(n_wrk_max, uint64_t, "u", "N worker threads limited") -MAC_STAT(n_wrk_queue, uint64_t, "u", "N queued work requests") -MAC_STAT(n_wrk_overflow, uint64_t, "u", "N overflowed work requests") -MAC_STAT(n_wrk_drop, uint64_t, "u", "N dropped work requests") +MAC_STAT(n_srcaddr, uint64_t, 'i', "N struct srcaddr") +MAC_STAT(n_srcaddr_act, uint64_t, 'i', "N active struct srcaddr") +MAC_STAT(n_sess_mem, uint64_t, 'i', "N struct sess_mem") +MAC_STAT(n_sess, uint64_t, 'i', "N struct sess") +MAC_STAT(n_object, uint64_t, 'i', "N struct object") +MAC_STAT(n_objecthead, uint64_t, 'i', "N struct objecthead") +MAC_STAT(n_smf, uint64_t, 'i', "N struct smf") +MAC_STAT(n_smf_frag, uint64_t, 'i', "N small free smf") +MAC_STAT(n_smf_large, uint64_t, 'i', "N large free smf") +MAC_STAT(n_vbe_conn, uint64_t, 'i', "N struct vbe_conn") +MAC_STAT(n_wrk, uint64_t, 'i', "N worker threads") +MAC_STAT(n_wrk_create, uint64_t, 'a', "N worker threads created") +MAC_STAT(n_wrk_failed, uint64_t, 'a', "N worker threads not created") +MAC_STAT(n_wrk_max, uint64_t, 'a', "N worker threads limited") +MAC_STAT(n_wrk_queue, uint64_t, 'a', "N queued work requests") +MAC_STAT(n_wrk_overflow, uint64_t, 'a', "N overflowed work requests") +MAC_STAT(n_wrk_drop, uint64_t, 'a', "N dropped work requests") -MAC_STAT(n_expired, uint64_t, "u", "N expired objects") -MAC_STAT(n_deathrow, uint64_t, "u", "N objects on deathrow") +MAC_STAT(n_expired, uint64_t, 'i', "N expired objects") +MAC_STAT(n_deathrow, uint64_t, 'i', "N objects on deathrow") -MAC_STAT(losthdr, uint64_t, "u", "HTTP header overflows") +MAC_STAT(losthdr, uint64_t, 'a', "HTTP header overflows") -MAC_STAT(n_objsendfile, uint64_t, "u", "Objects sent with sendfile") -MAC_STAT(n_objwrite, uint64_t, "u", "Objects sent with write") +MAC_STAT(n_objsendfile, uint64_t, 'a', "Objects sent with sendfile") +MAC_STAT(n_objwrite, uint64_t, 'a', "Objects sent with write") -MAC_STAT(s_sess, uint64_t, "u", "Total Sessions") -MAC_STAT(s_req, uint64_t, "u", "Total Requests") -MAC_STAT(s_pipe, uint64_t, "u", "Total pipe") -MAC_STAT(s_pass, uint64_t, "u", "Total pass") -MAC_STAT(s_fetch, uint64_t, "u", "Total fetch") -MAC_STAT(s_hdrbytes, uint64_t, "u", "Total header bytes") -MAC_STAT(s_bodybytes, uint64_t, "u", "Total body bytes") +MAC_STAT(s_sess, uint64_t, 'a', "Total Sessions") +MAC_STAT(s_req, uint64_t, 'a', "Total Requests") +MAC_STAT(s_pipe, uint64_t, 'a', "Total pipe") +MAC_STAT(s_pass, uint64_t, 'a', "Total pass") +MAC_STAT(s_fetch, uint64_t, 'a', "Total fetch") +MAC_STAT(s_hdrbytes, uint64_t, 'a', "Total header bytes") +MAC_STAT(s_bodybytes, uint64_t, 'a', "Total body bytes") -MAC_STAT(sess_closed, uint64_t, "u", "Session Closed") -MAC_STAT(sess_pipeline, uint64_t, "u", "Session Pipeline") -MAC_STAT(sess_readahead, uint64_t, "u", "Session Read Ahead") -MAC_STAT(sess_herd, uint64_t, "u", "Session herd") +MAC_STAT(sess_closed, uint64_t, 'a', "Session Closed") +MAC_STAT(sess_pipeline, uint64_t, 'a', "Session Pipeline") +MAC_STAT(sess_readahead, uint64_t, 'a', "Session Read Ahead") +MAC_STAT(sess_herd, uint64_t, 'a', "Session herd") -MAC_STAT(shm_records, uint64_t, "u", "SHM records") -MAC_STAT(shm_writes, uint64_t, "u", "SHM writes") -MAC_STAT(shm_cont, uint64_t, "u", "SHM MTX contention") +MAC_STAT(shm_records, uint64_t, 'a', "SHM records") +MAC_STAT(shm_writes, uint64_t, 'a', "SHM writes") +MAC_STAT(shm_cont, uint64_t, 'a', "SHM MTX contention") -MAC_STAT(sm_nreq, uint64_t, "u", "allocator requests") -MAC_STAT(sm_nobj, uint64_t, "u", "outstanding allocations") -MAC_STAT(sm_balloc, uint64_t, "u", "bytes allocated") -MAC_STAT(sm_bfree, uint64_t, "u", "bytes free") +MAC_STAT(sm_nreq, uint64_t, 'a', "allocator requests") +MAC_STAT(sm_nobj, uint64_t, 'i', "outstanding allocations") +MAC_STAT(sm_balloc, uint64_t, 'i', "bytes allocated") +MAC_STAT(sm_bfree, uint64_t, 'i', "bytes free") From des at projects.linpro.no Thu Jun 28 10:25:47 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 12:25:47 +0200 (CEST) Subject: r1588 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: <20070628102547.4EADA1EC46A@projects.linpro.no> Author: des Date: 2007-06-28 12:25:47 +0200 (Thu, 28 Jun 2007) New Revision: 1588 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/shmlog.c Log: Expose the instance name associated with the currently open VSL file. This is a bletcherous hack - the entire API needs cleaning up. Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2007-06-28 09:35:56 UTC (rev 1587) +++ trunk/varnish-cache/include/varnishapi.h 2007-06-28 10:25:47 UTC (rev 1588) @@ -56,6 +56,7 @@ int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); struct varnish_stats *VSL_OpenStats(const char *varnish_name); +const char *VSL_Name(void); extern const char *VSL_tags[256]; /* instance.c */ Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-28 09:35:56 UTC (rev 1587) +++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-28 10:25:47 UTC (rev 1588) @@ -90,6 +90,7 @@ static int vsl_fd; static struct shmloghead *vsl_lh; +static char vsl_name[PATH_MAX]; static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp); @@ -108,13 +109,13 @@ { int i; struct shmloghead slh; - char name[PATH_MAX], dirname[PATH_MAX], logname[PATH_MAX]; + char dirname[PATH_MAX], logname[PATH_MAX]; if (vsl_lh != NULL) return (0); - if (varnish_instance(varnish_name, name, - sizeof name, dirname, sizeof dirname) != 0) { + if (varnish_instance(varnish_name, vsl_name, + sizeof vsl_name, dirname, sizeof dirname) != 0) { fprintf(stderr, "Invalid instance name: %s\n", strerror(errno)); return (1); @@ -495,3 +496,9 @@ return (&vsl_lh->stats); } +const char * +VSL_Name(void) +{ + + return (vsl_name); +} From des at projects.linpro.no Thu Jun 28 10:29:27 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 12:29:27 +0200 (CEST) Subject: r1589 - trunk/varnish-cache/bin/varnishstat Message-ID: <20070628102927.A20291EC456@projects.linpro.no> Author: des Date: 2007-06-28 12:29:27 +0200 (Thu, 28 Jun 2007) New Revision: 1589 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Numerous improvements: display the instance name in the upper right corner; don't show more lines than the terminal can fit; correctly react to terminal size changes; react to Ctrl-L (redraw) and Ctrl-C / Ctrl-Q (quit). The layout code could use a cleanup, and we still fail to DTRT if the width of the terminal is less than that of our data, but this should not be a problem in daily use. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 10:25:47 UTC (rev 1588) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 10:29:27 UTC (rev 1589) @@ -31,14 +31,14 @@ * Log tailer for Varnish */ +#include +#include +#include #include -#include +#include #include -#include +#include #include -#include -#include -#include #ifndef HAVE_CLOCK_GETTIME #include "compat/clock_gettime.h" @@ -67,15 +67,18 @@ double a1, a2, a3; unsigned n1, n2, n3; time_t rt; - int i; + int ch, line; - memset(©, 0, sizeof copy); a1 = a2 = a3 = 0.0; n1 = n2 = n3 = 0; initscr(); + raw(); + noecho(); + nonl(); + intrflush(stdscr, false); erase(); lt = 0; @@ -87,18 +90,19 @@ rt = ts.tv_sec - VSL_stats->start_time; up = rt; - move(0,0); - i = 0; + move(0, 0); + printw("%*s\n", COLS - 1, VSL_Name()); + move(0, 0); if (rt > 86400) { printw("%dd+", rt / 86400); rt %= 86400; - i++; } printw("%02d:", rt / 3600); rt %= 3600; printw("%02d:", rt / 60); rt %= 60; - printw("%02d\n", rt); + printw("%02d", rt); + move(1, 0); hit = (intmax_t)VSL_stats->cache_hit - (intmax_t)copy.cache_hit; miss = (intmax_t)VSL_stats->cache_miss - @@ -115,8 +119,9 @@ printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3); printw("\n"); + line = 0; #define MAC_STAT(n, t, f, d) \ - do { \ + if (++line < LINES - 4) { \ ju = VSL_stats->n; \ if (f == 'a') { \ printw("%12ju %12.2f %12.2f %s\n", \ @@ -125,12 +130,31 @@ } else { \ printw("%12ju %12s %12s %s\n", ju, ". ", ". ", d); \ } \ - } while (0); + } #include "stat_field.h" #undef MAC_STAT lt = tt; refresh(); - sleep(delay); + timeout(delay * 1000); + switch ((ch = getch())) { + case ERR: + break; + case KEY_RESIZE: + erase(); + break; + case '\014': + redrawwin(stdscr); + refresh(); + break; + case '\003': /* Ctrl-C */ + case '\021': /* Ctrl-Q */ + case 'Q': + case 'q': + endwin(); + return; + default: + break; + } } } From des at projects.linpro.no Thu Jun 28 12:07:51 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 14:07:51 +0200 (CEST) Subject: r1590 - trunk/varnish-cache/bin/varnishstat Message-ID: <20070628120751.D42F21EC030@projects.linpro.no> Author: des Date: 2007-06-28 14:07:51 +0200 (Thu, 28 Jun 2007) New Revision: 1590 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Handle Ctrl-Z and Ctrl-T. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 10:29:27 UTC (rev 1589) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 12:07:51 UTC (rev 1590) @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -142,17 +143,24 @@ case KEY_RESIZE: erase(); break; - case '\014': + case '\014': /* Ctrl-L */ + case '\024': /* Ctrl-T */ redrawwin(stdscr); refresh(); break; case '\003': /* Ctrl-C */ + raise(SIGINT); + break; + case '\032': /* Ctrl-Z */ + raise(SIGTSTP); + break; case '\021': /* Ctrl-Q */ case 'Q': case 'q': endwin(); - return; + exit(0); default: + beep(); break; } } From des at projects.linpro.no Thu Jun 28 13:33:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 15:33:59 +0200 (CEST) Subject: r1591 - trunk/varnish-cache/bin/varnishstat Message-ID: <20070628133359.9FD471EC294@projects.linpro.no> Author: des Date: 2007-06-28 15:33:59 +0200 (Thu, 28 Jun 2007) New Revision: 1591 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Further cosmetic improvements + documentation updates Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-28 12:07:51 UTC (rev 1590) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.1 2007-06-28 13:33:59 UTC (rev 1591) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 15, 2007 +.Dd June 28, 2007 .Dt VARNISHSTAT 1 .Os .Sh NAME @@ -71,14 +71,31 @@ The columns in the main display are, from left to right: .Bl -enum .It -Total since startup +Value .It -Per-second average in the period since last update +Per-second average in the period since last update, or a period if the +value can not be averaged .It -Per-second average over process lifetime +Per-second average over process lifetime, or a period if the value can +not be averaged .It Descriptive text .El +.Pp +When using the +.Fl 1 +option, the columns in the output are, from left to right: +.Bl -enum +.It +Symbolic entry name +.It +Value +.It +Per-second average over process lifetime, or a period if the value can +not be averaged +.It +Descriptive text +.El .Sh SEE ALSO .Xr varnishd 1 , .Xr varnishhist 1 , @@ -89,8 +106,10 @@ .Sh HISTORY The .Nm -utility was developed by +utility was originally developed by .An Poul-Henning Kamp Aq phk at phk.freebsd.dk -in cooperation with Verdens Gang AS and Linpro AS. +in cooperation with Verdens Gang AS and Linpro AS, and later +substantially rewritten by +.An Dag-Erling Sm\(/orgrav Aq des at linpro.no . This manual page was written by .An Dag-Erling Sm\(/orgrav Aq des at linpro.no . Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 12:07:51 UTC (rev 1590) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-06-28 13:33:59 UTC (rev 1591) @@ -4,6 +4,7 @@ * All rights reserved. * * Author: Poul-Henning Kamp + * Author: Dag-Erling Sm?rgrav * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -80,6 +81,7 @@ noecho(); nonl(); intrflush(stdscr, false); + curs_set(0); erase(); lt = 0; @@ -91,23 +93,12 @@ rt = ts.tv_sec - VSL_stats->start_time; up = rt; - move(0, 0); - printw("%*s\n", COLS - 1, VSL_Name()); - move(0, 0); - if (rt > 86400) { - printw("%dd+", rt / 86400); - rt %= 86400; - } - printw("%02d:", rt / 3600); - rt %= 3600; - printw("%02d:", rt / 60); - rt %= 60; - printw("%02d", rt); - move(1, 0); - hit = (intmax_t)VSL_stats->cache_hit - - (intmax_t)copy.cache_hit; - miss = (intmax_t)VSL_stats->cache_miss - - (intmax_t)copy.cache_miss; + mvprintw(0, 0, "%*s", COLS - 1, VSL_Name()); + mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400, + (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60); + + hit = VSL_stats->cache_hit - copy.cache_hit; + miss = VSL_stats->cache_miss - copy.cache_miss; hit /= lt; miss /= lt; if (hit + miss != 0) { @@ -116,20 +107,20 @@ myexp(&a2, ratio, &n2, 100); myexp(&a3, ratio, &n3, 1000); } - printw("Hitrate ratio: %8u %8u %8u\n", n1, n2, n3); - printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3); - printw("\n"); + mvprintw(1, 0, "Hitrate ratio: %8u %8u %8u", n1, n2, n3); + mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f", a1, a2, a3); - line = 0; + line = 3; #define MAC_STAT(n, t, f, d) \ - if (++line < LINES - 4) { \ + if (++line < LINES) { \ ju = VSL_stats->n; \ if (f == 'a') { \ - printw("%12ju %12.2f %12.2f %s\n", \ + mvprintw(line, 0, "%12ju %12.2f %12.2f %s\n", \ ju, (ju - (intmax_t)copy.n)/lt, ju / up, d); \ copy.n = ju; \ } else { \ - printw("%12ju %12s %12s %s\n", ju, ". ", ". ", d); \ + mvprintw(line, 0, "%12ju %12s %12s %s\n", \ + ju, ". ", ". ", d); \ } \ } #include "stat_field.h" From des at projects.linpro.no Thu Jun 28 13:34:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 15:34:44 +0200 (CEST) Subject: r1592 - trunk/varnish-cache/bin/varnishtop Message-ID: <20070628133444.8B36C1EC030@projects.linpro.no> Author: des Date: 2007-06-28 15:34:44 +0200 (Thu, 28 Jun 2007) New Revision: 1592 Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am trunk/varnish-cache/bin/varnishtop/varnishtop.1 trunk/varnish-cache/bin/varnishtop/varnishtop.c Log: Rewrite to better handle both the curses case and the one-shot case. Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-06-28 13:33:59 UTC (rev 1591) +++ trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-06-28 13:34:44 UTC (rev 1592) @@ -14,4 +14,4 @@ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ - ${CURSES_LIBS} + ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.1 =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-28 13:33:59 UTC (rev 1591) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.1 2007-06-28 13:34:44 UTC (rev 1592) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 15, 2007 +.Dd June 28, 2007 .Dt VARNISHTOP 1 .Os .Sh NAME @@ -71,6 +71,8 @@ .It Fl 1 Instead of presenting of a continuously updated display, print the statistics once and exit. +Implies +.Fl d . .It Fl b Include log entries which result from communication with a backend server. @@ -98,7 +100,7 @@ .Nm will only process entries which are written to the log after it starts. -.Op Fl f +.It Fl f Sort and group only on the first field of each log entry. This is useful when displaying e.g. .Dv stataddr @@ -135,6 +137,18 @@ .It Fl x Ar tag Exclude log entries with the specified tag. .El +.Sh EXAMPLES +The following example displays a continuously updated list of the most +frequently requested URLs: +.Bd -literal +varnishtop -i RxURL +.Ed +.Pp +The following example displays a continuously updated list of the most +commonly used user agents: +.Bd -literal +varnishtop -i RxHeader -C -I \\^User-Agent +.Ed .Sh SEE ALSO .Xr varnishd 1 , .Xr varnishhist 1 , @@ -144,12 +158,10 @@ .Sh HISTORY The .Nm -utility was developed by +utility was originally developed by .An Poul-Henning Kamp Aq phk at phk.freebsd.dk -in cooperation with Verdens Gang AS and Linpro AS. +in cooperation with Verdens Gang AS and Linpro AS, and later +substantially rewritten by +.An Dag-Erling Sm\(/orgrav Aq des at linpro.no . This manual page was written by .An Dag-Erling Sm\(/orgrav Aq des at linpro.no . -.Sh BUGS -The -.Fl 1 -option currently does not work very well. Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-28 13:33:59 UTC (rev 1591) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-28 13:34:44 UTC (rev 1592) @@ -4,6 +4,7 @@ * All rights reserved. * * Author: Poul-Henning Kamp + * Author: Dag-Erling Sm?rgrav * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -61,20 +64,72 @@ /*--------------------------------------------------------------------*/ +static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; + +static int f_flag = 0; + static void -usage(void) +accumulate(const unsigned char *p) { - fprintf(stderr, "usage: varnishtop %s [-1V] [-n varnish_name]\n", VSL_USAGE); - exit(1); + struct top *tp, *tp2; + const unsigned char *q; + unsigned int u; + int i; + + // fprintf(stderr, "%*.*s\n", p[1], p[1], p + 4); + + u = 0; + q = p + 4; + for (i = 0; i < p[1]; i++, q++) { + if (f_flag && (*q == ':' || isspace(*q))) + break; + u += *q; + } + + TAILQ_FOREACH(tp, &top_head, list) { + if (tp->hash != u) + continue; + if (tp->rec[0] != p[0]) + continue; + if (tp->clen != q - p) + continue; + if (memcmp(p + 4, tp->rec + 4, q - (p + 4))) + continue; + tp->count += 1.0; + break; + } + if (tp == NULL) { + ntop++; + tp = calloc(sizeof *tp, 1); + assert(tp != NULL); + tp->hash = u; + tp->count = 1.0; + tp->clen = q - p; + TAILQ_INSERT_TAIL(&top_head, tp, list); + } + memcpy(tp->rec, p, 4 + p[1]); + while (1) { + tp2 = TAILQ_PREV(tp, tophead, list); + if (tp2 == NULL || tp2->count >= tp->count) + break; + TAILQ_REMOVE(&top_head, tp2, list); + TAILQ_INSERT_AFTER(&top_head, tp, tp2, list); + } + while (1) { + tp2 = TAILQ_NEXT(tp, list); + if (tp2 == NULL || tp2->count <= tp->count) + break; + TAILQ_REMOVE(&top_head, tp2, list); + TAILQ_INSERT_BEFORE(tp, tp2, list); + } } static void -upd(void) +update(void) { struct top *tp, *tp2; int l; double t = 0; - unsigned u = 0; static time_t last; time_t now; @@ -84,12 +139,17 @@ last = now; erase(); - l = 0; - mvprintw(0, 0, "list length %u\n", ntop); + l = 1; + mvprintw(0, 0, "%*s", COLS - 1, VSL_Name()); + mvprintw(0, 0, "list length %u", ntop); TAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { if (++l < LINES) { - printw("%10.2f %*.*s\n", - tp->count, tp->rec[1], tp->rec[1], tp->rec + 4); + int len = tp->rec[1]; + if (len > COLS - 20) + len = COLS - 20; + mvprintw(l, 0, "%9.2f %-9.9s %*.*s\n", + tp->count, VSL_tags[tp->rec[0]], + len, len, tp->rec + 4); t = tp->count; } tp->count *= .999; @@ -97,35 +157,139 @@ TAILQ_REMOVE(&top_head, tp, list); free(tp); ntop--; - u++; } } - mvprintw(0, 40, "cleaned %u\n", u); refresh(); } +static void * +accumulate_thread(void *arg) +{ + struct VSL_data *vd = arg; + + for (;;) { + unsigned char *p; + int i; + + i = VSL_NextLog(vd, &p); + if (i < 0) + break; + if (i == 0) { + usleep(50000); + continue; + } + + pthread_mutex_lock(&mtx); + accumulate(p); + pthread_mutex_unlock(&mtx); + } + return (arg); +} + +static void +do_curses(struct VSL_data *vd) +{ + pthread_t thr; + int ch; + + if (pthread_create(&thr, NULL, accumulate_thread, vd) != 0) { + fprintf(stderr, "pthread_create(): %s\n", strerror(errno)); + exit(1); + } + + initscr(); + raw(); + noecho(); + nonl(); + intrflush(stdscr, false); + curs_set(0); + erase(); + for (;;) { + pthread_mutex_lock(&mtx); + update(); + pthread_mutex_unlock(&mtx); + + timeout(1000); + switch ((ch = getch())) { + case ERR: + break; + case KEY_RESIZE: + erase(); + break; + case '\014': /* Ctrl-L */ + case '\024': /* Ctrl-T */ + redrawwin(stdscr); + refresh(); + break; + case '\003': /* Ctrl-C */ + raise(SIGINT); + break; + case '\032': /* Ctrl-Z */ + endwin(); + raise(SIGTSTP); + break; + case '\021': /* Ctrl-Q */ + case 'Q': + case 'q': + endwin(); + return; + default: + beep(); + break; + } + } +} + +static void +dump(void) +{ + struct top *tp, *tp2; + int len; + + TAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { + if (tp->count <= 1.0) + break; + len = tp->rec[1]; + printf("%9.2f %*.*s\n", tp->count, len, len, tp->rec + 4); + } +} + +static void +do_once(struct VSL_data *vd) +{ + unsigned char *p; + + while (VSL_NextLog(vd, &p) > 0) + accumulate(p); + dump(); +} + +static void +usage(void) +{ + fprintf(stderr, "usage: varnishtop %s [-1fV] [-n varnish_name]\n", VSL_USAGE); + exit(1); +} + int main(int argc, char **argv) { - int i, c; - unsigned char *p, *q; struct VSL_data *vd; - unsigned u, v; - struct top *tp, *tp2; - int f_flag = 0; const char *n_arg = NULL; + int i, o, once = 0; vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) { - i = VSL_Arg(vd, c, optarg); + while ((o = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) { + i = VSL_Arg(vd, o, optarg); if (i < 0) exit (1); if (i > 0) continue; - switch (c) { + switch (o) { case '1': - VSL_NonBlocking(vd, 1); + VSL_Arg(vd, 'd', NULL); + once = 1; break; case 'n': n_arg = optarg; @@ -144,64 +308,11 @@ if (VSL_OpenLog(vd, n_arg)) exit (1); - initscr(); - v = 0; - while (1) { - i = VSL_NextLog(vd, &p); - if (i < 0) - break; - if (i == 0) { - upd(); - usleep(50000); - continue; - } - if (++v > 100) { - upd(); - v = 0; - } - u = 0; - q = p + 4; - for (i = 0; i < p[1]; i++, q++) { - if (f_flag && (*q == ':' || isspace(*q))) - break; - u += *q; - } - TAILQ_FOREACH(tp, &top_head, list) { - if (tp->hash != u) - continue; - if (tp->rec[0] != p[0]) - continue; - if (tp->clen != q - p) - continue; - if (memcmp(p + 4, tp->rec + 4, q - (p + 4))) - continue; - tp->count += 1.0; - break; - } - if (tp == NULL) { - ntop++; - tp = calloc(sizeof *tp, 1); - assert(tp != NULL); - tp->hash = u; - tp->count = 1.0; - tp->clen = q - p; - TAILQ_INSERT_TAIL(&top_head, tp, list); - } - memcpy(tp->rec, p, 4 + p[1]); - while (1) { - tp2 = TAILQ_PREV(tp, tophead, list); - if (tp2 == NULL || tp2->count >= tp->count) - break; - TAILQ_REMOVE(&top_head, tp2, list); - TAILQ_INSERT_AFTER(&top_head, tp, tp2, list); - } - while (1) { - tp2 = TAILQ_NEXT(tp, list); - if (tp2 == NULL || tp2->count <= tp->count) - break; - TAILQ_REMOVE(&top_head, tp2, list); - TAILQ_INSERT_BEFORE(tp, tp2, list); - } + if (once) { + VSL_NonBlocking(vd, 1); + do_once(vd); + } else { + do_curses(vd); } exit(0); } From des at projects.linpro.no Thu Jun 28 15:10:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 28 Jun 2007 17:10:24 +0200 (CEST) Subject: r1593 - trunk/varnish-cache/bin/varnishhist Message-ID: <20070628151024.5B0981EC294@projects.linpro.no> Author: des Date: 2007-06-28 17:10:24 +0200 (Thu, 28 Jun 2007) New Revision: 1593 Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am trunk/varnish-cache/bin/varnishhist/varnishhist.1 trunk/varnish-cache/bin/varnishhist/varnishhist.c Log: Almost complete rewrite to address a number of interface issues. Most importantly, the display will now dynamically scale when the terminal is resized, and will be updated regularly regardless of the rate at which log data arrive. Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-06-28 13:34:44 UTC (rev 1592) +++ trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-06-28 15:10:24 UTC (rev 1593) @@ -15,4 +15,4 @@ $(top_builddir)/lib/libcompat/libcompat.a \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ - ${CURSES_LIBS} + ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.1 =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-28 13:34:44 UTC (rev 1592) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.1 2007-06-28 15:10:24 UTC (rev 1593) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 15, 2007 +.Dd June 28, 2007 .Dt VARNISHHIST 1 .Os .Sh NAME @@ -54,7 +54,13 @@ utility reads .Xr varnishd 1 shared memory logs and presents a continuously updated histogram -showing the distribution of requests by their processing time. +showing the distribution of the last +.Va N +requests by their processing. +The value of +.Va N +and the vertical scale are displayed in the top left corner. +The horizontal scale is logarithmic. Hits are marked with a pipe character ("|"), and misses are marked with a hash character ("#"). .Pp Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-28 13:34:44 UTC (rev 1592) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-06-28 15:10:24 UTC (rev 1593) @@ -4,6 +4,7 @@ * All rights reserved. * * Author: Poul-Henning Kamp + * Author: Dag-Erling Sm?rgrav * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,81 +34,113 @@ #include #include +#include #include +#include #include #include #include #include #include #include -#include #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" -#define HIST_LOW -50 -#define HIST_HIGH 25 -#define HIST_W (1 + (HIST_HIGH - HIST_LOW)) -#define HIST_N 2000 +#define HIST_N 2000 /* how far back we remember */ +#define HIST_LOW -6 /* low end of log range */ +#define HIST_HIGH 3 /* high end of log range */ +#define HIST_RANGE (HIST_HIGH - HIST_LOW) +#define HIST_RES 100 /* bucket resolution */ +#define HIST_BUCKETS (HIST_RANGE * HIST_RES) +static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; + static int delay = 1; -static volatile sig_atomic_t redraw; -static char rr_hist[HIST_N]; +static unsigned rr_hist[HIST_N]; +static unsigned nhist; static unsigned next_hist; -static unsigned bucket_miss[HIST_W]; -static unsigned bucket_hit[HIST_W]; -static unsigned char hh[65536]; -static double scale = 10; -static double c_hist; +static unsigned bucket_miss[HIST_BUCKETS]; +static unsigned bucket_hit[HIST_BUCKETS]; +static unsigned char hh[FD_SETSIZE]; -static void -sigalrm(int sig) -{ +static double log_ten; - (void)sig; - redraw = 1; -} +static int scales[] = { + 1, + 2, + 3, + 4, + 5, + 10, + 15, + 20, + 25, + 50, + 100, + 250, + 500, + 1000, + 2500, + 5000, + 10000, + 25000, + 50000, + 100000, + INT_MAX +}; static void -r_hist(void) +update(void) { - int x, y; - double m, r; + int w = COLS / HIST_RANGE; + int n = w * HIST_RANGE; + unsigned bm[n], bh[n]; + unsigned max; + int i, j, scale; - m = 0; - r = 0; - for (x = 1; x < HIST_W; x++) { - if (bucket_hit[x] + bucket_miss[x] > m) - m = bucket_hit[x] + bucket_miss[x]; - r += bucket_hit[x]; - r += bucket_miss[x]; + erase(); + + /* Draw horizontal axis */ + w = COLS / HIST_RANGE; + n = w * HIST_RANGE; + for (i = 0; i < n; ++i) + mvaddch(LINES - 2, i, '-'); + for (i = 0, j = HIST_LOW; i < HIST_RANGE; ++i, ++j) { + mvaddch(LINES - 2, w * i, '+'); + mvprintw(LINES - 1, w * i, "|1e%d", j); } - while (m > HIST_N / scale) - scale--; + mvprintw(0, 0, "%*s", COLS - 1, VSL_Name()); - mvprintw(0, 0, "Max %.0f Scale %.0f Tot: %.0f", m, HIST_N / scale, r); - m = (HIST_N / scale) / (LINES - 3); - move(1,0); - for (y = LINES - 3; y > 0; y--) { - if (y == 1) - r = 0; - else - r = y * m; - for (x = 0; x < HIST_W; x++) { - if (bucket_miss[x] > r) - addch('#'); - else if (bucket_hit[x] + bucket_miss[x] > r) - addch('|'); - else - addch(' '); - } - addch('\n'); + /* count our flock */ + for (i = 0; i < n; ++i) + bm[i] = bh[i] = 0; + for (i = 0, max = 1; i < HIST_BUCKETS; ++i) { + j = i * n / HIST_BUCKETS; + bm[j] += bucket_miss[i]; + bh[j] += bucket_hit[i]; + if (bm[j] + bh[j] > max) + max = bm[j] + bh[j]; } + + /* scale */ + for (i = 0; max / scales[i] > LINES - 3; ++i) + /* nothing */ ; + scale = scales[i]; + + mvprintw(0, 0, "1:%d, n = %d", scale, nhist); + + /* show them */ + for (i = 0; i < n; ++i) { + for (j = 0; j < bm[i] / scale; ++j) + mvaddch(LINES - 3 - j, i, '#'); + for (; j < (bm[i] + bh[i]) / scale; ++j) + mvaddch(LINES - 3 - j, i, '|'); + } + refresh(); - redraw = 0; - alarm(delay); } static int @@ -117,38 +150,55 @@ int i, j; (void)priv; - (void)fd; (void)len; (void)spec; + + if (fd >= FD_SETSIZE) + /* oops */ + return (0); + if (tag == SLT_Hit) { hh[fd] = 1; return (0); } if (tag != SLT_ReqEnd) return (0); + + /* determine processing time */ #if 1 i = sscanf(ptr, "%*d %*f %*f %*f %lf", &b); #else i = sscanf(ptr, "%*d %*f %*f %lf", &b); #endif assert(i == 1); - i = log(b) * c_hist; - if (i < HIST_LOW) - i = HIST_LOW; - if (i > HIST_HIGH) - i = HIST_HIGH; - i -= HIST_LOW; - assert(i < HIST_W); - j = rr_hist[next_hist]; - if (j < 0) { - assert(bucket_miss[-j] > 0); - bucket_miss[-j]--; + /* select bucket */ + i = HIST_RES * (log(b) / log_ten); + if (i < HIST_LOW * HIST_RES) + i = HIST_LOW * HIST_RES; + if (i >= HIST_HIGH * HIST_RES) + i = HIST_HIGH * HIST_RES - 1; + i -= HIST_LOW * HIST_RES; + assert(i >= 0); + assert(i < HIST_BUCKETS); + + pthread_mutex_lock(&mtx); + + /* phase out old data */ + if (nhist == HIST_N) { + j = rr_hist[next_hist]; + if (j < 0) { + assert(bucket_miss[-j] > 0); + bucket_miss[-j]--; + } else { + assert(bucket_hit[j] > 0); + bucket_hit[j]--; + } } else { - assert(bucket_hit[j] > 0); - bucket_hit[j]--; + ++nhist; } + /* phase in new data */ if (hh[fd] || i == 0) { bucket_hit[i]++; rr_hist[next_hist] = i; @@ -160,11 +210,82 @@ next_hist = 0; } hh[fd] = 0; - if (redraw) - r_hist(); + + pthread_mutex_unlock(&mtx); + return (0); } +static void * +accumulate_thread(void *arg) +{ + struct VSL_data *vd = arg; + int i; + + for (;;) { + i = VSL_Dispatch(vd, h_hist, NULL); + if (i < 0) + break; + if (i == 0) + usleep(50000); + } + return (arg); +} + +static void +do_curses(struct VSL_data *vd) +{ + pthread_t thr; + int ch; + + if (pthread_create(&thr, NULL, accumulate_thread, vd) != 0) { + fprintf(stderr, "pthread_create(): %s\n", strerror(errno)); + exit(1); + } + + initscr(); + raw(); + noecho(); + nonl(); + intrflush(stdscr, false); + curs_set(0); + erase(); + for (;;) { + pthread_mutex_lock(&mtx); + update(); + pthread_mutex_unlock(&mtx); + + timeout(delay * 1000); + switch ((ch = getch())) { + case ERR: + break; + case KEY_RESIZE: + erase(); + break; + case '\014': /* Ctrl-L */ + case '\024': /* Ctrl-T */ + redrawwin(stdscr); + refresh(); + break; + case '\003': /* Ctrl-C */ + raise(SIGINT); + break; + case '\032': /* Ctrl-Z */ + endwin(); + raise(SIGTSTP); + break; + case '\021': /* Ctrl-Q */ + case 'Q': + case 'q': + endwin(); + return; + default: + beep(); + break; + } + } +} + /*--------------------------------------------------------------------*/ static void @@ -178,14 +299,14 @@ int main(int argc, char **argv) { - int i, c, x; + int o; struct VSL_data *vd; const char *n_arg = NULL; vd = VSL_New(); - while ((c = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) { - switch (c) { + while ((o = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) { + switch (o) { case 'n': n_arg = optarg; break; @@ -196,38 +317,17 @@ delay = atoi(optarg); break; default: - if (VSL_Arg(vd, c, optarg) > 0) + if (VSL_Arg(vd, o, optarg) > 0) break; usage(); } } if (VSL_OpenLog(vd, n_arg)) - exit (1); + exit(1); - c_hist = 10.0 / log(10.0); - initscr(); - erase(); + log_ten = log(10.0); - bucket_hit[0] = HIST_N; - move(LINES - 2, 0); - for (x = 0; x < HIST_W; x++) - addch('-'); - - for (x = 0; x < HIST_W; x++) { - if ((x + HIST_LOW) % 10 != 0) - continue; - mvprintw(LINES - 2, x, "+"); - mvprintw(LINES - 1, x, "|1e%d", (x + HIST_LOW) / 10); - } - - signal(SIGALRM, sigalrm); - redraw = 1; - while (1) { - i = VSL_Dispatch(vd, h_hist, NULL); - if (i < 0) - break; - } - + do_curses(vd); exit(0); } From des at projects.linpro.no Fri Jun 29 08:20:36 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 10:20:36 +0200 (CEST) Subject: r1594 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070629082036.E5E331EC3F9@projects.linpro.no> Author: des Date: 2007-06-29 10:20:36 +0200 (Fri, 29 Jun 2007) New Revision: 1594 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Whitespace cleanup Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-28 15:10:24 UTC (rev 1593) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 08:20:36 UTC (rev 1594) @@ -27,7 +27,7 @@ * * $Id$ */ - + #include #include #include @@ -126,7 +126,7 @@ struct vss_addr *tap; char *addr, *port; int i, n; - + XXXAZ(VSS_parse(address, &addr, &port)); XXXAN(n = VSS_resolve(addr, port, &ta)); free(addr); @@ -141,8 +141,8 @@ } tap = ta[0]; free(ta); - - return tap; + + return tap; } /* Read a line from the socket and return the number of bytes read. @@ -176,7 +176,7 @@ nbuf += i; if (buf[nbuf-2] == '\r' && buf[nbuf-1] == '\n') break; - + } buf[nbuf] = '\0'; *line = buf; @@ -192,11 +192,11 @@ { char *buf; int n, nbuf; - + buf = malloc(length); nbuf = 0; while (nbuf < length) { - n = read(sock, buf + nbuf, + n = read(sock, buf + nbuf, (2048 < length - nbuf ? 2048 : length - nbuf)); if (n <= 0) { perror("failed reading the block\n"); @@ -205,7 +205,7 @@ nbuf += n; } free(buf); - return nbuf; + return nbuf; } /* Receive the response after sending a request. @@ -223,35 +223,35 @@ int n; long block_len; int status; - + /* Read header */ while (1) { line_len = read_line(&line); end = line + line_len; - + if (*line == '\r' && *(line + 1) == '\n') { free(line); break; } - + if (strncmp(line, "HTTP", 4) == 0) { sscanf(line, "%*s %d %*s\r\n", &status); req_failed = (status != 200); } else if (isprefix(line, "content-length:", end, &next)) content_length = strtol(next, &end, 10); - else if (isprefix(line, "encoding:", end, &next) || + else if (isprefix(line, "encoding:", end, &next) || isprefix(line, "transfer-encoding:", end, &next)) chunked = (strstr(next, "chunked") != NULL); else if (isprefix(line, "connection:", end, &next)) close_connection = (strstr(next, "close") != NULL); - + free(line); } - + if (debug) fprintf(stderr, "status: %d\n", status); - - + + /* Read body */ if (content_length > 0 && !chunked) { /* Fixed body size, read content_length bytes */ @@ -378,7 +378,7 @@ if (!rp->bogus) { fo = priv; - + /* If the method is supported (GET or HEAD), send the request out * on the socket. If the socket needs reopening, reopen it first. * When the request is sent, call the function for receiving @@ -388,7 +388,7 @@ if (reopen) sock = VSS_connect(adr_info); reopen = 0; - + if (debug) { fprintf(fo, "%s ", rp->df_m); fprintf(fo, "%s ", rp->df_Uq); @@ -403,10 +403,10 @@ write(sock, rp->df_H, strlen(rp->df_H)); write(sock, " ", 1); write(sock, "\r\n", 2); - + if (strncmp(rp->df_H, "HTTP/1.0", 8)) reopen = 1; - + write(sock, "Host: ", 6); if (rp->df_Host) { if (debug) @@ -444,7 +444,7 @@ freez(rp->df_c); #undef freez rp->bogus = 0; - + return (0); } @@ -470,7 +470,7 @@ last = *buf; } close(sock); - + } /*--------------------------------------------------------------------*/ @@ -512,7 +512,7 @@ break; case 't': /* This option is for testing only. The test file must contain - * a sequence of valid HTTP-requests that can be sent + * a sequence of valid HTTP-requests that can be sent * unchanged to the adress given with -a */ test_file = optarg; @@ -523,12 +523,12 @@ usage(); } } - + if (test_file != NULL) { send_test_request(test_file, address); exit(0); } - + if (address == NULL) { usage(); } @@ -538,7 +538,7 @@ ofn = "stdout"; of = stdout; - + adr_info = init_connection(address); reopen = 1; @@ -551,4 +551,3 @@ exit(0); } - From des at projects.linpro.no Fri Jun 29 10:03:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 12:03:55 +0200 (CEST) Subject: r1595 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070629100355.886BD1EC28F@projects.linpro.no> Author: des Date: 2007-06-29 12:03:55 +0200 (Fri, 29 Jun 2007) New Revision: 1595 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Fix some style nits and an out-of-bounds array dereference. Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 08:20:36 UTC (rev 1594) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 10:03:55 UTC (rev 1595) @@ -119,20 +119,23 @@ * hostname and returning a struct with necessary * connection info. */ -static struct vss_addr* -init_connection(const char* address) +static struct vss_addr * +init_connection(const char *address) { struct vss_addr **ta; struct vss_addr *tap; char *addr, *port; int i, n; - XXXAZ(VSS_parse(address, &addr, &port)); - XXXAN(n = VSS_resolve(addr, port, &ta)); + if (VSS_parse(address, &addr, &port) != 0) { + fprintf(stderr, "Invalid address\n"); + exit(2); + } + n = VSS_resolve(addr, port, &ta); free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not open TELNET port\n"); + fprintf(stderr, "Could not connect to server\n"); exit(2); } for (i = 1; i < n; ++i) { @@ -174,7 +177,7 @@ exit(1); } nbuf += i; - if (buf[nbuf-2] == '\r' && buf[nbuf-1] == '\n') + if (nbuf >= 2 && buf[nbuf-2] == '\r' && buf[nbuf-1] == '\n') break; } From des at projects.linpro.no Fri Jun 29 10:04:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 12:04:12 +0200 (CEST) Subject: r1596 - trunk/varnish-cache/bin/varnishtop Message-ID: <20070629100412.D76691EC030@projects.linpro.no> Author: des Date: 2007-06-29 12:04:12 +0200 (Fri, 29 Jun 2007) New Revision: 1596 Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c Log: Simplify. Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-29 10:03:55 UTC (rev 1595) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-06-29 10:04:12 UTC (rev 1596) @@ -276,16 +276,11 @@ { struct VSL_data *vd; const char *n_arg = NULL; - int i, o, once = 0; + int o, once = 0; vd = VSL_New(); while ((o = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) { - i = VSL_Arg(vd, o, optarg); - if (i < 0) - exit (1); - if (i > 0) - continue; switch (o) { case '1': VSL_Arg(vd, 'd', NULL); @@ -301,6 +296,8 @@ varnish_version("varnishtop"); exit(0); default: + if (VSL_Arg(vd, o, optarg) > 0) + break; usage(); } } From des at projects.linpro.no Fri Jun 29 10:04:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 12:04:42 +0200 (CEST) Subject: r1597 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070629100442.021461EC28F@projects.linpro.no> Author: des Date: 2007-06-29 12:04:41 +0200 (Fri, 29 Jun 2007) New Revision: 1597 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Simplify. Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 10:04:12 UTC (rev 1596) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 10:04:41 UTC (rev 1597) @@ -501,11 +501,6 @@ debug = 0; while ((c = getopt(argc, argv, "a:Dr:t:")) != -1) { - i = VSL_Arg(vd, c, optarg); - if (i < 0) - exit (1); - if (i > 0) - continue; switch (c) { case 'a': address = optarg; From des at projects.linpro.no Fri Jun 29 10:15:10 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 12:15:10 +0200 (CEST) Subject: r1598 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070629101510.643761EC030@projects.linpro.no> Author: des Date: 2007-06-29 12:15:10 +0200 (Fri, 29 Jun 2007) New Revision: 1598 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Oops! Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 10:04:41 UTC (rev 1597) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-06-29 10:15:10 UTC (rev 1598) @@ -489,7 +489,7 @@ int main(int argc, char *argv[]) { - int i, c; + int c; struct VSL_data *vd; const char *ofn = NULL; const char *address = NULL; From des at projects.linpro.no Fri Jun 29 12:54:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 14:54:25 +0200 (CEST) Subject: r1599 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070629125425.2A1031EC28F@projects.linpro.no> Author: des Date: 2007-06-29 14:54:24 +0200 (Fri, 29 Jun 2007) New Revision: 1599 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Run varnishd with the smallest allowable storage file. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-29 10:15:10 UTC (rev 1598) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-06-29 12:54:24 UTC (rev 1599) @@ -59,6 +59,7 @@ %config = ('server_address' => 'localhost:8081', 'varnish_address' => 'localhost:8080', + 'storage_spec' => 'file,/tmp/regress.bin,512k', %config); my $self = bless({ 'mux' => IO::Multiplex->new, Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-29 10:15:10 UTC (rev 1598) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-06-29 12:54:24 UTC (rev 1599) @@ -95,6 +95,7 @@ close STDERR_WRITE; my @opts = ('-d', '-d', + '-s', $engine->{'config'}->{'storage_spec'}, '-a', $engine->{'config'}->{'varnish_address'}, '-b', $engine->{'config'}->{'server_address'}); From des at projects.linpro.no Fri Jun 29 12:56:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 14:56:44 +0200 (CEST) Subject: r1600 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070629125644.65B191EC030@projects.linpro.no> Author: des Date: 2007-06-29 14:56:44 +0200 (Fri, 29 Jun 2007) New Revision: 1600 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm Log: Shut down the client before returning. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-29 12:54:24 UTC (rev 1599) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-29 12:56:44 UTC (rev 1600) @@ -63,6 +63,8 @@ $response->protocol, $sv) if $response->protocol ne $sv; + $client->shutdown(); + return sprintf("Client: %s Server: %s", $cv, $sv); } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-29 12:54:24 UTC (rev 1599) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-29 12:56:44 UTC (rev 1600) @@ -63,6 +63,8 @@ if $response->content ne $body; } + $client->shutdown(); + return 'OK'; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-29 12:54:24 UTC (rev 1599) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-06-29 12:56:44 UTC (rev 1600) @@ -57,6 +57,9 @@ die "Incorrect body\n" if $response->content() ne $languages{$lang}; } + + $client->shutdown(); + return 'OK'; } sub ev_server_request($$$$) { From des at projects.linpro.no Fri Jun 29 12:57:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 14:57:55 +0200 (CEST) Subject: r1601 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070629125755.B50B51EC515@projects.linpro.no> Author: des Date: 2007-06-29 14:57:55 +0200 (Fri, 29 Jun 2007) New Revision: 1601 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm Log: Add a regression test for the LRU. Currently, it tests that the child does not crash when the cache fills up, and that a request for a document that ought to have been evicted does not result in a cache hit. Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-06-29 12:57:55 UTC (rev 1601) @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# 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$ +# + +package Varnish::Test::Case::LRU; + +use strict; +use base 'Varnish::Test::Case'; + +use Data::Dumper; + +# Number of repetitions; total size of data set will be approximately +# (25 * $repeat * $repeat), and needs to be larger than the size of +# the storage file for the test to be meaningful. +our $repeat = 256; + +sub _testLRU($$) { + my ($self, $n) = @_; + + my $client = $self->new_client(); + my $uri = "/Varnish/Test/Case/LRU/$n"; + my $request = HTTP::Request->new('GET', $uri); + $request->protocol('HTTP/1.1'); + $client->send_request($request, 2); + my ($event, $response) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Timed out\n" + if ($event eq 'ev_client_timeout'); + die "No (complete) response received\n" + unless defined($response); + die "Empty body\n" + if $response->content() eq ''; + die "Incorrect body\n" + if $response->content() !~ m/^(?:\Q$uri\E){$repeat}$/; + $client->shutdown(); + return $response; +} + +sub testLRU($) { + my ($self) = @_; + + # Send $repeat requests in an attempt to eat through the entire + # storage file. + # + # XXX We should check to see if the child dies while we do this. + # XXX Currently, we will most likely get a client_timeout when + # XXX testing a pre-LRU version of Varnish. + for (my $n = 0; $n < $repeat; ++$n) { + $self->_testLRU($n); + } + + # Redo the first request; if we get a cached response (indicated + # by a second XID in X-Varnish), the test is inconclusive and + # needs to be re-run with either a smaller storage file or a + # larger value for $repeat. + my $response = $self->_testLRU(0); + die "Inconclusive test\n" + unless $response->header("X-Varnish") =~ m/^(\d+)$/; + + return 'OK'; +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + + my $body = $request->uri() x $repeat; + my $response = HTTP::Response->new(200, undef, + [ 'Content-Type', 'text/plain', + 'Content-Length', length($body) ], + $body); + $response->protocol('HTTP/1.1'); + $connection->send_response($response); +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Fri Jun 29 14:05:22 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 16:05:22 +0200 (CEST) Subject: r1602 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070629140522.048451EC030@projects.linpro.no> Author: des Date: 2007-06-29 16:05:21 +0200 (Fri, 29 Jun 2007) New Revision: 1602 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm Log: Add an usleep() method based on select(). Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-29 12:57:55 UTC (rev 1601) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-29 14:05:21 UTC (rev 1602) @@ -188,4 +188,10 @@ return $client; } +sub usleep($$) { + my ($self, $usec) = @_; + + select(undef, undef, undef, $usec / 1000000.0); +} + 1; From des at projects.linpro.no Fri Jun 29 14:05:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 29 Jun 2007 16:05:50 +0200 (CEST) Subject: r1603 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070629140550.021FE1EC515@projects.linpro.no> Author: des Date: 2007-06-29 16:05:49 +0200 (Fri, 29 Jun 2007) New Revision: 1603 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm Log: Greatly improve this test; see $DESCR + comments for details. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-06-29 14:05:21 UTC (rev 1602) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-06-29 14:05:49 UTC (rev 1603) @@ -33,18 +33,24 @@ use strict; use base 'Varnish::Test::Case'; -use Data::Dumper; +our $prefix = __PACKAGE__; # Number of repetitions; total size of data set will be approximately # (25 * $repeat * $repeat), and needs to be larger than the size of # the storage file for the test to be meaningful. our $repeat = 256; +our $DESCR = "Tests the LRU code by running more data through Varnish" . + " than the cache can hold, while simultaneously repeatedly requesting" . + " one particular object, which should remain in cache throughout. The" . + " total amount of space consumed is approximately $repeat * round(" . + ((length(__PACKAGE__) + 5) * $repeat) . ", PAGE_SIZE)."; + sub _testLRU($$) { my ($self, $n) = @_; my $client = $self->new_client(); - my $uri = "/Varnish/Test/Case/LRU/$n"; + my $uri = __PACKAGE__ . "::$n"; my $request = HTTP::Request->new('GET', $uri); $request->protocol('HTTP/1.1'); $client->send_request($request, 2); @@ -65,21 +71,36 @@ sub testLRU($) { my ($self) = @_; + my $response = $self->_testLRU(0); + die "Invalid X-Varnish in response" + unless $response->header("X-Varnish") =~ m/^(\d+)$/; + my $xid0 = $1; + # Send $repeat requests in an attempt to eat through the entire - # storage file. + # storage file. Keep one object hot throughout. # - # XXX We should check to see if the child dies while we do this. - # XXX Currently, we will most likely get a client_timeout when - # XXX testing a pre-LRU version of Varnish. - for (my $n = 0; $n < $repeat; ++$n) { + #XXX We should check to see if the child dies while we do this. + #XXX Currently, when testing a pre-LRU version of Varnish, we will + #XXX most likely get a client timeout and the test framework will + #XXX get stuck. + for (my $n = 1; $n < $repeat; ++$n) { + # cold object $self->_testLRU($n); + + # Slow down! If we run through the cache faster than the + # hysteresis in the LRU code, the hot object will be evicted. + $self->usleep(100000); + + # hot object + $response = $self->_testLRU(0); + die "Cache miss on hot object" + unless $response->header("X-Varnish") =~ m/^(\d+)\s+($xid0)$/o; } - # Redo the first request; if we get a cached response (indicated - # by a second XID in X-Varnish), the test is inconclusive and - # needs to be re-run with either a smaller storage file or a - # larger value for $repeat. - my $response = $self->_testLRU(0); + # Re-request an object which should have been evicted. If we get + # a cache hit, the test is inconclusive and needs to be re-run + # with a smaller storage file or a larger value of $repeat. + $response = $self->_testLRU(1); die "Inconclusive test\n" unless $response->header("X-Varnish") =~ m/^(\d+)$/; @@ -92,7 +113,8 @@ my $body = $request->uri() x $repeat; my $response = HTTP::Response->new(200, undef, [ 'Content-Type', 'text/plain', - 'Content-Length', length($body) ], + 'Content-Length', length($body), + 'Cache-Control', 'max-age=3600', ], $body); $response->protocol('HTTP/1.1'); $connection->send_response($response);