Skip to content

Commit

Permalink
bash error changes ported to 202012
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
  • Loading branch information
vivekrnv committed Sep 29, 2021
1 parent 0b5f90b commit 86919fa
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ save_bcmcmd() {
local do_gzip=${3:-false}
local tarpath="${BASE}/dump/$filename"
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
fi

if [ $SKIP_BCMCMD -eq 1 ]; then
echo "Skip $cmd"
Expand All @@ -78,8 +80,8 @@ save_bcmcmd() {
if $NOOP; then
echo "${timeout_cmd} $cmd &> '${filepath}'"
else
eval "${timeout_cmd} $cmd" &> "${filepath}"
ret=$?
ret=0
eval "${timeout_cmd} $cmd" &> "${filepath}" || ret=$?
if [ $ret -ne 0 ]; then
if [ $ret -eq 124 ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
Expand Down Expand Up @@ -164,15 +166,16 @@ save_cmd() {
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local redirect='&>'
local redirect_eval='2>&1'
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
fi

if ! $SAVE_STDERR
then
redirect=">"
redirect_eval=""
fi

[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR

# eval required here to re-evaluate the $cmd properly at runtime
# This is required if $cmd has quoted strings that should be bunched
# as one argument, e.g. vtysh -c "COMMAND HERE" needs to have
Expand Down Expand Up @@ -264,12 +267,13 @@ copy_from_docker() {
echo "${timeout_cmd} ${touch_cmd}"
echo "${timeout_cmd} ${cp_cmd}"
else
eval "${timeout_cmd} ${touch_cmd}"
if [ $? -ne 0 ]; then
RC=0
eval "${timeout_cmd} ${touch_cmd}" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $touch_cmd timedout after ${TIMEOUT_MIN} minutes."
fi
eval "${timeout_cmd} ${cp_cmd}"
if [ $? -ne 0 ]; then
eval "${timeout_cmd} ${cp_cmd}" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $cp_cmd timedout after ${TIMEOUT_MIN} minutes."
fi
fi
Expand Down Expand Up @@ -710,7 +714,9 @@ save_file() {
local tar_path="${BASE}/$supp_dir/$(basename $orig_path)"
local do_gzip=${3:-true}
local do_tar_append=${4:-true}
[ ! -d "$TARDIR/$supp_dir" ] && $MKDIR $V -p "$TARDIR/$supp_dir"
if [ ! -d "$TARDIR/$supp_dir" ]; then
$MKDIR $V -p "$TARDIR/$supp_dir"
fi

if $do_gzip; then
gz_path="${gz_path}.gz"
Expand Down Expand Up @@ -1244,8 +1250,9 @@ main() {
$RM $V -rf $TARDIR

if $DO_COMPRESS; then
$GZIP $V $TARFILE
if [ $? -eq 0 ]; then
RC=0
$GZIP $V $TARFILE || RC=$?
if [ $RC -eq 0 ]; then
TARFILE="${TARFILE}.gz"
else
echo "WARNING: gzip operation appears to have failed." >&2
Expand Down

0 comments on commit 86919fa

Please sign in to comment.