Various fixes
authorAlan T. DeKok <aland@freeradius.org>
Sun, 19 Sep 2010 06:41:44 +0000 (08:41 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 19 Sep 2010 06:52:01 +0000 (08:52 +0200)
If timeout is zero, set it to 1^6.  That should be good enough.

Don't filter output through sed, this makes it impossible to kill the
"tail" process.

Catch the tail PID, and kill it on exit.

Trap on signals, not on normal exit.

Duplicate code in trap for normal exit.  This ensures that the code is
only executed once.

scripts/raddebug

index 3fac9de..a799ba8 100755 (executable)
@@ -52,6 +52,7 @@ do
        extra="-f $OPTARG"
        ;;
   t)   timeout="$OPTARG"
+       [ "$timout" = "0" ] && timeout=1000000
        ;;
   u)   condition="(User-Name == $OPTARG)"
        ;;
@@ -94,10 +95,12 @@ fi
 cp /dev/null $outfile
 chmod g+w $outfile
 
+TAILPID=$$
+
 #
 #  Set the trap to clean up on exit and any interrupts.
 #
-trap '$radmin -e "debug condition" -e "debug file"; rm -f $outfile; exit 0' 0 1 2 15
+trap '$radmin -e "debug condition" -e "debug file"; rm -f $outfile;kill -TERM $TAILPID;exit 0' 1 2 15
 
 #
 #  Set the debug condition
@@ -107,6 +110,9 @@ $radmin -e "debug condition \"$condition\""
 #
 #  Print the output, and wait for "timeout".  Then, stop printing.
 #
-(tail -f $outfile | sed 's/^.*Debug: //') &
+tail -f $outfile &
+TAILPID=$!
 sleep $timeout
-kill -INT %1
+kill -TERM $TAILPID
+$radmin -e "debug condition" -e "debug file"
+rm -f $outfile