Skip to content

Commit

Permalink
END clause does not execute when consumer stops the producer
Browse files Browse the repository at this point in the history
The END probe's clause does not execute when the consumer requests
tracing to stop.  One example is when the user sends a SIGINT to the
dtrace command-line tool and it calls dtrace_stop().  This problem
would also occur once -c is supported and the specified command finishes.

The problem is that the END probe checks that the activity state is
DRAINING before executing its clause, but DRAINING is set only by
calling the D exit() action.

Before calling END_probe(), advance the activity state to DRAINING if
it is not yet that far.  Add a test for this problem.

Orabug: 32036406
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh committed Oct 19, 2020
1 parent bf93f27 commit a38a40f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libdtrace/dt_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ dtrace_stop(dtrace_hdl_t *dtp)
if (dtp->dt_stopped)
return 0;

if (dt_state_get_activity(dtp) < DT_ACTIVITY_DRAINING)
dt_state_set_activity(dtp, DT_ACTIVITY_DRAINING);

END_probe();

dtp->dt_stopped = 1;
Expand Down
30 changes: 30 additions & 0 deletions test/unittest/actions/exit/tst.kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

dtrace=$1
out=$tmpdir/output.$$

watch_output_for() {
for iter in 1 2 3 4 5 6; do
sleep 1
if grep -q $1 $out; then
iter=0
break
fi
done
if [[ $iter -ne 0 ]]; then
echo ERROR: missing $1 in output file
exit 1
fi
}

$dtrace $dt_flags -n BEGIN,END -o $out &
watch_output_for :BEGIN
kill %1
watch_output_for :END
echo success

0 comments on commit a38a40f

Please sign in to comment.