aboutsummaryrefslogtreecommitdiff
path: root/cddl/usr.sbin
diff options
context:
space:
mode:
authorDevin Teske <dteske@FreeBSD.org>2018-05-12 05:49:31 +0000
committerDevin Teske <dteske@FreeBSD.org>2018-05-12 05:49:31 +0000
commit6a21b3cdf445340a76d880e8cef139c020942fe3 (patch)
tree21cef1d9e589e54fd2a055498e12e20b49fefcfb /cddl/usr.sbin
parent4a73674e322e7fef96298581779fcc639c702067 (diff)
downloadsrc-6a21b3cdf445340a76d880e8cef139c020942fe3.tar.gz
src-6a21b3cdf445340a76d880e8cef139c020942fe3.zip
dwatch(1): Export ARGV to profiles loaded via load_profile()
A module that wishes to post-process the output needs to know which arguments were passed in order to re-execute a child in a pipe-chain. Further, the expansion of ARGV needs to be such that items are escaped properly. Sponsored by: Smule, Inc.
Notes
Notes: svn path=/head/; revision=333516
Diffstat (limited to 'cddl/usr.sbin')
-rwxr-xr-xcddl/usr.sbin/dwatch/dwatch43
1 files changed, 43 insertions, 0 deletions
diff --git a/cddl/usr.sbin/dwatch/dwatch b/cddl/usr.sbin/dwatch/dwatch
index c51974f7eb13..05fe5921993f 100755
--- a/cddl/usr.sbin/dwatch/dwatch
+++ b/cddl/usr.sbin/dwatch/dwatch
@@ -537,6 +537,11 @@ list_profiles()
exit $SUCCESS
}
+shell_escape()
+{
+ echo "$*" | awk 'gsub(/'\''/, "&\\\\&&")||1'
+}
+
load_profile()
{
local profile="$1"
@@ -546,6 +551,44 @@ load_profile()
local oldIFS="$IFS"
local dir found=
+ local ARGV=
+
+ [ $COUNT -gt 0 ] && ARGV="$ARGV -N $COUNT"
+ [ "$DEBUG" ] && ARGV="$ARGV -d"
+ [ "$DESTRUCTIVE_ACTIONS" ] && ARGV="$ARGV -w"
+ [ "$EXIT_AFTER_COMPILE" ] && ARGV="$ARGV -e"
+ [ "$GROUP" ] && ARGV="$ARGV -g $GROUP"
+ [ "$JID" ] && ARGV="$ARGV -j $JID"
+ [ $MAX_ARGS -ne $_MAX_ARGS ] && ARGV="$ARGV -B $MAX_ARGS"
+ [ $MAX_DEPTH -ne $_MAX_DEPTH ] && ARGV="$ARGV -K $MAX_DEPTH"
+ [ "$ONELINE" ] && ARGV="$ARGV -1"
+ [ "$PID" ] && ARGV="$ARGV -p $PID"
+ [ "$PSTREE" ] && ARGV="$ARGV -R"
+ [ "$QUIET" ] && ARGV="$ARGV -q"
+ [ "$TIMEOUT" ] && ARGV="$ARGV -T $TIMEOUT"
+ [ "$TRACE" ] && ARGV="$ARGV -x"
+ [ "$USER" ] && ARGV="$ARGV -u $USER"
+ [ "$VERBOSE" ] && ARGV="$ARGV -v"
+
+ [ "$FILTER" ] &&
+ ARGV="$ARGV -r '$( shell_escape "$FILTER" )'"
+ [ "$EXECREGEX" ] &&
+ ARGV="$ARGV -z '$( shell_escape "$EXECREGEX" )'"
+ [ "$CUSTOM_DETAILS" ] &&
+ ARGV="$ARGV -E '$( shell_escape "$EVENT_DETAILS" )'"
+ [ "$EVENT_TEST" ] &&
+ ARGV="$ARGV -t '$( shell_escape "$EVENT_TEST" )'"
+ [ "$OUTPUT" ] &&
+ ARGV="$ARGV -o '$( shell_escape "$OUTPUT" )'"
+ [ "$OUTPUT_CMD" ] &&
+ ARGV="$ARGV -O '$( shell_escape "$OUTPUT_CMD" )'"
+
+ case "$PROBE_TYPE" in
+ provider) ARGV="$ARGV -P" ;;
+ module) ARGV="$ARGV -m" ;;
+ function) ARGV="$ARGV -f" ;;
+ name) ARGV="$ARGV -n" ;;
+ esac
IFS=:
for dir in $DWATCH_PROFILES_PATH; do