neno: Clean-up no longer needed: tmpfile are unlinked but kept open.
This commit is contained in:
parent
6902fe306a
commit
38dfa767fb
46
neno/neno
46
neno/neno
|
@ -63,38 +63,24 @@ B<man>
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
print() {
|
_tmp=$(mktemp -d /tmp/no-error.XXXXX)
|
||||||
cat $TMP/stdout >&3
|
true 2>$_tmp/stderr >$_tmp/stdout
|
||||||
cat $TMP/stderr >&4
|
# 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() {
|
eval "$@"
|
||||||
rm -rf $TMP
|
_error=$?
|
||||||
return $?
|
if [ $_error == 0 ] ; then
|
||||||
}
|
|
||||||
|
|
||||||
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
|
# skip
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
print
|
cat 0<&21 >&11
|
||||||
|
cat 0<&22 >&12
|
||||||
fi
|
fi
|
||||||
cleanup
|
exit $_error
|
||||||
exit $ERROR
|
|
||||||
|
|
Loading…
Reference in a new issue