[Qemu-devel] [RFC PATCH RESEND 1/2] scripts: helper to keep console alive

Philippe Mathieu-Daudé posted 2 patches 8 years, 7 months ago
[Qemu-devel] [RFC PATCH RESEND 1/2] scripts: helper to keep console alive
Posted by Philippe Mathieu-Daudé 8 years, 7 months ago
useful to avoid Travis CI jobs getting killed after 10min of inactivity.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 MAINTAINERS          |  1 +
 scripts/aliveness.sh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100755 scripts/aliveness.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index 9529c9484c..c39f418a13 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1866,6 +1866,7 @@ S: Maintained
 F: .travis.yml
 F: .shippable.yml
 F: tests/docker/
+F: scripts/aliveness.sh
 W: https://travis-ci.org/qemu/qemu
 W: https://app.shippable.com/github/qemu/qemu
 W: http://patchew.org/QEMU/
diff --git a/scripts/aliveness.sh b/scripts/aliveness.sh
new file mode 100755
index 0000000000..1c2b6136b9
--- /dev/null
+++ b/scripts/aliveness.sh
@@ -0,0 +1,32 @@
+#! /usr/bin/env sh
+#
+# Send an "Alive!" message regularly to stderr
+#
+# Copyright (C) 2017 Philippe Mathieu-Daudé
+#
+# Author: Philippe Mathieu-Daudé <f4bug@amsat.org>
+#
+# This work is licensed under the terms of the GNU LGPL, version 2+.
+# See the COPYING file in the top-level directory.
+
+TIMEOUT_S=$1
+shift 1
+{
+  set -e
+  while true
+  do
+    sleep ${TIMEOUT_S}
+    echo "Alive!" >&2
+  done
+} &
+WATCHDOG_PID=$!
+
+cleanup() {
+    echo "killing watchdog ${WATCHDOG_PID}" >&2
+    kill -TERM ${WATCHDOG_PID}
+    exit $((1 - $#))
+}
+trap cleanup INT
+
+$*
+cleanup 0
-- 
2.13.2


Re: [Qemu-devel] [RFC PATCH RESEND 1/2] scripts: helper to keep console alive
Posted by Eric Blake 8 years, 7 months ago
On 07/13/2017 05:03 AM, Philippe Mathieu-Daudé wrote:
> useful to avoid Travis CI jobs getting killed after 10min of inactivity.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  MAINTAINERS          |  1 +
>  scripts/aliveness.sh | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
>  create mode 100755 scripts/aliveness.sh
> 

> +++ b/scripts/aliveness.sh
> @@ -0,0 +1,32 @@
> +#! /usr/bin/env sh

Overkill.  /bin/sh exists everywhere, the only need for using 'env' is
where a program does not have a reliable installation path across platforms.

> +#
> +# Send an "Alive!" message regularly to stderr
> +#
> +# Copyright (C) 2017 Philippe Mathieu-Daudé
> +#
> +# Author: Philippe Mathieu-Daudé <f4bug@amsat.org>
> +#
> +# This work is licensed under the terms of the GNU LGPL, version 2+.
> +# See the COPYING file in the top-level directory.
> +
> +TIMEOUT_S=$1
> +shift 1
> +{
> +  set -e
> +  while true
> +  do
> +    sleep ${TIMEOUT_S}
> +    echo "Alive!" >&2
> +  done
> +} &
> +WATCHDOG_PID=$!
> +
> +cleanup() {
> +    echo "killing watchdog ${WATCHDOG_PID}" >&2
> +    kill -TERM ${WATCHDOG_PID}
> +    exit $((1 - $#))

This looks odd - what are you really trying to accomplish here?  A
different exit status according to whether the watchdog exited normally
or was killed?  A reflection of the exit status of the command being run
in parallel with the watchdog?

> +}
> +trap cleanup INT

Don't you want to clean up on more than just INT?  The more typical
spelling is:

trap cleanup 0 1 2 3 15

> +
> +$*

Huh? Oh, you're expecting this to be called as "aliveness.sh $TIMEOUT
$command to run".  Some usage comments would be nice.

> +cleanup 0
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org