Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 May 2018 05:49:31 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r333516 - head/cddl/usr.sbin/dwatch
Message-ID:  <201805120549.w4C5nVE9030888@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Sat May 12 05:49:31 2018
New Revision: 333516
URL: https://svnweb.freebsd.org/changeset/base/333516

Log:
  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.

Modified:
  head/cddl/usr.sbin/dwatch/dwatch

Modified: head/cddl/usr.sbin/dwatch/dwatch
==============================================================================
--- head/cddl/usr.sbin/dwatch/dwatch	Sat May 12 05:43:47 2018	(r333515)
+++ head/cddl/usr.sbin/dwatch/dwatch	Sat May 12 05:49:31 2018	(r333516)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805120549.w4C5nVE9030888>