From: Kern Sibbald Date: Sat, 28 Jan 2012 14:46:08 +0000 (+0100) Subject: Make mtx-changer more fault tolerant X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=af2d8bddad2f1d7643c8fa3f5d618b15bcf9f450;p=bacula%2Fbacula Make mtx-changer more fault tolerant --- diff --git a/bacula/scripts/mtx-changer.in b/bacula/scripts/mtx-changer.in index ca5c5481ff..fe23051edf 100644 --- a/bacula/scripts/mtx-changer.in +++ b/bacula/scripts/mtx-changer.in @@ -82,6 +82,29 @@ make_temp_file() { fi } +# +# Create a temporary file for stderr +# +# Note, this file is used because sometime mtx emits +# unexpected error messages followed by the output +# expected during success. +# So we separate STDOUT and STDERR in +# certain of the mtx commands. The contents of STDERR +# is then printed after the STDOUT produced by mtx +# thus we sometimes get better changer results. +# +make_err_file() { + ERRFILE=`mktemp @working_dir@/mtx.err.XXXXXXXXXX` + if test x${ERRFILE} = x; then + ERRFILE="@working_dir@/mtx.err.$$" + if test -f ${ERRFILE}; then + echo "ERROR: Temp file security problem on: ${ERRFILE}" + exit 1 + fi + fi +} + + # # The purpose of this function to wait a maximum # time for the drive. It will @@ -160,17 +183,25 @@ case $cmd in if test ${offline_sleep} -ne 0 ; then sleep ${offline_sleep} fi - ${MTX} -f $ctl unload $slot $drive + make_err_file + ${MTX} -f $ctl unload $slot $drive 2>${ERRFILE} + rtn=$? + cat ${ERRFILE} + rm -f ${ERRFILE} >/dev/null 2>&1 + exit $rtn ;; load) debug "Doing mtx -f $ctl load $slot $drive" - ${MTX} -f $ctl load $slot $drive + make_err_file + ${MTX} -f $ctl load $slot $drive 2>${ERRFILE} rtn=$? if test ${load_sleep} -ne 0 ; then sleep ${load_sleep} fi wait_for_drive $device + cat ${ERRFILE} + rm -f ${ERRFILE} >/dev/null 2>&1 exit $rtn ;;