mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-19 01:09:21 +08:00
Use secure tmp dir instead of /tmp.
This commit is contained in:
54
bin/pt-pmp
54
bin/pt-pmp
@@ -4,6 +4,48 @@
|
|||||||
# See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal
|
# See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal
|
||||||
# notices and disclaimers.
|
# notices and disclaimers.
|
||||||
|
|
||||||
|
# ###########################################################################
|
||||||
|
# tmpdir package
|
||||||
|
# This package is a copy without comments from the original. The original
|
||||||
|
# with comments and its test file can be found in the Bazaar repository at,
|
||||||
|
# lib/bash/tmpdir.sh
|
||||||
|
# t/lib/bash/tmpdir.sh
|
||||||
|
# See https://launchpad.net/percona-toolkit for more information.
|
||||||
|
# ###########################################################################
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
TMPDIR=""
|
||||||
|
|
||||||
|
mk_tmpdir() {
|
||||||
|
local dir="${1:-""}"
|
||||||
|
|
||||||
|
if [ -n "$dir" ]; then
|
||||||
|
if [ ! -d "$dir" ]; then
|
||||||
|
mkdir "$dir" || die "Cannot make tmpdir $dir"
|
||||||
|
fi
|
||||||
|
TMPDIR="$dir"
|
||||||
|
else
|
||||||
|
local tool="${0##*/}"
|
||||||
|
local pid="$$"
|
||||||
|
TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \
|
||||||
|
|| die "Cannot make secure tmpdir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
rm_tmpdir() {
|
||||||
|
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
|
||||||
|
rm -rf "$TMPDIR"
|
||||||
|
fi
|
||||||
|
TMPDIR=""
|
||||||
|
}
|
||||||
|
|
||||||
|
# ###########################################################################
|
||||||
|
# End tmpdir package
|
||||||
|
# ###########################################################################
|
||||||
|
|
||||||
|
set +u
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
if [ "${OPT_ERR}" ]; then
|
if [ "${OPT_ERR}" ]; then
|
||||||
echo "${OPT_ERR}" >&2
|
echo "${OPT_ERR}" >&2
|
||||||
@@ -100,7 +142,6 @@ aggregate_stacktrace() {
|
|||||||
|
|
||||||
# The main program to run.
|
# The main program to run.
|
||||||
main() {
|
main() {
|
||||||
rm -f /tmp/percona-toolkit
|
|
||||||
|
|
||||||
# Get command-line options
|
# Get command-line options
|
||||||
for o; do
|
for o; do
|
||||||
@@ -155,15 +196,14 @@ main() {
|
|||||||
fi
|
fi
|
||||||
date;
|
date;
|
||||||
for x in $(seq 1 $OPT_i); do
|
for x in $(seq 1 $OPT_i); do
|
||||||
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $OPT_p >> "${OPT_k:-/tmp/percona-toolkit}"
|
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $OPT_p >> "${OPT_k:-$TMPDIR/percona-toolkit}"
|
||||||
date +'TS %N.%s %F %T' >> "${OPT_k:-/tmp/percona-toolkit}"
|
date +'TS %N.%s %F %T' >> "${OPT_k:-$TMPDIR/percona-toolkit}"
|
||||||
sleep $OPT_s
|
sleep $OPT_s
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
aggregate_stacktrace "${OPT_l}" "${OPT_k:-/tmp/percona-toolkit}"
|
aggregate_stacktrace "${OPT_l}" "${OPT_k:-$TMPDIR/percona-toolkit}"
|
||||||
rm -f /tmp/percona-toolkit
|
|
||||||
else
|
else
|
||||||
aggregate_stacktrace "${OPT_l}" "$@"
|
aggregate_stacktrace "${OPT_l}" "$@"
|
||||||
fi
|
fi
|
||||||
@@ -172,7 +212,9 @@ main() {
|
|||||||
# Execute the program if it was not included from another file. This makes it
|
# Execute the program if it was not included from another file. This makes it
|
||||||
# possible to include without executing, and thus test.
|
# possible to include without executing, and thus test.
|
||||||
if [ "$(basename "$0")" = "pt-pmp" ] || [ "$(basename "$0")" = "bash" -a "$_" = "$0" ]; then
|
if [ "$(basename "$0")" = "pt-pmp" ] || [ "$(basename "$0")" = "bash" -a "$_" = "$0" ]; then
|
||||||
main "$@"
|
mk_tmpdir
|
||||||
|
main "$@"
|
||||||
|
rm_tmpdir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ warn() {
|
|||||||
exit_status=$((exit_status | 1))
|
exit_status=$((exit_status | 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cwd="$PWD"
|
||||||
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
||||||
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
||||||
else
|
else
|
||||||
@@ -27,6 +28,7 @@ else
|
|||||||
fi
|
fi
|
||||||
BRANCH=`pwd`
|
BRANCH=`pwd`
|
||||||
fi
|
fi
|
||||||
|
cd "$cwd"
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Global variables
|
# Global variables
|
||||||
|
|||||||
Reference in New Issue
Block a user