Add timeout for dotnet process
authorWonYoung Choi <wy80.choi@samsung.com>
Fri, 18 Aug 2017 08:28:26 +0000 (17:28 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Fri, 18 Aug 2017 08:28:26 +0000 (17:28 +0900)
Change-Id: I8d7c8d1071df49d4257304531200cdbbb802514c

Tools/dotnet-build.sh
Tools/timeout.sh [new file with mode: 0755]
packaging/dotnet-build-tools.spec

index 080a48b..bd18dab 100755 (executable)
@@ -48,7 +48,7 @@ run_xbuild() {
 
 run_dotnet() {
   echo "+ dotnet $@"
-  dotnet $@
+  timeout 600 dotnet $@
   exit_on_error $?
 }
 
@@ -80,7 +80,7 @@ build_project() {
 
 cmd_restore() {
   if $USE_DOTNET_CLI; then
-    update_version_to_asterisk # update PackageReference version to * in .csproj
+    ## update_version_to_asterisk # update PackageReference version to * in .csproj
     local OPTS=""
     [ -n "$SOURCE" ] && OPTS="$OPTS -s $SOURCE"
     run_dotnet restore $PROJECT $OPTS $@
@@ -218,8 +218,8 @@ elif [ -d $PROJECT ]; then
   fi
 fi
 
-# Disable telemetry of dotnet
 export DOTNET_CLI_TELEMETRY_OPTOUT=1
+export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
 
 # To build PCL projects ReferenceAssemblyRoot should be set.
 # dotnet-cli will find reference assemblies for PCL in this path.
diff --git a/Tools/timeout.sh b/Tools/timeout.sh
new file mode 100755 (executable)
index 0000000..c7273d0
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# Execute a command with a timeout
+
+# License: LGPLv2
+# Author:
+#    http://www.pixelbeat.org/
+# Notes:
+#    Note there is a timeout command packaged with coreutils since v7.0
+#    If the timeout occurs the exit status is 124.
+#    There is an asynchronous (and buggy) equivalent of this
+#    script packaged with bash (under /usr/share/doc/ in my distro),
+#    which I only noticed after writing this.
+#    I noticed later again that there is a C equivalent of this packaged
+#    with satan by Wietse Venema, and copied to forensics by Dan Farmer.
+# Changes:
+#    V1.0, Nov  3 2006, Initial release
+#    V1.1, Nov 20 2007, Brad Greenlee <brad@footle.org>
+#                       Make more portable by using the 'CHLD'
+#                       signal spec rather than 17.
+#    V1.3, Oct 29 2009, Ján Sáreník <jasan@x31.com>
+#                       Even though this runs under dash,ksh etc.
+#                       it doesn't actually timeout. So enforce bash for now.
+#                       Also change exit on timeout from 128 to 124
+#                       to match coreutils.
+#    V2.0, Oct 30 2009, Ján Sáreník <jasan@x31.com>
+#                       Rewritten to cover compatibility with other
+#                       Bourne shell implementations (pdksh, dash)
+
+if [ "$#" -lt "2" ]; then
+    echo "Usage:   `basename $0` timeout_in_seconds command" >&2
+    echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2
+    exit 1
+fi
+
+cleanup()
+{
+    trap - ALRM               #reset handler to default
+    kill -ALRM $a 2>/dev/null #stop timer subshell if running
+    kill $! 2>/dev/null &&    #kill last job
+      exit 124                #exit with 124 if it was running
+}
+
+watchit()
+{
+    trap "cleanup" ALRM
+    sleep $1& wait
+    kill -ALRM $$
+}
+
+watchit $1& a=$!         #start the timeout
+shift                    #first param was timeout for sleep
+trap "cleanup" ALRM INT  #cleanup after timeout
+"$@"& wait $!; RET=$?    #start the job wait for it and save its return value
+kill -ALRM $a            #send ALRM signal to watchit
+wait $a                  #wait for watchit to finish cleanup
+exit $RET                #return the value
+
index f893025..23fd3c7 100644 (file)
@@ -3,7 +3,7 @@
 
 Name:       dotnet-build-tools
 Summary:    Tools for building C# API projects
-Version:    1.2.9
+Version:    1.3.0
 Release:    1
 Group:      Development/Libraries
 License:    MIT and Apache-2.0
@@ -58,6 +58,7 @@ mkdir -p %{buildroot}%{_bindir}
 mkdir -p %{buildroot}%{TOOLS_PATH}
 install -p -m 755 Tools/* %{buildroot}%{TOOLS_PATH}
 ln -s %{TOOLS_PATH}/dotnet-build.sh %{buildroot}%{_bindir}/dotnet-build
+ln -s %{TOOLS_PATH}/timeout.sh %{buildroot}%{_bindir}/timeout
 
 # dotnet-cli
 mkdir -p %{buildroot}%{CLI_PATH}