[Libreoffice-commits] .: 2 commits - bin/timeout3 git-hooks/pre-commit Makefile.am

Jan Holesovsky kendy at kemper.freedesktop.org
Thu Nov 11 08:07:30 PST 2010


 Makefile.am          |   12 ++----
 bin/timeout3         |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 git-hooks/pre-commit |   13 +++----
 3 files changed, 104 insertions(+), 14 deletions(-)

New commits:
commit 2806327d6ce12351abe013132e0d656bf19202cc
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Thu Nov 11 17:03:39 2010 +0100

    smoketest: Now timeout correctly during make smoketest.
    
    Use an existing script for timing out, than the fragile one-line bash hackery.
    The script is added as a part of this commit.

diff --git a/Makefile.am b/Makefile.am
index 7f9f982..2b4361f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -165,14 +165,10 @@ $(BUILDDIR)/install/program/ooenv: $(STAMP_DIR)/build
 
 # Run smoketest, but timeout in 15 minutes if it got stuck
 smoketest: $(BUILDDIR)/install/program/ooenv
-	( ( . $(OOBUILDDIR)/*.Set.sh ; export SAL_USE_VCLPLUGIN="svp" ; \
-	    cd $(OOBUILDDIR)/test && build.pl && deliver.pl && \
-	    cd $(OOBUILDDIR)/smoketestoo_native && build.pl ) & \
-	  ( COMMAND_PID=$$! ; DELAY=$$((15*60)) ; \
-	    while test "$$DELAY" -gt "0" && ps "$$COMMAND_PID" > /dev/null ; do \
-	        sleep 1 ; DELAY=$$(($$DELAY-1)) ; \
-	    done ; \
-	    ps "$$COMMAND_PID" > /dev/null && ( kill "$$COMMAND_PID" ; echo "Smoketest timed out, killed." ; exit 1 ) ) )
+	( . $(OOBUILDDIR)/*.Set.sh ; export SAL_USE_VCLPLUGIN="svp" ; \
+	  cd $(OOBUILDDIR)/test && build.pl && deliver.pl && \
+	  cd $(OOBUILDDIR)/smoketestoo_native && \
+	  $(TOOLSDIR)/bin/timeout3 -t $$((15*60)) build.pl )
 
 id : $(OOBUILDDIR)/ID
 $(OOBUILDDIR)/ID : $(STAMP_DIR)/build
diff --git a/bin/timeout3 b/bin/timeout3
new file mode 100755
index 0000000..9e26253
--- /dev/null
+++ b/bin/timeout3
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+#
+# The Bash shell script executes a command with a time-out.
+# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
+# is blocked, then the subsequent SIGKILL (9) terminates it.
+#
+# Based on the Bash documentation example.
+
+# Hello Chet,
+# please find attached a "little easier"  :-)  to comprehend
+# time-out example.  If you find it suitable, feel free to include
+# anywhere: the very same logic as in the original examples/scripts, a
+# little more transparent implementation to my taste.
+#
+# Dmitry V Golovashkin <Dmitry.Golovashkin at sas.com>
+#
+# http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3
+
+scriptName="${0##*/}"
+
+declare -i DEFAULT_TIMEOUT=9
+declare -i DEFAULT_INTERVAL=1
+declare -i DEFAULT_DELAY=1
+
+# Timeout.
+declare -i timeout=DEFAULT_TIMEOUT
+# Interval between checks if the process is still alive.
+declare -i interval=DEFAULT_INTERVAL
+# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
+declare -i delay=DEFAULT_DELAY
+
+function printUsage() {
+    cat <<EOF
+
+Synopsis
+    $scriptName [-t timeout] [-i interval] [-d delay] command
+    Execute a command with a time-out.
+    Upon time-out expiration SIGTERM (15) is sent to the process. If SIGTERM
+    signal is blocked, then the subsequent SIGKILL (9) terminates it.
+
+    -t timeout
+        Number of seconds to wait for command completion.
+        Default value: $DEFAULT_TIMEOUT seconds.
+
+    -i interval
+        Interval between checks if the process is still alive.
+        Positive integer, default value: $DEFAULT_INTERVAL seconds.
+
+    -d delay
+        Delay between posting the SIGTERM signal and destroying the
+        process by SIGKILL. Default value: $DEFAULT_DELAY seconds.
+
+As of today, Bash does not support floating point arithmetic (sleep does),
+therefore all delay/time values must be integers.
+EOF
+}
+
+# Options.
+while getopts ":t:i:d:" option; do
+    case "$option" in
+        t) timeout=$OPTARG ;;
+        i) interval=$OPTARG ;;
+        d) delay=$OPTARG ;;
+        *) printUsage; exit 1 ;;
+    esac
+done
+shift $((OPTIND - 1))
+
+# $# should be at least 1 (the command to execute), however it may be strictly
+# greater than 1 if the command itself has options.
+if (($# == 0 || interval <= 0)); then
+    printUsage
+    exit 1
+fi
+
+# kill -0 pid   Exit code indicates if a signal may be sent to $pid process.
+(
+    ((t = timeout))
+
+    while ((t > 0)); do
+        sleep $interval
+        kill -0 $$ || exit 0
+        ((t -= interval))
+    done
+
+    # Be nice, post SIGTERM first.
+    # The 'exit 0' below will be executed if any preceeding command fails.
+    kill -s SIGTERM $$ && kill -0 $$ || exit 0
+    sleep $delay
+    kill -s SIGKILL $$
+) 2> /dev/null &
+
+exec "$@"
commit 38d28818b7fbf54f0b6b7cdfd2f82652689fddc6
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Thu Nov 11 17:02:10 2010 +0100

    git-hooks: Fix the check for leading tabs to work only some file types.
    
    The check for the file types was by mistake left out during the bash -> Perl
    change.

diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 5a9a4b4..253f2dd 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -121,17 +121,18 @@ EOM
 
 # be strict about tabs - we don't want them at all, setup your editor
 # correctly ;-)
-my $check_ext = '\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml)$';
 my $err_ext = "";
 
 open( FILES, "git diff-index --cached --name-only $against |" ) || die "Cannot run git diff-index.";
 while ( my $file = <FILES> ) {
     chomp( $file );
-    open( F, "git diff-index -p --cached $against -- '$file' |" );
-    while ( my $line = <F> ) {
-        if ( $line =~ /^\+ *\t/ ) {
-            $err_ext .= "$file\n";
-            last;
+    if ( $file =~ /\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml)$/) {
+        open( F, "git diff-index -p --cached $against -- '$file' |" );
+        while ( my $line = <F> ) {
+            if ( $line =~ /^\+ *\t/ ) {
+                $err_ext .= "$file\n";
+                last;
+            }
         }
     }
     close( F );


More information about the Libreoffice-commits mailing list