validate-diameter-xml.sh: do not hard-code temporary directory
authorPeter Wu <peter@lekensteyn.nl>
Wed, 17 Oct 2018 10:22:17 +0000 (12:22 +0200)
committerJeff Morriss <jeff.morriss.ws@gmail.com>
Wed, 17 Oct 2018 15:02:42 +0000 (15:02 +0000)
In the event that validation fails, the hard-coded temporary directory
would remain present. Use of a fixed hard-coded directory also prevents
concurrent runs.

Change-Id: I29f09dc004b1ab3578b4a9c51ea7e1a5b526159f
Reviewed-on: https://code.wireshark.org/review/30231
Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
tools/validate-diameter-xml.sh

index 3fad9c863233ff8526f0aac06ae83fe4e70f68f9..36b6fb29767ea3dc1236dd79910749ebfd28d89e 100755 (executable)
@@ -37,24 +37,27 @@ then
        exit 1
 fi
 
+if ! tmpdir=$(mktemp -d); then
+       echo "Could not create temporary directory" >&2
+       exit 1
+fi
+trap 'rm -rf "$tmpdir"' EXIT
+
 # First edit all the AVP names that start with "3GPP" to indicate "TGPP".
 # XML doesn't allow ID's to start with a digit but:
 #   1) We don't *really* care if it's valid XML
 #   2) (but) we do want to use xmllint to find problems
 #   3) (and) users see the AVP names.  Showing them "TGPP" instead of "3GPP"
 #      is annoying enough to warrant this extra work.
-mkdir /tmp/diameter || exit 1
-cp diameter/dictionary.dtd /tmp/diameter || exit 1
+cp diameter/dictionary.dtd "$tmpdir" || exit 1
 for f in diameter/*.xml
 do
-       sed 's/name="3GPP/name="TGPP/g' $f > /tmp/$f || exit 1
+       sed 's/name="3GPP/name="TGPP/g' "$f" > "$tmpdir/${f##*/}" || exit 1
 done
 
-xmllint --noout --noent --postvalid /tmp/diameter/dictionary.xml &&
+xmllint --noout --noent --postvalid "$tmpdir/dictionary.xml" &&
        echo "Diameter dictionary is (mostly) valid XML."
 
-rm -rf /tmp/diameter
-
 #
 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 #