Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
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)
treef20c8d393d6ad747137ef1c599e96f3d27b346b1 /bin
parent210693c22fa86708cca7a0e102b7d823f16239fb (diff)
downloadtame-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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tame1
-rwxr-xr-xbin/tamed38
2 files changed, 35 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
export TAMED_STALL_SECONDS
+export TAMED_SPAWNER_PID
# 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
-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