Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-08 23:27:02 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-11 22:25:18 -0400
commit6027769633abc3d8d2377caceb7b942fc7fd92aa (patch)
tree12b17cd67576d1b9d53989245f967392991b7c0a /bin
parent88da519c5e43566871e504a4716ac7609e9adf2c (diff)
downloadtame-6027769633abc3d8d2377caceb7b942fc7fd92aa.tar.gz
tame-6027769633abc3d8d2377caceb7b942fc7fd92aa.tar.bz2
tame-6027769633abc3d8d2377caceb7b942fc7fd92aa.zip
Integrate new compilation scripts, remove cqueue and Makefile.2
This is a major step toward normalcy---removing the kluge of a build process that was causing so many issues. Rather than echoing all operations to a queue file before passing it off to dslc, the new build scripts in `bin/' are used to invoke tame normally, as needed. This solves all of the current issues with things not rebuilding when they should. And, as a bonus, tab completion on targets works. Sorry this took so long. There wasn't much motivation until we hired so many people that are suffering from this. This does a few major things, along with some miscellaneous others: - Invoke bin/tame directly; - Merge Makefile.2.in into Makefile.am; and - Fix up some targets. * build-aux/Makefile.2.in: Delete file. Mostly merged with Makefile.am. * build-aux/Makefile.am: Add a bunch of new targets and definitions from Makefile.2.in. Modify all that previously used .cqueue to now invoke `$(TAME)' directly. Remove miscellaneous targets for trying to proxy targets to Makefile.2. (saneout, _go): Remove definitions. (.NOTPARALLEL): Add to prevent parallel builds. (ui/program.expanded.xml)[.version.xml]: Remove dependency for now. (clean): Also clean generated PHP files. Follow symlinks to clean core. This is still incomplete (does not clean all rate table stuff). (suppliers.mk)[xmlo_cmd]: Remove. See `gen-make' and `gen-c1make'. (lvroot)[summary-html]: New dependency. (kill-tamed, tamed-die): New targets (former alias of latter) to kill tamed. * build-aux/gen-c1make: Generate `$(TAME)' invocation. * build-aux/gen-make: Likewise. Remove `xmlo_cmd' output. Ignore recursive `tame' symlink (this can be removed once we clean `rater/' up. * build-aux/m4/calcdsl.m4 (TAME): Update description to reflect that it should now be the path to `bin/tame'. Adjust `AC_CHECK_FILE' lines accordingly. (tame_needed_ver): Remove. We have been in the same repo as TAME itself for quite some time. Remove associated code. (AC_CONFIG_FILES): Remove `Makefile.2'. * src/current/src/com/lovullo/dslc/DslCompiler.java (_DslCompiler)[compile]: Perform validation prefore `compile' command rather than a separate `validate' step. Remove `rm'. [compileSrc]: Stop echoing command. This was only necessary because of the previous Makefile klugery; now Make echoes on its own correctly.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tame30
-rwxr-xr-xbin/tamed68
2 files changed, 73 insertions, 25 deletions
diff --git a/bin/tame b/bin/tame
index be9fc61..ecb2bed 100755
--- a/bin/tame
+++ b/bin/tame
@@ -43,6 +43,10 @@ command-runner()
verify-runner "$base" "$pid"
+ # forward signals to runner so that build is actually halted
+ # (rather than continuing in background after we die)
+ trap 'kill -TERM $pid &>/dev/null' INT TERM
+
# all remaining arguments are passed to the runner
echo "$@" > "$base/0"
@@ -163,10 +167,11 @@ saneout()
awk ' \
/^~~~~\[begin /,/^~~~~\[end / { next } \
/^rm / { next } \
+ /^COMMAND / { next } \
/^Exception|^\t+at / { \
if ( /^E/ ) { \
print; \
- print "Stack trace written to .runlog"; \
+ print "Stack trace written to run-*.log"; \
} \
next; \
} \
@@ -184,14 +189,19 @@ saneout()
usage()
{
cat <<EOF
-Usage: $0 cmdline
+Usage: $0 [-v|--verbose] cmdline
Or: $0 --kill
Send command line CMDLINE to a tamed runner. Start tamed if
not already running.
Options:
- --kill kill tamed
- --help show this message
+ --help show this message
+ --kill kill tamed
+ -v, --verbose show runner logs
+
+Environment Variables:
+ TAME_VERBOSE when greater than zero, show runner logs
+ (see also --verbose)
EOF
exit $EX_USAGE
@@ -203,17 +213,27 @@ main()
{
local -r root=/run/user/$UID/tamed
+ local outcmd=saneout
+
test $# -gt 0 || usage
case "${1:-}" in
--kill) kill-tamed "$root"; exit;;
+ -v|--verbose) outcmd=cat;;
--help) usage;;
esac
+ # alternative to --verbose
+ if [ "${TAME_VERBOSE:-0}" -ge 1 ]; then
+ outcmd=cat
+ fi
+
start-tamed "$root"
# for now we only support a single runner
- command-runner 0 "$root" "$@" | saneout
+ command-runner 0 "$root" "$@" \
+ | tee -a "run-0.log" \
+ | "$outcmd"
}
main "$@"
diff --git a/bin/tamed b/bin/tamed
index 54e5c6b..25b2077 100755
--- a/bin/tamed
+++ b/bin/tamed
@@ -25,6 +25,9 @@ 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}"
+
# set by `main', global for `cleanup'
declare root=
@@ -50,6 +53,9 @@ mkfifos()
echo "fatal: failed to create FIFO at $in"
exit $EX_CANTCREAT
}
+
+ # keep FIFOs open so we don't get EOF from writers
+ tail -f >"$root/$n" &
done
}
@@ -69,13 +75,13 @@ spawn-runner()
mkfifos "$base"
- # TODO: should we separate back out std{out,err}?
- # XXX: why does dslc quit (with a 0 exit code) occsionally? stdin?
+ # monitor runner usage and kill when inactive
+ stall-monitor "$base" &
+
+ # loop to restart runner in case of crash
while true; do
- "$mypath/dslc" < <( persistent-cat "$base/0" ) \
- >"$base/1" \
- 2>&1
- echo "warning: runner $id exited with code $?; restarting"
+ "$mypath/dslc" < "$base/0" &> "$base/1"
+ echo "warning: runner $id exited with code ${PIPESTATUS[0]}; restarting" >&2
done &
echo "$!" > "$base/pid"
@@ -84,19 +90,37 @@ spawn-runner()
}
-# Persistently read commands from FIFO IN
+# Kill runner at BASE when it becomes inactive for TAMED_STALL_SECONDS
+# seconds
#
-# This will continue to read from the FIFO as long as it is
-# readable. This is necessary since SIGPIPE gets sent to
-# processes reading/writing from/to the FIFO whenever a
-# process detaches from it.
-persistent-cat()
+# This monitors the modification time on the stdout FIFO. stdin does not
+# need to be monitored since dslc immediately echoes back commands it
+# receives.
+#
+# dslc is pretty chatty at the time of writing this, so TAMED_STALL_SECONDS
+# 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.
+stall-monitor()
{
- local -r in="${1?Missing input path}"
+ local -r base="${1?Missing base}"
+
+ # monitor output FIFO modification time
+ while true; do
+ local -i since=$( date +%s )
+ sleep "$TAMED_STALL_SECONDS"
+ local -i last=$( stat -c%Y "$base/1" )
- while test -r "$in"; do
- read -r < "$in" || return
- echo "$REPLY"
+ # keep waiting if there has been activity since $since
+ test "$last" -le "$since" || continue
+
+ # no activity; kill
+ local -r pid=$( cat "$base/pid" )
+ kill "$pid"
+ wait "$pid" 2>/dev/null
+
+ # this stall subprocess is no longer needed
+ break
done
}
@@ -154,8 +178,6 @@ kill-running()
# recurse.
cleanup()
{
- echo "killing remaining runners..."
-
rm -rf "$root"
kill 0
}
@@ -170,11 +192,17 @@ Start tamed and runners. Do not fork into background process.
The default value of RUNPATH is \`/run/user/$UID/tamed'.
-Only one runner is currently supported.
+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).
Options:
- --kill kill a runing tamed at path RUNPATH
--help show this message
+ --kill kill a runing tamed at path RUNPATH
+
+Environment Variables:
+ TAMED_STALL_SECONDS number of seconds of runner inactivity before
+ runner is automatically killed (default 30)
EOF
exit $EX_USAGE