]> err.no Git - varnish/commitdiff
Add -P (pid file) option.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 May 2007 12:17:26 +0000 (12:17 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 May 2007 12:17:26 +0000 (12:17 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1415 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/varnishd.1
varnish-cache/bin/varnishd/varnishd.c

index e78d38218a2514abdbc2013a85207cffdf2427de..ee6dd9dbb6040436e7cadf477f62771100c83429 100644 (file)
@@ -41,6 +41,7 @@
 .Op Fl d
 .Op Fl f Ar config
 .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 s Ar type Ns Op , Ns Ar options
 .Op Fl T Ar address Ns Op : Ns Ar port
@@ -111,6 +112,9 @@ Specifies the hash algorithm.
 See
 .Sx Hash 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
 Set the parameter specified by
 .Ar param
index e547bec321ad2170f1e479e9a5925198f4d1e190..0bdfea27229f74a4eeba1a51ca172aeb3715d1b6 100644 (file)
 #include <time.h>
 #include <unistd.h>
 
+#ifndef HAVE_DAEMON
+#include "compat/daemon.h"
+#endif
+
 #include "vsb.h"
+#include "vpf.h"
 
 #include "cli.h"
 #include "cli_priv.h"
@@ -163,7 +168,7 @@ usage(void)
        fprintf(stderr, "    %-28s # %s\n", "",
            "   -b '<hostname_or_IP>:<port_or_service>'");
        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",
            "-h kind[,hashoptions]", "Hash specification");
        fprintf(stderr, "    %-28s # %s\n", "",
@@ -172,6 +177,7 @@ usage(void)
            "  -h classic  [default]");
        fprintf(stderr, "    %-28s # %s\n", "",
            "  -h classic,<buckets>");
+       fprintf(stderr, "    %-28s # %s\n", "-P file", "PID file");
        fprintf(stderr, "    %-28s # %s\n", "-p param=value",
            "set parameter");
        fprintf(stderr, "    %-28s # %s\n",
@@ -396,12 +402,14 @@ main(int argc, char *argv[])
        const char *b_arg = NULL;
        const char *f_arg = NULL;
        const char *h_flag = "classic";
+       const char *P_arg = NULL;
        const char *s_arg = "file";
        const char *T_arg = NULL;
        unsigned C_flag = 0;
        char *p;
        struct params param;
        struct cli cli[1];
+       struct pidfh *pfh = NULL;
 
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
@@ -420,8 +428,8 @@ main(int argc, char *argv[])
         * 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: change.
-        * XXX: For now live with the harmless flexelint warning this causes: 
-        * XXX: varnishd.c 393 Info 789: Assigning address of auto variable 
+        * XXX: For now live with the harmless flexelint warning this causes:
+        * XXX: varnishd.c 393 Info 789: Assigning address of auto variable
         * XXX:    'param' to static
         */
 
@@ -433,7 +441,7 @@ main(int argc, char *argv[])
        MCF_ParamInit(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) {
                case 'a':
                        MCF_ParamSet(cli, "listen_address", optarg);
@@ -454,6 +462,9 @@ main(int argc, char *argv[])
                case 'h':
                        h_flag = optarg;
                        break;
+               case 'P':
+                       P_arg = optarg;
+                       break;
                case 'p':
                        p = strchr(optarg, '=');
                        if (p == NULL)
@@ -499,6 +510,11 @@ main(int argc, char *argv[])
                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))
                exit (2);
        if (C_flag)
@@ -516,9 +532,14 @@ main(int argc, char *argv[])
        if (d_flag == 1)
                printf("%d\n", getpid());
 
+       if (pfh != NULL)
+               vpf_write(pfh);
+
        mgt_cli_init();
 
        mgt_run(d_flag, T_arg);
 
+       if (pfh != NULL)
+               vpf_remove(pfh);
        exit(0);
 }