From 5c83d53b777250ed11f06e43350739805b5cb4cf Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 7 Sep 2016 17:56:16 +0200 Subject: scripts/restore-etc: get rid of function "die" This function causes trouble combined with temporary files as it exits without cleaning anything. Let's kill it and let the callers perform the cleanup. --- scripts/restore-etc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/restore-etc b/scripts/restore-etc index ff1775a..9256ee5 100755 --- a/scripts/restore-etc +++ b/scripts/restore-etc @@ -124,14 +124,6 @@ list_changes() { fi } -# kills the program and outputs an error if provided. -function die { - local ret="$1" - shift - [ -n "$*" ] && echo "$@" >&2 - exit $ret -} - # tries to unmount /etc unmount_etc() { while umount "$ROOTDIR/etc" >/dev/null 2>&1; do : ; done @@ -165,7 +157,11 @@ try_restore_config() { if [ "$config" = "-" ]; then # restore from stdin - temp_cfg_dir="$(mkstemp)" || die 1 "Cannot create a temporary directory in '${TMPDIR-/tmp}'." + temp_cfg_dir="$(mkstemp)" + if [ $? -ne 0 ]; then + echo "Cannot create a temporary directory in '${TMPDIR-/tmp}'." >&2 + return 1 + fi config="$temp_cfg_dir/stdin" cat > "$temp_cfg_dir/stdin" fi -- 1.7.12.1