Commit b214d480 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Handle terminal disconnections correctly

Change SIGHUP handling depending on whether we're running in daemon mode
or foreground. The former will continue rotating the logs, the latter
will abort the loop and die gracefully.

Fixes #1794.
parent b8f55d90
......@@ -291,6 +291,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
return (0);
}
static int __match_proto__(VUT_cb_f)
sighup(void)
{
return (1);
}
static void *
do_curses(void *arg)
{
......@@ -465,6 +471,7 @@ main(int argc, char **argv)
}
VUT.dispatch_f = &accumulate;
VUT.dispatch_priv = NULL;
VUT.sighup_f = sighup;
VUT_Main();
end_of_file = 1;
AZ(pthread_join(thr, NULL));
......
......@@ -110,6 +110,12 @@ flushout(void)
return (0);
}
static int __match_proto__(VUT_cb_f)
sighup(void)
{
return (1);
}
int
main(int argc, char * const *argv)
{
......@@ -153,10 +159,12 @@ main(int argc, char * const *argv)
VUT.dispatch_f = VSL_PrintTransactions;
else
VUT.dispatch_f = VSL_WriteTransactions;
VUT.sighup_f = sighup;
if (LOG.w_arg) {
openout(LOG.a_opt);
AN(LOG.fo);
VUT.sighup_f = rotateout;
if (VUT.D_opt)
VUT.sighup_f = rotateout;
} else
LOG.fo = stdout;
VUT.idle_f = flushout;
......
......@@ -46,11 +46,11 @@
VOPT("w:", "[-w filename]", "Output filename", \
"Redirect output to file. The file will be overwritten" \
" unless the -a option was specified. If the application" \
" receives a SIGHUP the file will be reopened allowing" \
" the old one to be rotated away. The file can then be" \
" read by varnishlog and other tools with the -r option," \
" unless the -A option was specified. This option is" \
" required when running in daemon mode." \
" receives a SIGHUP in daemon mode the file will be " \
" reopened allowing the old one to be rotated away. The" \
" file can then be read by varnishlog and other tools with" \
" the -r option, unless the -A option was specified. This" \
" option is required when running in daemon mode." \
)
LOG_OPT_a
......
......@@ -927,6 +927,12 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
return (0);
}
static int __match_proto__(VUT_cb_f)
sighup(void)
{
return (1);
}
int
main(int argc, char * const *argv)
{
......@@ -991,10 +997,12 @@ main(int argc, char * const *argv)
/* Setup output */
VUT.dispatch_f = &dispatch_f;
VUT.dispatch_priv = NULL;
VUT.sighup_f = sighup;
if (CTX.w_arg) {
openout(CTX.a_opt);
AN(CTX.fo);
VUT.sighup_f = &rotateout;
if (VUT.D_opt)
VUT.sighup_f = &rotateout;
} else
CTX.fo = stdout;
VUT.idle_f = &flushout;
......
......@@ -41,7 +41,7 @@
)
#define NCSA_OPT_g \
VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \
VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \
"The grouping of the log records. The default is to group" \
" by vxid." \
)
......@@ -50,9 +50,9 @@
VOPT("w:", "[-w filename]", "Output filename", \
"Redirect output to file. The file will be overwritten" \
" unless the -a option was specified. If the application" \
" receives a SIGHUP the file will be reopened allowing" \
" the old one to be rotated away. This option is required" \
" when running in daemon mode." \
" receives a SIGHUP in daemon mode the file will be" \
" reopened allowing the old one to be rotated away. This" \
" option is required when running in daemon mode." \
)
NCSA_OPT_a
......
......@@ -12,7 +12,7 @@ server s1 {
varnish v1 -vcl+backend "" -start
process p1 "exec ${varnishncsa} -n ${v1_name} -w ${tmpdir}/ncsa.log -F %s" -start
shell "${varnishncsa} -D -P ${tmpdir}/ncsa.pid -n ${v1_name} -w ${tmpdir}/ncsa.log -F %s"
# give varnishncsa enough time to open the VSM
delay 2
......@@ -27,7 +27,7 @@ delay 2
# rotate logs
shell "mv ${tmpdir}/ncsa.log ${tmpdir}/ncsa.old.log >/dev/null 2>&1"
process p1 -kill "HUP"
shell "kill -HUP `cat ${tmpdir}/ncsa.pid`"
client c1 {
txreq -url "/bar"
......@@ -37,7 +37,7 @@ client c1 {
# give varnishncsa enough time to write
delay 2
process p1 -stop
shell "kill `cat ${tmpdir}/ncsa.pid`"
shell "grep 200 ${tmpdir}/ncsa.old.log >/dev/null"
shell "grep 404 ${tmpdir}/ncsa.log >/dev/null"
......@@ -180,6 +180,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
return (0);
}
static int __match_proto__(VUT_cb_f)
sighup(void)
{
return (1);
}
static void
update(int p)
{
......@@ -362,6 +368,7 @@ main(int argc, char **argv)
}
VUT.dispatch_f = &accumulate;
VUT.dispatch_priv = NULL;
VUT.sighup_f = sighup;
VUT_Main();
end_of_file = 1;
if (once)
......
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