Commit b751efaf authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@749 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 97410c2c
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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();
......
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