try and improve the control-c trapping

This commit is contained in:
chess.griffin 2008-11-11 20:46:11 +00:00
parent 0710c04d04
commit a2a4fdc8e3

View file

@ -30,9 +30,9 @@
# Wisehart, slakmagik, Eric Hameleers, Michiel van Wessem, hba, Erik # Wisehart, slakmagik, Eric Hameleers, Michiel van Wessem, hba, Erik
# Hanson, Antoine, ktabic, Ken Roberts, samac, Bert Babington, Murat # Hanson, Antoine, ktabic, Ken Roberts, samac, Bert Babington, Murat
# D. Kadirov, The-spiki, David Somero, LukenShiro, Drew Ames, nille, # D. Kadirov, The-spiki, David Somero, LukenShiro, Drew Ames, nille,
# acidchild, mancha, macavity, Zordrak, and Joao Felipe Santos. This # acidchild, mancha, macavity, Zordrak, Joao Felipe Santos, and
# script would not be where it is without the help of these folks. # cotterochan. This script would not be where it is without the help
# Thank you! # of these folks. Thank you!
#set -x #set -x
# Variables # Variables
@ -601,7 +601,7 @@ as the root user in order to build packages." 8 30
# that were created along the way. See the comment to the # that were created along the way. See the comment to the
# control_c function as well. Also, see the similar code # control_c function as well. Also, see the similar code
# at the get_source function. # at the get_source function.
( build_package $APP >> $SBOPKGOUTPUT & echo $! >> $TMP/sbopkg-build.pid ) 2>>$SBOPKGOUTPUT ( build_package $APP >> $SBOPKGOUTPUT & echo $! >> $TMP/sbopkgpidlist ) 2>>$SBOPKGOUTPUT
while [ -f $TMP/sbopkg_build.lck ]; do while [ -f $TMP/sbopkg_build.lck ]; do
dialog --backtitle "Building the $APP package." \ dialog --backtitle "Building the $APP package." \
--tailbox $SBOPKGOUTPUT 18 70 --tailbox $SBOPKGOUTPUT 18 70
@ -953,8 +953,8 @@ if [ ! -e $PKGPATH/$SRCNAME ]; then
# when a user presses Control-C. Please see the comments # when a user presses Control-C. Please see the comments
# above around line 530 when build_package is first called as # above around line 530 when build_package is first called as
# well as the comments to the control_c function, below. # well as the comments to the control_c function, below.
wget $WGETFLAGS $DOWNLOAD -O $DOWNLOADFILE >> $SBOPKGOUTPUT & echo $! >> $TMP/sbopkg-build.pid 2>>$SBOPKGOUTPUT wget $WGETFLAGS $DOWNLOAD -O $DOWNLOADFILE >> $SBOPKGOUTPUT & echo "$!" >> $TMP/sbopkgpidlist 2>>$SBOPKGOUTPUT
#( wget -c -t 5 -T $TIMEOUT --progress=bar $DOWNLOAD -O $DOWNLOADFILE >> $SBOPKGOUTPUT & echo $! >> $TMP/sbopkg-build.pid ) 2>>$SBOPKGOUTPUT #( wget -c -t 5 -T $TIMEOUT --progress=bar $DOWNLOAD -O $DOWNLOADFILE >> $SBOPKGOUTPUT & echo $! >> $TMP/sbopkgpidlist ) 2>>$SBOPKGOUTPUT
wait wait
cd - cd -
ln -s $SRCDIR/$SRCNAME $LOCALREPO/$SLACKVER/$PKGPATH/$SRCNAME ln -s $SRCDIR/$SRCNAME $LOCALREPO/$SLACKVER/$PKGPATH/$SRCNAME
@ -1053,9 +1053,11 @@ if [ "$SLACKBUILD" = "original" ]; then
# The following pid stuff isn't working right now. If a user # The following pid stuff isn't working right now. If a user
# exists the build process, it continues going in the background. # exists the build process, it continues going in the background.
# This works for cancelling the wget source, but not the build. # This works for cancelling the wget source, but not the build.
# Search this script for other instances of sbopkg-build.pid and # Search this script for other instances of sbopkgpidlist and
# you'll see where I'm hacking on this. # you'll see where I'm hacking on this.
# ( sh $PKG.SlackBuild & >> $SBOPKGOUTPUT echo $! >> $TMP/sbopkg-build.pid ) 2>>$SBOPKGOUTPUT #sh $PKG.SlackBuild &
#echo "$!" >> $TMP/sbopkgpidlist 2>>$SBOPKGOUTPUT
#wait
fi fi
if [ "$SLACKBUILD" = "local" ]; then if [ "$SLACKBUILD" = "local" ]; then
sh $PKG.SlackBuild.sbopkg || rm -rf $TMP/sbopkg_build.lck sh $PKG.SlackBuild.sbopkg || rm -rf $TMP/sbopkg_build.lck
@ -1263,7 +1265,7 @@ cd $CWD
control_c () { control_c () {
# This function holds the commands that will be executed when the user # This function holds the commands that will be executed when the user
# presses Control-C. The $TMP/sbopkg-build.pid file is file to which # presses Control-C. The $TMP/sbopkgpidlist file is file to which
# various PID's are written to as certain background processes etc. # various PID's are written to as certain background processes etc.
# are executed. For example, look at the wget command in the # are executed. For example, look at the wget command in the
# get_source function, above. I am trying to work out a way where a # get_source function, above. I am trying to work out a way where a
@ -1273,17 +1275,22 @@ control_c () {
# the wget step but not the building step. I would really like to # the wget step but not the building step. I would really like to
# have this working well, so suggestions/diffs etc. would be greatly # have this working well, so suggestions/diffs etc. would be greatly
# appreciated. :-) # appreciated. :-)
echo "Trying to exit cleanly..."; echo "Control-C detected. Trying to exit cleanly...";
for pid in $(cat $TMP/sbopkg-build.pid); do if [ -e $TMP/sbopkgpidlist ]; then
echo "killing $pid" for pid in $(cat $TMP/sbopkgpidlist); do
kill -9 $pid; echo "killing $pid"
done; kill -9 $pid;
done;
rm -rf $TMP/oldbuildpid
mv $TMP/sbopkgpidlist $TMP/oldbuildpid
rm -rf $TMP/sbopkgpidlist
fi
rm -rf $TMP/sbopkg_* rm -rf $TMP/sbopkg_*
rm -rf $TMP/oldbuildpid if [ "$DIAG" = 1 ]; then
mv $TMP/sbopkg-build.pid $TMP/oldbuildpid break
#rm -rf $TMP/sbopkg-build.pid else
break exit 0
#exit 0 fi
} }
main_menu () { main_menu () {