Mike Gerwitz

Activist for User Freedom

diff options
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-12-03 16:25:24 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-12-03 16:25:25 -0500
commit079d1dcfafd3eb75156bc513db81c623b66bc41b (patch)
parent210693c22fa86708cca7a0e102b7d823f16239fb (diff)
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.
3 files changed, 38 insertions, 4 deletions
diff --git a/bin/tame b/bin/tame
index 17b2483..693242d 100755
--- a/bin/tame
+++ b/bin/tame
@@ -31,6 +31,7 @@ declare -ri TAME_CMD_WAITTIME="${TAME_CMD_WAITTIME:-3}"
# propagate to daemon
# Send a single command to a runner and observe the result
diff --git a/bin/tamed b/bin/tamed
index 3b8b48b..d313612 100755
--- a/bin/tamed
+++ b/bin/tamed
@@ -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
+# number of seconds of output silence before runners are considered unused
+# and are subject to termination (see stall-monitor)
+# id of process that indirectly spawned tamed (default $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.
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.
+ 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.
--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)
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
+TAMED_SPAWNER_PID=$(shell echo $$PPID)
all: program-data-copy
program-ui: standalones ui/package.strip.js ui/Program.js program-ui-immediate