Commit 01a6d89a authored by Federico G. Schwindt's avatar Federico G. Schwindt Committed by Lasse Karstensen

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