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

Add -D (daemonize) and -P (pid file) options.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1411 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2cea8eae
......@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
.Dd April 21, 2007
.Dd May 11, 2007
.Dt VARNISHLOG 1
.Os
.Sh NAME
......@@ -40,10 +40,12 @@
.Op Fl b
.Op Fl C
.Op Fl c
.Op Fl D
.Op Fl d
.Op Fl I Ar regex
.Op Fl i Ar tag
.Op Fl o
.Op Fl P Ar file
.Op Fl r Ar file
.Op Fl V
.Op Fl w Ar file
......@@ -82,6 +84,8 @@ nor
is specified,
.Nm
acts as if they both were.
.It Fl D
Daemonize.
.It Fl d
Process old log entries on startup.
Normally,
......@@ -107,6 +111,9 @@ Group log entries by request ID.
This has no effect when writing to a file using the
.Fl w
option.
.It Fl P Ar file
Write the process's PID to the specified
.Ar file .
.It Fl r Ar file
Read log entries from
.Ar file
......
......@@ -40,15 +40,24 @@
#include <string.h>
#include <unistd.h>
#ifndef HAVE_DAEMON
#include "compat/daemon.h"
#endif
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "compat/vis.h"
#endif
#include "vsb.h"
#include "vpf.h"
#include "libvarnish.h"
#include "shmlog.h"
#include "varnishapi.h"
static int bflag, cflag;
static int b_flag, c_flag;
/* -------------------------------------------------------------------*/
......@@ -100,7 +109,7 @@ h_order(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec
(void)priv;
if (!(spec & (VSL_S_CLIENT|VSL_S_BACKEND))) {
if (!bflag && !cflag)
if (!b_flag && !c_flag)
VSL_H_Print(stdout, tag, fd, len, spec, ptr);
return (0);
}
......@@ -179,12 +188,12 @@ do_order(struct VSL_data *vd, int argc, char **argv)
exit (2);
}
}
if (!bflag) {
if (!b_flag) {
VSL_Select(vd, SLT_SessionOpen);
VSL_Select(vd, SLT_SessionClose);
VSL_Select(vd, SLT_ReqEnd);
}
if (!cflag) {
if (!c_flag) {
VSL_Select(vd, SLT_BackendOpen);
VSL_Select(vd, SLT_BackendClose);
VSL_Select(vd, SLT_BackendReuse);
......@@ -264,7 +273,7 @@ static void
usage(void)
{
fprintf(stderr,
"usage: varnishlog %s [-aoV] [-w file]\n", VSL_USAGE);
"usage: varnishlog %s [-aDoV] [-P file] [-w file]\n", VSL_USAGE);
exit(1);
}
......@@ -272,20 +281,28 @@ int
main(int argc, char **argv)
{
int i, c;
int a_flag = 0, o_flag = 0;
char *w_opt = NULL;
int a_flag = 0, D_flag = 0, o_flag = 0;
const char *P_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);
......@@ -293,12 +310,12 @@ main(int argc, char **argv)
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();
......@@ -313,7 +330,22 @@ main(int argc, char **argv)
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);
......@@ -329,5 +361,7 @@ main(int argc, char **argv)
break;
}
if (pfh != NULL)
vpf_remove(pfh);
return (0);
}
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