]> err.no Git - varnish/commitdiff
Improve the "-d" and "-d -d" facilities.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 20:24:47 +0000 (20:24 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 20:24:47 +0000 (20:24 +0000)
When we close a CLI and it had fd# 0 and/or fd#1, reopen these
as /dev/null so the will not be reused for the CLI pipe to the
child on next restart, otherwise stdout/stderr output from the
manager would get sent there and confuse the clients CLI reader.

Don't double free a pointer to the CLI buffer.

Accept non-zero results from cli_readres() errors are non-fatal.

Use stderr more consistently for manager debugging.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@749 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/mgt_cli.c
varnish-cache/bin/varnishd/varnishd.c

index c0650e82f6deec8b65625ea750a228a33b0de245..c870f04804392ed27fc9d73a8fbf817948176746 100644 (file)
@@ -67,7 +67,7 @@ child_listener(struct ev *e, int what)
                return (1);
        }
        buf[i] = '\0';
-       printf("Child said (%d, %d): <<%s>>\n", child_state, child_pid, buf);
+       fprintf(stderr, "Child said (%d, %d): <<%s>>\n", child_state, child_pid, buf);
        return (0);
 }
 
@@ -128,7 +128,7 @@ start_child(void)
                exit (1);
        }
 
-       printf("start child pid %d\n", i);
+       fprintf(stderr, "start child pid %d\n", i);
 
        AZ(close(child_fds[1]));
        child_fds[1] = -1;
@@ -183,7 +183,7 @@ stop_child(void)
        }
        ev_poker = NULL;
 
-       printf("Clean child\n");
+       fprintf(stderr, "Clean child\n");
        mgt_cli_stop_child();
 
        /* We tell the child to die gracefully by closing the CLI */
@@ -192,7 +192,7 @@ stop_child(void)
        AZ(close(heritage.fds[3]));
        heritage.fds[3] = -1;
 
-       printf("Child stopping\n");
+       fprintf(stderr, "Child stopping\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -214,16 +214,16 @@ mgt_sigchld(struct ev *e, int what)
 
        r = wait4(-1, &status, WNOHANG, NULL);
        if (r != child_pid) {
-               printf("Unknown child died pid=%d status=0x%x\n",
+               fprintf(stderr, "Unknown child died pid=%d status=0x%x\n",
                    r, status);
                return (0);
        }
-       printf("Cache child died pid=%d status=0x%x\n", r, status);
+       fprintf(stderr, "Cache child died pid=%d status=0x%x\n", r, status);
        child_pid = -1;
 
        if (child_state == CH_RUNNING) {
                child_state = CH_DIED;
-               printf("Clean child\n");
+               fprintf(stderr, "Clean child\n");
                mgt_cli_stop_child();
 
                /* We tell the child to die gracefully by closing the CLI */
@@ -241,7 +241,7 @@ mgt_sigchld(struct ev *e, int what)
 
        AZ(close(child_fds[0]));
        child_fds[0] = -1;
-       printf("Child cleaned\n");
+       fprintf(stderr, "Child cleaned\n");
 
        if (child_state == CH_DIED)
                start_child();
@@ -258,7 +258,7 @@ mgt_sigint(struct ev *e, int what)
 
        (void)e;
        (void)what;
-       printf("Manager got SIGINT\n");
+       fprintf(stderr, "Manager got SIGINT\n");
        fflush(stdout);
        if (child_pid >= 0)
                stop_child();
@@ -276,6 +276,7 @@ mgt_run(int dflag)
 {
        struct sigaction sac;
        struct ev *e;
+       int i;
 
        mgt_pid = getpid();
 
@@ -320,9 +321,10 @@ mgt_run(int dflag)
        if (!dflag)
                start_child();
 
-       ev_schedule(mgt_evb);
+       i = ev_schedule(mgt_evb);
+       fprintf(stderr, "ev_schedule = %d\n", i);
 
-       printf("manager dies\n");
+       fprintf(stderr, "manager dies\n");
        exit(2);
 }
 
index 7eb423bd9f636902446673bd870e4dec8cf2f036..41918e4e70b16c141b96d867d939531151ee7d28 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -189,7 +190,6 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
        j = write(cli_o, p, i);
        free(p);
        if (j != i) {
-               free(p);
                if (status != NULL)
                        *status = CLIS_COMMS;
                if (resp != NULL)
@@ -198,7 +198,6 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
        }
 
        i = cli_readres(cli_i, &u, resp, 3.0);
-       assert(i == 0);
        if (status != NULL)
                *status = u;
        return (u == CLIS_OK ? 0 : u);
@@ -281,7 +280,14 @@ fprintf(stderr, "CLI <%s>\n", cp->buf);
        vsb_delete(cp->cli->sb);
        free(cp->buf);
        close(cp->fdi);
+       if (cp->fdi == 0)
+               open("/dev/null", O_RDONLY);
        close(cp->fdo);
+       if (cp->fdo == 1) {
+               close(2);
+               open("/dev/null", O_WRONLY);
+               open("/dev/null", O_WRONLY);
+       }
        free(cp);
        return (1);
 }
index 0bdababc1d5995197e931b7be6e5855836ddd4ff..7069fe2cd74afe4fdf40d6c013d4fe35362ea325 100644 (file)
@@ -403,10 +403,10 @@ main(int argc, char *argv[])
 
        if (dflag == 1)
                DebugStunt();
-       if (dflag != 2)
+       if (dflag < 2)
                daemon(dflag, dflag);
-       if (dflag)
-               printf("%d\n%d\n%d\n", getpid(), getsid(0), getpgrp());
+       if (dflag == 1)
+               printf("%d\n", getpid());
 
        mgt_cli_init();