[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnulib-tool should be interruptible
From: |
Ralf Wildenhues |
Subject: |
gnulib-tool should be interruptible |
Date: |
Sat, 16 Sep 2006 09:06:17 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Right now, hitting ^C will make a running gnulib-tool go rather wild;
in any case, it won't make it stop consistently. I propose an approach
like in Autoconf-generated scripts, see below. Also I think a SIGPIPE
caused by a write error should be caught as well.
Cheers,
Ralf
* gnulib-tool (func_exit): New function, to allow to pass the
exit status portably through the trap. Use everywhere.
(--help, --version): Signal a write error.
(trap): catch SIGPIPE, for write errors.
Exit at the end of the trap, with the correct exit status.
Index: gnulib-tool
===================================================================
RCS file: /cvsroot/gnulib/gnulib/gnulib-tool,v
retrieving revision 1.160
diff -u -r1.160 gnulib-tool
--- gnulib-tool 13 Sep 2006 15:00:47 -0000 1.160
+++ gnulib-tool 16 Sep 2006 07:05:50 -0000
@@ -177,6 +177,13 @@
echo "# Generated by gnulib-tool."
}
+# func_exit STATUS
+# exit with status
+func_exit ()
+{
+ (exit $1); exit $1
+}
+
# func_tmpdir
# creates a temporary directory.
# Sets variable
@@ -204,7 +211,7 @@
} ||
{
echo "$0: cannot create a temporary directory in $TMPDIR" >&2
- { (exit 1); exit 1; }
+ func_exit 1
}
}
@@ -214,7 +221,7 @@
{
echo "gnulib-tool: *** $1" 1>&2
echo "gnulib-tool: *** Stop." 1>&2
- exit 1
+ func_exit 1
}
# func_readlink SYMLINK
@@ -548,10 +555,10 @@
shift ;;
--help | --hel | --he | --h )
func_usage
- exit 0 ;;
+ func_exit $? ;;
--version | --versio | --versi | --vers | --ver | --ve | --v )
func_version
- exit 0 ;;
+ func_exit $? ;;
-- )
# Stop option processing
shift
@@ -559,7 +566,7 @@
-* )
echo "gnulib-tool: unknown option $1" 1>&2
echo "Try 'gnulib-tool --help' for more information." 1>&2
- exit 1 ;;
+ func_exit 1 ;;
* )
break ;;
esac
@@ -571,7 +578,7 @@
echo "Try 'gnulib-tool --help' for more information." 1>&2
echo "If you really want to modify the gnulib configuration of your
project," 1>&2
echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
- exit 1
+ func_exit 1
fi
if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
|| test -n "$sourcebase" || test -n "$m4base" \
@@ -582,7 +589,7 @@
echo "Try 'gnulib-tool --help' for more information." 1>&2
echo "If you really want to modify the gnulib configuration of your
project," 1>&2
echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
- exit 1
+ func_exit 1
fi
do_changelog=false
fi
@@ -685,7 +692,16 @@
gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
func_tmpdir
-trap 'rm -rf "$tmp"' 0 1 2 3 15
+trap 'exit_status=$?
+ if test "$signal" != 0; then
+ echo "caught signal $signal" >&2
+ fi
+ rm -rf "$tmp"
+ exit $exit_status' 0
+for signal in 1 2 3 13 15; do
+ trap '{ signal='$signal'; func_exit 1; }' $signal
+done
+signal=0
# func_lookup_file file
# looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
@@ -2498,7 +2514,7 @@
# local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
# testsbase, libname, lgpl, makefile_name, libtool,
macro_prefix
# don't propagate from one directory to another.
- (func_import) || exit 1
+ (func_import) || func_exit 1
done
else
# Really ambiguous.
@@ -2545,7 +2561,7 @@
if test -n "$remaining"; then
echo "Remaining files:" $remaining 1>&2
echo "gnulib-tool: *** Stop." 1>&2
- exit 1
+ func_exit 1
fi
cd ..
cd ..
@@ -2568,7 +2584,7 @@
if test -n "$remaining"; then
echo "Remaining files:" $remaining 1>&2
echo "gnulib-tool: *** Stop." 1>&2
- exit 1
+ func_exit 1
fi
cd ..
cd ..
@@ -2671,12 +2687,12 @@
rm -rf "$tmp"
# Undo the effect of the previous 'trap' command. Some shellology:
-# We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
+# We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
# execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
# exit); for the others we need to call 'exit' explicitly. The value of $? is
# 128 + signal number and is set before the trap-registered command is run.
trap '' 0
-trap 'exit $?' 1 2 3 15
+trap 'func_exit $?' 1 2 3 13 15
exit 0
- gnulib-tool should be interruptible,
Ralf Wildenhues <=