diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-12-03 16:25:24 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-12-03 16:25:25 -0500 |
commit | 079d1dcfafd3eb75156bc513db81c623b66bc41b (patch) | |
tree | f20c8d393d6ad747137ef1c599e96f3d27b346b1 | |
parent | 210693c22fa86708cca7a0e102b7d823f16239fb (diff) | |
download | tame-079d1dcfafd3eb75156bc513db81c623b66bc41b.tar.gz tame-079d1dcfafd3eb75156bc513db81c623b66bc41b.tar.bz2 tame-079d1dcfafd3eb75156bc513db81c623b66bc41b.zip |
tamed: Do not stall if TAMED_SPAWER_PID is running
This will ensure that tamed does not stall while e.g. make is still
running. This makes TAMED_STALL_SECONDS almost useless; maybe it'll be
removed in future versions.
* bin/tame (TAMED_SPAWNER_PID): Export variable.
* bin/tamed (TAMED_SPAWNER_PID): New variable, default to PPID.
(spawner-dead): New function.
(stall-monitor): Use it.
(usage): Update documentation.
* build-aux/Makefile.am: Set TAMED_SPAWNER_PID to own id and export.
-rwxr-xr-x | bin/tame | 1 | ||||
-rwxr-xr-x | bin/tamed | 38 | ||||
-rw-r--r-- | build-aux/Makefile.am | 3 |
3 files changed, 38 insertions, 4 deletions
@@ -31,6 +31,7 @@ declare -ri TAME_CMD_WAITTIME="${TAME_CMD_WAITTIME:-3}" # propagate to daemon export TAMED_STALL_SECONDS +export TAMED_SPAWNER_PID # Send a single command to a runner and observe the result @@ -25,8 +25,12 @@ declare -ri EX_RUNNING=1 declare -ri EX_USAGE=64 # incorrect usage; sysexits.h declare -ri EX_CANTCREAT=73 # cannot create file; sysexits.h -# number of seconds before runners are considered unused and terminate -declare -ri TAMED_STALL_SECONDS="${TAMED_STALL_SECONDS:-30}" +# number of seconds of output silence before runners are considered unused +# and are subject to termination (see stall-monitor) +declare -ri TAMED_STALL_SECONDS="${TAMED_STALL_SECONDS:-1}" + +# id of process that indirectly spawned tamed (default $PPID) +declare -ri TAMED_SPAWNER_PID="${TAMED_SPAWNER_PID:-$PPID}" # set by `main', global for `cleanup' declare root= @@ -106,6 +110,11 @@ spawn-runner() # can easily be <=30s even for large packages. This may need to change in # the future if it becomes too much less chatty. Increase that environment # variable if runners stall unexpectedly in the middle of builds. +# +# If the id of the spawning process has been provided then we will never +# consider ourselves to be stalled if that process is still running. This +# prevents, for example, tamed from killing itself while a parent make +# process is still running. stall-monitor() { local -r base="${1?Missing base}" @@ -119,6 +128,8 @@ stall-monitor() # keep waiting if there has been activity since $since test "$last" -le "$since" || continue + spawner-dead || continue + # no activity; kill local -r pid=$( cat "$base/pid" ) kill "$pid" @@ -130,6 +141,18 @@ stall-monitor() } +# Check to see if the spawning process has died +# +# If no spawning process was provided, then this always returns a zero +# status. Otherwise, it returns whether the given pid is _not_ running. +spawner-dead() +{ + test "$TAMED_SPAWNER_PID" -gt 0 || return 0 + + ! ps "$TAMED_SPAWNER_PID" &>/dev/null +} + + # Exit if tamed is already running at path ROOT # # If tamed is already running at ROOT, exit with status @@ -199,7 +222,12 @@ The default value of RUNPATH is \`/run/user/$UID/tamed'. Only one runner is currently supported. tamed exits once all runners have terminated. Runners will be killed once they are -inactive for at least TAMED_STALL_SECONDS (default 30). +inactive for at least TAMED_STALL_SECONDS (default 1), unless +the process identified by TAMED_SPAWNER_PID is still running. +For example, a build script may wish to set TAMED_SPAWNER_PID +to the process id of make itself. It defaults to the actual +parent process id (PPID), so tamed will never kill itself if +run manually on a shell. Options: --help show this message @@ -207,7 +235,9 @@ Options: Environment Variables: TAMED_STALL_SECONDS number of seconds of runner inactivity before - runner is automatically killed (default 30) + runner is automatically killed (default 1) + TAMED_SPAWNER_PID inhibit stalling while this process is running + (default PPID) EOF exit $EX_USAGE diff --git a/build-aux/Makefile.am b/build-aux/Makefile.am index 0ccca61..0fa6c31 100644 --- a/build-aux/Makefile.am +++ b/build-aux/Makefile.am @@ -89,6 +89,9 @@ SHELL = /bin/bash -O extglob export TAME_CMD_WAITTIME export TAMED_STALL_SECONDS +TAMED_SPAWNER_PID=$(shell echo $$PPID) +export TAMED_SPAWNER_PID + all: program-data-copy program-ui: standalones ui/package.strip.js ui/Program.js program-ui-immediate |