[DTrace-devel] [PATCH] END clause does not execute when consumer stops the producer

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Oct 15 23:22:43 PDT 2020


From: Eugene Loh <eugene.loh at oracle.com>

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.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_work.c                    |  3 +++
 test/unittest/actions/exit/tst.kill.sh | 31 ++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100755 test/unittest/actions/exit/tst.kill.sh

diff --git a/libdtrace/dt_work.c b/libdtrace/dt_work.c
index 02246219..51da120e 100644
--- a/libdtrace/dt_work.c
+++ b/libdtrace/dt_work.c
@@ -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;
diff --git a/test/unittest/actions/exit/tst.kill.sh b/test/unittest/actions/exit/tst.kill.sh
new file mode 100755
index 00000000..2ff465b8
--- /dev/null
+++ b/test/unittest/actions/exit/tst.kill.sh
@@ -0,0 +1,31 @@
+#!/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
+
-- 
2.18.4




More information about the DTrace-devel mailing list