r749 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Aug 7 22:24:47 CEST 2006
Author: phk
Date: 2006-08-07 22:24:47 +0200 (Mon, 07 Aug 2006)
New Revision: 749
Modified:
trunk/varnish-cache/bin/varnishd/mgt_child.c
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Improve the "-d" and "-d -d" facilities.
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.
Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2006-08-07 18:33:01 UTC (rev 748)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2006-08-07 20:24:47 UTC (rev 749)
@@ -67,7 +67,7 @@
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 @@
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 @@
}
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 @@
AZ(close(heritage.fds[3]));
heritage.fds[3] = -1;
- printf("Child stopping\n");
+ fprintf(stderr, "Child stopping\n");
}
/*--------------------------------------------------------------------*/
@@ -214,16 +214,16 @@
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 @@
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 @@
(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 @@
{
struct sigaction sac;
struct ev *e;
+ int i;
mgt_pid = getpid();
@@ -320,9 +321,10 @@
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);
}
Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-07 18:33:01 UTC (rev 748)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-07 20:24:47 UTC (rev 749)
@@ -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 @@
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 @@
}
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 @@
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);
}
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-07 18:33:01 UTC (rev 748)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-07 20:24:47 UTC (rev 749)
@@ -403,10 +403,10 @@
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();
More information about the varnish-commit
mailing list