#include <string.h>
#include <unistd.h>
+#ifndef HAVE_DAEMON
+#include "compat/daemon.h"
+#endif
+
+#ifdef HAVE_VIS_H
+#include <vis.h>
+#else
#include "compat/vis.h"
+#endif
#include "vsb.h"
+#include "vpf.h"
#include "libvarnish.h"
#include "shmlog.h"
#include "varnishapi.h"
-static int bflag, cflag;
+static int b_flag, c_flag;
/* -------------------------------------------------------------------*/
(void)priv;
if (!(spec & (VSL_S_CLIENT|VSL_S_BACKEND))) {
- if (!bflag && !cflag)
+ if (!b_flag && !c_flag)
VSL_H_Print(stdout, tag, fd, len, spec, ptr);
return (0);
}
exit (2);
}
}
- if (!bflag) {
+ if (!b_flag) {
VSL_Select(vd, SLT_SessionOpen);
VSL_Select(vd, SLT_SessionClose);
VSL_Select(vd, SLT_ReqEnd);
}
- if (!cflag) {
+ if (!c_flag) {
VSL_Select(vd, SLT_BackendOpen);
VSL_Select(vd, SLT_BackendClose);
VSL_Select(vd, SLT_BackendReuse);
usage(void)
{
fprintf(stderr,
- "usage: varnishlog %s [-aoV] [-w file]\n", VSL_USAGE);
+ "usage: varnishlog %s [-aDoV] [-P file] [-w file]\n", VSL_USAGE);
exit(1);
}
main(int argc, char **argv)
{
int i, c;
- int a_flag = 0, o_flag = 0;
- char *w_opt = NULL;
+ int a_flag = 0, D_flag = 0, o_flag = 0;
+ const char *P_opt = NULL;
+ const char *w_opt = NULL;
+ struct pidfh *pfh = NULL;
struct VSL_data *vd;
vd = VSL_New();
- while ((c = getopt(argc, argv, VSL_ARGS "aoVw:")) != -1) {
+ while ((c = getopt(argc, argv, VSL_ARGS "aDoP:Vw:")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
break;
+ case 'D':
+ D_flag = 1;
+ break;
case 'o':
o_flag = 1;
break;
+ case 'P':
+ P_opt = optarg;
+ break;
case 'V':
varnish_version("varnishlog");
exit(0);
w_opt = optarg;
break;
case 'c':
- cflag = 1;
+ c_flag = 1;
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
case 'b':
- bflag = 1;
+ b_flag = 1;
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
usage();
if (VSL_OpenLog(vd))
- exit (1);
+ exit(1);
+
+ if (P_opt && (pfh = vpf_open(P_opt, 0600, NULL)) == NULL) {
+ perror(P_opt);
+ exit(1);
+ }
+
+ if (D_flag && daemon(0, 0) == -1) {
+ perror("daemon()");
+ if (pfh != NULL)
+ vpf_remove(pfh);
+ exit(1);
+ }
+
+ if (pfh != NULL)
+ vpf_write(pfh);
if (w_opt != NULL)
do_write(vd, w_opt, a_flag);
break;
}
+ if (pfh != NULL)
+ vpf_remove(pfh);
return (0);
}