Commit 51016c37 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Add -P (pid file) option.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1415 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent a6344859
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
.Op Fl d .Op Fl d
.Op Fl f Ar config .Op Fl f Ar config
.Op Fl h Ar type Ns Op , Ns Ar options .Op Fl h Ar type Ns Op , Ns Ar options
.Op Fl P Ar file
.Op Fl p Ar param Ns = Ns Ar value .Op Fl p Ar param Ns = Ns Ar value
.Op Fl s Ar type Ns Op , Ns Ar options .Op Fl s Ar type Ns Op , Ns Ar options
.Op Fl T Ar address Ns Op : Ns Ar port .Op Fl T Ar address Ns Op : Ns Ar port
...@@ -111,6 +112,9 @@ Specifies the hash algorithm. ...@@ -111,6 +112,9 @@ Specifies the hash algorithm.
See See
.Sx Hash Algorithms .Sx Hash Algorithms
for a list of supported algorithms. for a list of supported algorithms.
.It Fl P Ar file
Write the process's PID to the specified
.Ar file .
.It Fl p Ar param Ns = Ns Ar value .It Fl p Ar param Ns = Ns Ar value
Set the parameter specified by Set the parameter specified by
.Ar param .Ar param
......
...@@ -45,7 +45,12 @@ ...@@ -45,7 +45,12 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifndef HAVE_DAEMON
#include "compat/daemon.h"
#endif
#include "vsb.h" #include "vsb.h"
#include "vpf.h"
#include "cli.h" #include "cli.h"
#include "cli_priv.h" #include "cli_priv.h"
...@@ -163,7 +168,7 @@ usage(void) ...@@ -163,7 +168,7 @@ usage(void)
fprintf(stderr, " %-28s # %s\n", "", fprintf(stderr, " %-28s # %s\n", "",
" -b '<hostname_or_IP>:<port_or_service>'"); " -b '<hostname_or_IP>:<port_or_service>'");
fprintf(stderr, " %-28s # %s\n", "-d", "debug"); fprintf(stderr, " %-28s # %s\n", "-d", "debug");
fprintf(stderr, " %-28s # %s\n", "-f file", "VCL_file"); fprintf(stderr, " %-28s # %s\n", "-f file", "VCL script");
fprintf(stderr, " %-28s # %s\n", fprintf(stderr, " %-28s # %s\n",
"-h kind[,hashoptions]", "Hash specification"); "-h kind[,hashoptions]", "Hash specification");
fprintf(stderr, " %-28s # %s\n", "", fprintf(stderr, " %-28s # %s\n", "",
...@@ -172,6 +177,7 @@ usage(void) ...@@ -172,6 +177,7 @@ usage(void)
" -h classic [default]"); " -h classic [default]");
fprintf(stderr, " %-28s # %s\n", "", fprintf(stderr, " %-28s # %s\n", "",
" -h classic,<buckets>"); " -h classic,<buckets>");
fprintf(stderr, " %-28s # %s\n", "-P file", "PID file");
fprintf(stderr, " %-28s # %s\n", "-p param=value", fprintf(stderr, " %-28s # %s\n", "-p param=value",
"set parameter"); "set parameter");
fprintf(stderr, " %-28s # %s\n", fprintf(stderr, " %-28s # %s\n",
...@@ -396,12 +402,14 @@ main(int argc, char *argv[]) ...@@ -396,12 +402,14 @@ main(int argc, char *argv[])
const char *b_arg = NULL; const char *b_arg = NULL;
const char *f_arg = NULL; const char *f_arg = NULL;
const char *h_flag = "classic"; const char *h_flag = "classic";
const char *P_arg = NULL;
const char *s_arg = "file"; const char *s_arg = "file";
const char *T_arg = NULL; const char *T_arg = NULL;
unsigned C_flag = 0; unsigned C_flag = 0;
char *p; char *p;
struct params param; struct params param;
struct cli cli[1]; struct cli cli[1];
struct pidfh *pfh = NULL;
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, NULL); setbuf(stderr, NULL);
...@@ -420,8 +428,8 @@ main(int argc, char *argv[]) ...@@ -420,8 +428,8 @@ main(int argc, char *argv[])
* XXX: block in shared memory. It would give us the advantage * 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: of having the CLI thread be able to take action on the
* XXX: change. * XXX: change.
* XXX: For now live with the harmless flexelint warning this causes: * XXX: For now live with the harmless flexelint warning this causes:
* XXX: varnishd.c 393 Info 789: Assigning address of auto variable * XXX: varnishd.c 393 Info 789: Assigning address of auto variable
* XXX: 'param' to static * XXX: 'param' to static
*/ */
...@@ -433,7 +441,7 @@ main(int argc, char *argv[]) ...@@ -433,7 +441,7 @@ main(int argc, char *argv[])
MCF_ParamInit(cli); MCF_ParamInit(cli);
cli_check(cli); cli_check(cli);
while ((o = getopt(argc, argv, "a:b:Cdf:h:p:s:T:t:Vw:")) != -1) while ((o = getopt(argc, argv, "a:b:Cdf:h:P:p:s:T:t:Vw:")) != -1)
switch (o) { switch (o) {
case 'a': case 'a':
MCF_ParamSet(cli, "listen_address", optarg); MCF_ParamSet(cli, "listen_address", optarg);
...@@ -454,6 +462,9 @@ main(int argc, char *argv[]) ...@@ -454,6 +462,9 @@ main(int argc, char *argv[])
case 'h': case 'h':
h_flag = optarg; h_flag = optarg;
break; break;
case 'P':
P_arg = optarg;
break;
case 'p': case 'p':
p = strchr(optarg, '='); p = strchr(optarg, '=');
if (p == NULL) if (p == NULL)
...@@ -499,6 +510,11 @@ main(int argc, char *argv[]) ...@@ -499,6 +510,11 @@ main(int argc, char *argv[])
usage(); usage();
} }
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, C_flag))
exit (2); exit (2);
if (C_flag) if (C_flag)
...@@ -516,9 +532,14 @@ main(int argc, char *argv[]) ...@@ -516,9 +532,14 @@ main(int argc, char *argv[])
if (d_flag == 1) if (d_flag == 1)
printf("%d\n", getpid()); printf("%d\n", getpid());
if (pfh != NULL)
vpf_write(pfh);
mgt_cli_init(); mgt_cli_init();
mgt_run(d_flag, T_arg); mgt_run(d_flag, T_arg);
if (pfh != NULL)
vpf_remove(pfh);
exit(0); exit(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