neno: Clean-up no longer needed: tmpfile are unlinked but kept open.

This commit is contained in:
Ole Tange 2020-05-28 21:35:37 +02:00
parent 6902fe306a
commit 38dfa767fb

View file

@ -63,38 +63,24 @@ B<man>
=cut
print() {
cat $TMP/stdout >&3
cat $TMP/stderr >&4
}
_tmp=$(mktemp -d /tmp/no-error.XXXXX)
true 2>$_tmp/stderr >$_tmp/stdout
# Save original stdout/stderr
exec 11>&1 12>&2
# Redirect stdout/stderr to tmpfiles
exec 1>$_tmp/stdout 2>$_tmp/stderr
# Open the tmpfiles for reading
exec 21<$_tmp/stdout 22<$_tmp/stderr
# Unlink files (but keep them open)
rm -rf $_tmp
cleanup() {
rm -rf $TMP
return $?
}
control_c() {
# Run if user hits control-C
# >&4 is the non-redirected stderr
echo >&4
print
echo -en "\n$0: CTRL-C hit: Exiting.\n" >&4
cleanup
exit $?
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
TMP=$(mktemp -d /tmp/no-error.XXXXX)
exec 3>&1 4>&2
eval $* 2>$TMP/stderr >$TMP/stdout
ERROR=$?
if [ $ERROR == 0 ] ; then
# skip
true
eval "$@"
_error=$?
if [ $_error == 0 ] ; then
# skip
true
else
print
cat 0<&21 >&11
cat 0<&22 >&12
fi
cleanup
exit $ERROR
exit $_error