[DTrace-devel] [PATCH] Add support for the ftruncate() action

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Nov 4 22:40:51 UTC 2021


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

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_cg.c                    | 2 ++
 libdtrace/dt_consume.c               | 9 +++++++++
 test/unittest/funcs/tst.ftruncate.sh | 8 +-------
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 58f8b5c7..b5b66a49 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -1326,6 +1326,8 @@ dt_cg_act_exit(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 static void
 dt_cg_act_ftruncate(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
+	dt_rec_add(pcb->pcb_hdl, dt_cg_fill_gap, DTRACEACT_LIBACT, 0, 1, NULL,
+		   DT_ACT_FTRUNCATE);
 }
 
 static void
diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index c66c2654..0dfc7b5f 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -2330,6 +2330,15 @@ dt_consume_one_probe(dtrace_hdl_t *dtp, FILE *fp, char *data, uint32_t size,
 					return DTRACE_WORKSTATUS_ERROR;
 
 				i++;
+				continue;
+			case DT_ACT_FTRUNCATE:
+				if (fp == NULL)
+					continue;
+
+				fflush(fp);
+				ftruncate(fileno(fp), 0);
+				fseeko(fp, 0, SEEK_SET);
+
 				continue;
 			}
 		}
diff --git a/test/unittest/funcs/tst.ftruncate.sh b/test/unittest/funcs/tst.ftruncate.sh
index 9dfe6f35..59ca9beb 100755
--- a/test/unittest/funcs/tst.ftruncate.sh
+++ b/test/unittest/funcs/tst.ftruncate.sh
@@ -1,11 +1,10 @@
 #!/bin/bash
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2021, 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.
 #
-# @@xfail: dtv2
 script()
 {
 	$dtrace $dt_flags -q -o $tmpfile -s /dev/stdin <<EOF
@@ -28,11 +27,6 @@ script()
 EOF
 }
 
-if [ $# != 1 ]; then
-	echo expected one argument: '<'dtrace-path'>'
-	exit 2
-fi
-
 dtrace=$1
 tmpfile=$tmpdir/tst.ftruncate.$$
 
-- 
2.18.4




More information about the DTrace-devel mailing list