Change TMPDIR to PT_TMPDIR

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-11 17:51:43 -03:00
parent bf2a769536
commit bc8f5a610c
30 changed files with 588 additions and 595 deletions

View File

@@ -126,8 +126,8 @@ collect_master_logs_status () {
# Somewhat different from the others, this one joins the status we got earlier
collect_mysql_deferred_status () {
local status_file="$1"
collect_mysql_status > "$TMPDIR/defer_gatherer"
join "$status_file" "$TMPDIR/defer_gatherer"
collect_mysql_status > "$PT_TMPDIR/defer_gatherer"
join "$status_file" "$PT_TMPDIR/defer_gatherer"
}
collect_internal_vars () {

View File

@@ -183,7 +183,7 @@ network_device_info () {
local ip_minus_s_file="$1"
if [ "$CMD_ETHTOOL" ]; then
local tempfile="$TMPDIR/ethtool_output_temp"
local tempfile="$PT_TMPDIR/ethtool_output_temp"
# For each entry in the ip -s link dump, check if itu starts with a number.
# If it does, print the second field. Then remove the colon and everything
# following that. Then skip what are usually interfaces.
@@ -298,7 +298,7 @@ find_virtualization () { local PTFUNCNAME=find_virtualization;
local dmesg_file="$2"
local lspci_file="$3"
local tempfile="$TMPDIR/find_virtualziation.tmp"
local tempfile="$PT_TMPDIR/find_virtualziation.tmp"
local virt=""
if [ -s "$dmesg_file" ]; then
@@ -395,8 +395,8 @@ mounted_fs_info () { local PTFUNCNAME=mounted_fs_info;
if [ "${platform}" = "Linux" ]; then
cmd="df -h -P"
fi
$cmd | sort > "$TMPDIR/mounted_fs_info.tmp"
mount | sort | join "$TMPDIR/mounted_fs_info.tmp" -
$cmd | sort > "$PT_TMPDIR/mounted_fs_info.tmp"
mount | sort | join "$PT_TMPDIR/mounted_fs_info.tmp" -
fi
}
@@ -409,7 +409,7 @@ raid_controller () { local PTFUNCNAME=raid_controller;
local dmesg_file="$1"
local lspci_file="$2"
local tempfile="$TMPDIR/raid_controller.tmp"
local tempfile="$PT_TMPDIR/raid_controller.tmp"
local controller=""
if [ -s "$lspci_file" ]; then

View File

@@ -23,7 +23,7 @@
# global variables for each option.
# XXX
# GLOBAL $TMPDIR AND $TOOL MUST BE SET BEFORE USING THIS LIB!
# GLOBAL $PT_TMPDIR AND $TOOL MUST BE SET BEFORE USING THIS LIB!
# XXX
# Parsing command line options with Bash is easy until we have to dealt
@@ -63,7 +63,7 @@ PO_DIR="" # Directory with program option spec files
# file - Program file with Perl POD which has usage and options.
#
# Required Global Variables:
# TIMDIR - Temp directory set by <set_TMPDIR()>.
# TIMDIR - Temp directory set by <set_PT_TMPDIR()>.
# TOOL - Tool's name.
usage() {
local file="$1"
@@ -150,7 +150,7 @@ option_error() {
# file - Program file with Perl POD options.
#
# Required Global Variables:
# TIMDIR - Temp directory set by <set_TMPDIR()>.
# TIMDIR - Temp directory set by <set_PT_TMPDIR()>.
#
# Set Global Variables:
# This sub decalres a global var for each option by uppercasing the
@@ -169,7 +169,7 @@ parse_options() {
OPT_ERRS=0
OPT_VERSION=""
OPT_HELP=""
PO_DIR="$TMPDIR/po"
PO_DIR="$PT_TMPDIR/po"
# Ready the directory for the program option (po) spec files.
if [ ! -d "$PO_DIR" ]; then
@@ -422,10 +422,10 @@ _parse_command_line() {
fi
# Find the option's spec file.
if [ -f "$TMPDIR/po/$opt" ]; then
spec="$TMPDIR/po/$opt"
if [ -f "$PT_TMPDIR/po/$opt" ]; then
spec="$PT_TMPDIR/po/$opt"
else
spec=$(grep "^short form:-$opt\$" "$TMPDIR"/po/* | cut -d ':' -f 1)
spec=$(grep "^short form:-$opt\$" "$PT_TMPDIR"/po/* | cut -d ':' -f 1)
if [ -z "$spec" ]; then
option_error "Unknown option: $real_opt"
continue

View File

@@ -476,7 +476,7 @@ find_max_trx_time() {
find_transation_states () {
local file="$1"
local tmpfile="$TMPDIR/find_transation_states.tmp"
local tmpfile="$PT_TMPDIR/find_transation_states.tmp"
[ -e "$file" ] || return
@@ -531,7 +531,7 @@ format_innodb_status () {
# then there should be multiple databases.
format_overall_db_stats () {
local file="$1"
local tmpfile="$TMPDIR/format_overall_db_stats.tmp"
local tmpfile="$PT_TMPDIR/format_overall_db_stats.tmp"
[ -e "$file" ] || return

View File

@@ -55,16 +55,16 @@ parse_proc_cpuinfo () { local PTFUNCNAME=parse_proc_cpuinfo;
name_val "Processors" "physical = ${physical}, cores = ${cores}, virtual = ${virtual}, hyperthreading = ${htt}"
awk -F: '/cpu MHz/{print $2}' "${file}" \
| sort | uniq -c > "$TMPDIR/parse_proc_cpuinfo_cpu.unq"
name_val "Speeds" "$(group_concat "$TMPDIR/parse_proc_cpuinfo_cpu.unq")"
| sort | uniq -c > "$PT_TMPDIR/parse_proc_cpuinfo_cpu.unq"
name_val "Speeds" "$(group_concat "$PT_TMPDIR/parse_proc_cpuinfo_cpu.unq")"
awk -F: '/model name/{print $2}' "${file}" \
| sort | uniq -c > "$TMPDIR/parse_proc_cpuinfo_model.unq"
name_val "Models" "$(group_concat "$TMPDIR/parse_proc_cpuinfo_model.unq")"
| sort | uniq -c > "$PT_TMPDIR/parse_proc_cpuinfo_model.unq"
name_val "Models" "$(group_concat "$PT_TMPDIR/parse_proc_cpuinfo_model.unq")"
awk -F: '/cache size/{print $2}' "${file}" \
| sort | uniq -c > "$TMPDIR/parse_proc_cpuinfo_cache.unq"
name_val "Caches" "$(group_concat "$TMPDIR/parse_proc_cpuinfo_cache.unq")"
| sort | uniq -c > "$PT_TMPDIR/parse_proc_cpuinfo_cache.unq"
name_val "Caches" "$(group_concat "$PT_TMPDIR/parse_proc_cpuinfo_cache.unq")"
}
# ##############################################################################
@@ -121,8 +121,8 @@ parse_psrinfo_cpus() { local PTFUNCNAME=parse_psrinfo_cpus;
start = index($0, " at ") + 4;
end = length($0) - start - 4
print substr($0, start, end);
}' "$file" | sort | uniq -c > "$TMPDIR/parse_psrinfo_cpus.tmp"
name_val "Speeds" "$(group_concat "$TMPDIR/parse_psrinfo_cpus.tmp")"
}' "$file" | sort | uniq -c > "$PT_TMPDIR/parse_psrinfo_cpus.tmp"
name_val "Speeds" "$(group_concat "$PT_TMPDIR/parse_psrinfo_cpus.tmp")"
}
# ##############################################################################
@@ -409,7 +409,7 @@ parse_filesystems () { local PTFUNCNAME=parse_filesystems;
}
# ##############################################################################
# Parse the output of fdisk -l, which should be in $TMPDIR/percona-toolkit; there might be
# Parse the output of fdisk -l, which should be in $PT_TMPDIR/percona-toolkit; there might be
# multiple fdisk -l outputs in the file.
# ##############################################################################
parse_fdisk () { local PTFUNCNAME=parse_fdisk;
@@ -460,7 +460,7 @@ parse_ethernet_controller_lspci () { local PTFUNCNAME=parse_ethernet_controller_
# ##############################################################################
# Parse the output of "hpacucli ctrl all show config", which should be stored in
# $TMPDIR/percona-toolkit
# $PT_TMPDIR/percona-toolkit
# ##############################################################################
parse_hpacucli () { local PTFUNCNAME=parse_hpacucli;
local file="$1"
@@ -469,7 +469,7 @@ parse_hpacucli () { local PTFUNCNAME=parse_hpacucli;
}
# ##############################################################################
# Parse the output of arcconf, which should be stored in $TMPDIR/percona-toolkit
# Parse the output of arcconf, which should be stored in $PT_TMPDIR/percona-toolkit
# ##############################################################################
parse_arcconf () { local PTFUNCNAME=parse_arcconf;
local file="$1"

View File

@@ -37,7 +37,7 @@ get_nice_of_pid () {
if [ -n "${niceness}" ]; then
echo $niceness
else
local tmpfile="$TMPDIR/nice_through_c.tmp.c"
local tmpfile="$PT_TMPDIR/nice_through_c.tmp.c"
_d "Getting the niceness from ps failed, somehow. We are about to try this:"
cat <<EOC > "$tmpfile"
#include <sys/time.h>
@@ -127,8 +127,8 @@ setup_data_dir () {
local data_dir=""
if [ -z "$existing_dir" ]; then
# User didn't specify a --save-data dir, so use a sub-dir in our tmpdir.
mkdir "$TMPDIR/data" || die "Cannot mkdir $TMPDIR/data"
data_dir="$TMPDIR/data"
mkdir "$PT_TMPDIR/data" || die "Cannot mkdir $PT_TMPDIR/data"
data_dir="$PT_TMPDIR/data"
else
# Check the user's --save-data dir.
if [ ! -d "$existing_dir" ]; then

View File

@@ -24,16 +24,16 @@
set -u
# Global variables.
TMPDIR=""
PT_TMPDIR=""
# Sub: mk_tmpdir
# Create a secure tmpdir and set TMPDIR.
# Create a secure tmpdir and set PT_TMPDIR.
#
# Optional Arguments:
# dir - User-specified tmpdir (default none).
#
# Set Global Variables:
# TMPDIR - Absolute path of secure temp directory.
# PT_TMPDIR - Absolute path of secure temp directory.
mk_tmpdir() {
local dir="${1:-""}"
@@ -41,28 +41,28 @@ mk_tmpdir() {
if [ ! -d "$dir" ]; then
mkdir "$dir" || die "Cannot make tmpdir $dir"
fi
TMPDIR="$dir"
PT_TMPDIR="$dir"
else
local tool="${0##*/}"
local pid="$$"
TMPDIR=`mktemp -d -t "${tool}.${pid}.XXXXXX"` \
PT_TMPDIR=`mktemp -d -t "${tool}.${pid}.XXXXXX"` \
|| die "Cannot make secure tmpdir"
fi
}
# Sub: rm_tmpdir
# Remove the tmpdir and unset TMPDIR.
# Remove the tmpdir and unset PT_TMPDIR.
#
# Optional Global Variables:
# TMPDIR - TMPDIR set by <mk_tmpdir()>.
# PT_TMPDIR - PT_TMPDIR set by <mk_tmpdir()>.
#
# Set Global Variables:
# TMPDIR - Set to "".
# PT_TMPDIR - Set to "".
rm_tmpdir() {
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf "$TMPDIR"
if [ -n "$PT_TMPDIR" ] && [ -d "$PT_TMPDIR" ]; then
rm -rf "$PT_TMPDIR"
fi
TMPDIR=""
PT_TMPDIR=""
}
# ###########################################################################