Commit 237d5f1f authored by Geoff Simmons's avatar Geoff Simmons

varnishevent - bugfixes for formatting

	- read config files
	- read closing tags for *both* client and backend requests
parent 0711e54a
......@@ -109,7 +109,10 @@ CONF_Add(const char *lval, const char *rval)
confString("varnish.name", varnish_name);
confString("log.file", log_file);
confString("varnish.bindump", varnish_bindump);
confString("cformat", cformat);
confString("bformat", bformat);
confString("zformat", zformat);
confUnsigned("max.reclen", max_reclen);
confUnsigned("max.headers", max_headers);
confUnsigned("max.fd", max_fd);
......
......@@ -391,9 +391,8 @@ format_SLT(logline_t *ll, char *name, enum VSL_tag_e tag,
{
(void) name;
record_t *rec = get_hdr(name, &ll->vcl_log);
if (ll->tag[tag].len)
RETURN_REC(*rec, s, len);
RETURN_REC(ll->tag[tag], s, len);
}
static int
......@@ -462,9 +461,8 @@ compile_fmt(char *format, compiled_fmt_t *fmt, unsigned spec, char *err)
memset(fmt->tags, 0, MAX_VSL_TAG);
/* always read the closing tags for clients and backends */
if (C(spec))
if (C(spec) || B(spec)) {
ADD_TAG(fmt->tags, ReqEnd);
else if (B(spec)) {
ADD_TAG(fmt->tags, BackendReuse);
ADD_TAG(fmt->tags, BackendClose);
}
......@@ -732,11 +730,11 @@ FMT_Init(char *err)
if (compile_fmt(config.cformat, &cformat, VSL_S_CLIENT, err) != 0)
return EINVAL;
if (EMPTY(config.bformat))
if (!EMPTY(config.bformat))
if (compile_fmt(config.bformat, &bformat, VSL_S_BACKEND, err) != 0)
return EINVAL;
if (EMPTY(config.zformat))
if (!EMPTY(config.zformat))
if (compile_fmt(config.zformat, &zformat, 0, err) != 0)
return EINVAL;
......
......@@ -88,6 +88,8 @@
#include "varnishevent.h"
#define DEFAULT_CONFIG "/etc/varnishevent.conf"
typedef enum {
FD_EMPTY = 0,
FD_OPEN
......@@ -120,6 +122,8 @@ static int waiting = 0;
static char *obuf;
static char cli_config_filename[BUFSIZ] = "";
int
RDR_Waiting(void)
{
......@@ -379,6 +383,19 @@ open_log(const char *ofn, int append)
/*--------------------------------------------------------------------*/
static void
read_default_config(void) {
if (access(DEFAULT_CONFIG, F_OK) == 0) {
if (access(DEFAULT_CONFIG, R_OK) != 0) {
perror(DEFAULT_CONFIG);
exit(EXIT_FAILURE);
}
printf("Reading config from %s\n", DEFAULT_CONFIG);
if (CONF_ReadFile(DEFAULT_CONFIG) != 0)
exit(EXIT_FAILURE);
}
}
static void
usage(void)
{
......@@ -393,9 +410,8 @@ int
main(int argc, char *argv[])
{
int c, errnum;
int a_flag = 0, d_flag = 0, D_flag = 0, format_flag = 0;
const char *P_arg = NULL;
const char *w_arg = NULL;
int a_flag = 0, g_flag = 0, D_flag = 0, format_flag = 0;
const char *P_arg = NULL, *w_arg = NULL;
char scratch[BUFSIZ];
struct vpf_fh *pfh = NULL;
FILE *of;
......@@ -403,15 +419,13 @@ main(int argc, char *argv[])
vd = VSM_New();
VSL_Setup(vd);
CONF_Init();
read_default_config();
while ((c = getopt(argc, argv, VSL_ARGS "adDP:Vw:fF:")) != -1) {
while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:fF:gG:")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
break;
case 'd':
d_flag = 1;
break;
case 'f':
if (format_flag) {
fprintf(stderr, "-f and -F can not be combined\n");
......@@ -440,20 +454,18 @@ main(int argc, char *argv[])
case 'w':
w_arg = optarg;
break;
case 'b':
fprintf(stderr, "-b is not valid for varnishncsa\n");
exit(1);
case 'g':
D_flag = 1;
break;
case 'i':
fprintf(stderr, "-i is not valid for varnishncsa\n");
exit(1);
case 'G':
strcpy(cli_config_filename, optarg);
break;
case 'b':
case 'i':
case 'I':
fprintf(stderr, "-I is not valid for varnishncsa\n");
exit(1);
break;
case 'c':
/* XXX: Silently ignored: it's required anyway */
fprintf(stderr, "-%c is not valid for varnishevent\n", c);
exit(1);
break;
case 'm':
m_flag = 1; /* Fall through */
......@@ -463,6 +475,15 @@ main(int argc, char *argv[])
usage();
}
}
if (! EMPTY(cli_config_filename)) {
printf("Reading config from %s\n", cli_config_filename);
if (CONF_ReadFile(cli_config_filename) != 0) {
fprintf(stderr, "Error reading config from %s\n",
cli_config_filename);
exit(EXIT_FAILURE);
}
}
if (VSL_Open(vd, 1))
exit(1);
......@@ -493,7 +514,7 @@ main(int argc, char *argv[])
if (LOG_Open("varnishevent") != 0) {
exit(EXIT_FAILURE);
}
if (d_flag)
if (g_flag)
LOG_SetLevel(LOG_DEBUG);
LOG_Log(LOG_INFO, "initializing (%s)", VCS_version);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment