-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduced a wrapper script to either directly call an existing
'timeout' command (e.g. on RaspberryMatic) or to use shell syntax to replicate the same functionality just using shell functionality. This should hopefully solve any licensing issues between GPL and Apache2 license under which this check_mk_agent is licensed.
- Loading branch information
Showing
5 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/sh | ||
# | ||
# wrapper script to either directly call /usr/bin/timeout or to simply | ||
# call an own shell-based implementation. This script is CCU2, CCU3 and | ||
# RaspberryMatic compatible. | ||
# | ||
# Copyright (c) 2019 Jens Maus <[email protected]> | ||
# Apache 2.0 License applies. | ||
# | ||
|
||
# if a BusyBox timeout command is already present we use that | ||
# one. Instead we use shell functionality to replicate the same | ||
# functionality in terminating commands after a certain amount | ||
# of time. | ||
if [[ -n "$(type -p timeout 2>&1)" ]]; then | ||
timeout "$@" | ||
exit $? | ||
else | ||
# default values | ||
maxtime=10 | ||
signal=SIGTERM | ||
|
||
# Options | ||
O=$(getopt -- :t:s: "$@") || exit 1 | ||
eval set -- "${O}" | ||
while true; do | ||
case "${1}" in | ||
-t) maxtime=${2}; shift 2;; | ||
-s) signal=${2}; shift 2;; | ||
--) shift; break;; | ||
*) exit 1;; | ||
esac | ||
done | ||
|
||
# lets sleep first | ||
sleep "${maxtime}" & | ||
SPID=${!} | ||
|
||
# execute the actual command | ||
("$@"; RETVAL=$?; kill ${SPID}; exit ${RETVAL}) & | ||
CPID=${!} | ||
wait %1 | ||
SLEEPRETVAL=$? | ||
if [[ ${SLEEPRETVAL} -eq 0 ]] && kill -${signal} ${CPID} >/dev/null 2>&1 ; then | ||
RETVAL=143 | ||
#(sleep 1; kill -9 ${CPID} >/dev/null 2>&1)& | ||
wait %2 | ||
else | ||
wait %2 | ||
RETVAL=$? | ||
fi | ||
exit $RETVAL | ||
fi |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters