r3622 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Thu Feb 5 13:23:06 CET 2009
Author: tfheen
Date: 2009-02-05 13:23:06 +0100 (Thu, 05 Feb 2009)
New Revision: 3622
Modified:
branches/2.0/varnish-cache/bin/varnishd/mgt.h
branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c
branches/2.0/varnish-cache/bin/varnishd/varnishd.c
branches/2.0/varnish-cache/include/libvarnish.h
branches/2.0/varnish-cache/include/libvcl.h
branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c
branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c
Log:
Merge r3415: Simplify how we manage the -f argument:
The VCL file specified to -f must be read relative to the directory
from which varnishd is started, before we chdir to the workdir.
We used to deal with this by opening the file and passing the file
handle down. It's simpler to just read the file and pass the actual
VCL code down.
Modified: branches/2.0/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-05 12:23:06 UTC (rev 3622)
@@ -58,7 +58,7 @@
/* mgt_vcc.c */
void mgt_vcc_init(void);
-int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag);
+int mgt_vcc_default(const char *bflag, char *vcl, int Cflag);
int mgt_push_vcls_and_start(unsigned *status, char **p);
int mgt_has_vcl(void);
extern char *mgt_cc_cmd;
Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:23:06 UTC (rev 3622)
@@ -201,40 +201,27 @@
/*--------------------------------------------------------------------*/
static char *
-mgt_VccCompile(struct vsb *sb, const char *b, const char *e, int C_flag)
+mgt_VccCompile(struct vsb **sb, const char *b, int C_flag)
{
char *csrc, *vf = NULL;
- csrc = VCC_Compile(sb, b, e);
- if (csrc != NULL) {
- if (C_flag)
- (void)fputs(csrc, stdout);
- vf = mgt_run_cc(csrc, sb);
- if (C_flag && vf != NULL)
- AZ(unlink(vf));
- free(csrc);
- }
- return (vf);
-}
+ *sb = vsb_newauto();
+ XXXAN(*sb);
+ csrc = VCC_Compile(*sb, b, NULL);
-static char *
-mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag, int fd)
-{
- char *csrc, *vf = NULL;
-
- csrc = VCC_CompileFile(sb, fn, fd);
if (csrc != NULL) {
if (C_flag)
(void)fputs(csrc, stdout);
- vf = mgt_run_cc(csrc, sb);
+ vf = mgt_run_cc(csrc, *sb);
if (C_flag && vf != NULL)
AZ(unlink(vf));
free(csrc);
}
+ vsb_finish(*sb);
+ AZ(vsb_overflowed(*sb));
return (vf);
}
-
/*--------------------------------------------------------------------*/
static struct vclprog *
@@ -290,16 +277,15 @@
/*--------------------------------------------------------------------*/
int
-mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag)
+mgt_vcc_default(const char *b_arg, char *vcl, int C_flag)
{
char *addr, *port;
- char *buf, *vf;
+ char *vf;
struct vsb *sb;
struct vclprog *vp;
- sb = vsb_newauto();
- XXXAN(sb);
if (b_arg != NULL) {
+ AZ(vcl);
/*
* XXX: should do a "HEAD /" on the -b argument to see that
* XXX: it even works. On the other hand, we should do that
@@ -318,26 +304,21 @@
*/
free(port);
fprintf(stderr, "invalid backend address\n");
- vsb_delete(sb);
return (1);
}
- buf = NULL;
- asprintf(&buf,
+ asprintf(&vcl,
"backend default {\n"
" .host = \"%s\";\n"
" .port = \"%s\";\n"
"}\n", addr, port ? port : "http");
free(addr);
free(port);
- AN(buf);
- vf = mgt_VccCompile(sb, buf, NULL, C_flag);
- free(buf);
- } else {
- vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd);
+ AN(vcl);
}
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+
+ vf = mgt_VccCompile(&sb, vcl, C_flag);
+ free(vcl);
if (vsb_len(sb) > 0)
fprintf(stderr, "%s", vsb_data(sb));
vsb_delete(sb);
@@ -432,11 +413,7 @@
return;
}
- sb = vsb_newauto();
- XXXAN(sb);
- vf = mgt_VccCompile(sb, av[3], NULL, 0);
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+ vf = mgt_VccCompile(&sb, av[3], 0);
if (vsb_len(sb) > 0)
cli_out(cli, "%s", vsb_data(sb));
vsb_delete(sb);
@@ -459,7 +436,7 @@
void
mcf_config_load(struct cli *cli, const char * const *av, void *priv)
{
- char *vf;
+ char *vf, *vcl;
struct vsb *sb;
unsigned status;
char *p = NULL;
@@ -473,11 +450,16 @@
return;
}
- sb = vsb_newauto();
- XXXAN(sb);
- vf = mgt_VccCompileFile(sb, av[3], 0, -1);
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+ vcl = vreadfile(av[3]);
+ if (vcl == NULL) {
+ cli_out(cli, "Cannot open '%s'", av[3]);
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
+
+ vf = mgt_VccCompile(&sb, vcl, 0);
+ free(vcl);
+
if (vsb_len(sb) > 0)
cli_out(cli, "%s", vsb_data(sb));
vsb_delete(sb);
Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 12:23:06 UTC (rev 3622)
@@ -424,14 +424,13 @@
const char *l_arg = "80m";
uintmax_t l_size;
const char *q;
- int f_fd = -1;
const char *h_arg = "classic";
const char *n_arg = NULL;
const char *P_arg = NULL;
const char *s_arg = "file";
int s_arg_given = 0;
const char *T_arg = NULL;
- char *p;
+ char *p, *vcl = NULL;
struct cli cli[1];
struct pidfh *pfh = NULL;
char dirname[1024];
@@ -567,9 +566,9 @@
}
if (f_arg != NULL) {
- f_fd = open(f_arg, O_RDONLY);
- if (f_fd < 0) {
- fprintf(stderr, "Cannot open '%s': %s\n",
+ vcl = vreadfile(f_arg);
+ if (vcl == NULL) {
+ fprintf(stderr, "Cannot read '%s': %s\n",
f_arg, strerror(errno));
exit(1);
}
@@ -606,7 +605,7 @@
}
if (b_arg != NULL || f_arg != NULL)
- if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag))
+ if (mgt_vcc_default(b_arg, vcl, C_flag))
exit (2);
if (C_flag)
Modified: branches/2.0/varnish-cache/include/libvarnish.h
===================================================================
--- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:23:06 UTC (rev 3622)
@@ -86,7 +86,7 @@
/* from libvarnish/vtmpfile.c */
int vtmpfile(char *);
-char *vreadfile(int fd);
+char *vreadfile(const char *fn);
/*
* assert(), AN() and AZ() are static checks that should not happen.
Modified: branches/2.0/varnish-cache/include/libvcl.h
===================================================================
--- branches/2.0/varnish-cache/include/libvcl.h 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/include/libvcl.h 2009-02-05 12:23:06 UTC (rev 3622)
@@ -30,7 +30,6 @@
*/
char *VCC_Compile(struct vsb *sb, const char *b, const char *e);
-char *VCC_CompileFile(struct vsb *sb, const char *fn, int fd);
void VCC_InitCompile(const char *default_vcl);
Modified: branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:23:06 UTC (rev 3622)
@@ -78,8 +78,8 @@
/* not reached */
}
-char *
-vreadfile(int fd)
+static char *
+vreadfd(int fd)
{
struct stat st;
char *f;
@@ -95,3 +95,19 @@
f[i] = '\0';
return (f);
}
+
+char *
+vreadfile(const char *fn)
+{
+ int fd, err;
+ char *r;
+
+ fd = open(fn, O_RDONLY);
+ if (fd < 0)
+ return (NULL);
+ r = vreadfd(fd);
+ err = errno;
+ AZ(close(fd));
+ errno = err;
+ return (r);
+}
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:19:35 UTC (rev 3621)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:23:06 UTC (rev 3622)
@@ -399,22 +399,17 @@
/*--------------------------------------------------------------------*/
static struct source *
-vcc_file_source(struct vsb *sb, const char *fn, int fd)
+vcc_file_source(struct vsb *sb, const char *fn)
{
char *f;
struct source *sp;
- if (fd < 0) {
- fd = open(fn, O_RDONLY);
- if (fd < 0) {
- vsb_printf(sb, "Cannot open file '%s': %s\n",
- fn, strerror(errno));
- return (NULL);
- }
+ f = vreadfile(fn);
+ if (f == NULL) {
+ vsb_printf(sb, "Cannot read file '%s': %s\n",
+ fn, strerror(errno));
+ return (NULL);
}
- f = vreadfile(fd);
- AN(f);
- AZ(close(fd));
sp = vcc_new_source(f, NULL, fn);
sp->freeit = f;
return (sp);
@@ -450,7 +445,7 @@
}
assert(t2 != NULL);
- sp = vcc_file_source(tl->sb, t1->dec, -1);
+ sp = vcc_file_source(tl->sb, t1->dec);
if (sp == NULL) {
vcc_ErrWhere(tl, t1);
return;
@@ -668,24 +663,6 @@
}
/*--------------------------------------------------------------------
- * Compile the VCL code from the file named. Error messages, if any
- * are formatted into the vsb.
- */
-
-char *
-VCC_CompileFile(struct vsb *sb, const char *fn, int fd)
-{
- struct source *sp;
- char *r;
-
- sp = vcc_file_source(sb, fn, fd);
- if (sp == NULL)
- return (NULL);
- r = vcc_CompileSource(sb, sp);
- return (r);
-}
-
-/*--------------------------------------------------------------------
* Initialize the compiler and register the default VCL code for later
* compilation runs.
*/
More information about the varnish-commit
mailing list