X-Git-Url: https://git.madduck.net/code/pulserecorder.git/blobdiff_plain/fb1414bb84493438c4404c07172bb15da1d96a7c..0419e8fbc114f36a087acd8ea6de65cbfcfec788:/pulserecorder

diff --git a/pulserecorder b/pulserecorder
index 65a40ce..211c6d5 100755
--- a/pulserecorder
+++ b/pulserecorder
@@ -15,11 +15,22 @@
 #
 # The third form waits for a new sink-input to appear, and will record that.
 #
-# Copyright © 2020 martin f. krafft <madduck@madduck.net>
+# Copyright © 2020–2021 martin f. krafft <madduck@madduck.net>
 # Released under the teams of the Artistic Licence 2.0
 #
 set -eu
 
+cleanup_commands=
+cleanup() {
+  set +e
+  eval $cleanup_commands 2>/dev/null
+  trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
+}
+trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
+cleanup_hook() {
+  cleanup_commands="$@${cleanup_commands:+; $cleanup_commands}"
+}
+
 if [ -z "${TMPDIR:-}" ]; then
   TMPDIR=/tmp
 fi
@@ -31,17 +42,12 @@ for i in $LOGNAME volatile; do
 done
 export TMPDIR
 TMPDIR=$(mktemp -dp "$TMPDIR" parec.XXXXXXXXXX)
+cleanup_hook rm -r $TMPDIR
 
-cleanup_commands="rm -r $TMPDIR"
-cleanup() {
-  set +e
-  eval $cleanup_commands 2>/dev/null
-  trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
-}
-trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
-cleanup_hook() {
-  cleanup_commands="$@${cleanup_commands:+; $cleanup_commands}"
-}
+if command -v systemd-inhibit >/dev/null; then
+  systemd-inhibit --who=pulserecorder --why=recording sleep 99d 2>/dev/null &
+  cleanup_hook kill $!
+fi
 
 state= outfile= index= clobber=0
 for arg in "$@"; do
@@ -66,7 +72,7 @@ pa_wait_for_event() {
   type="${1:-*}" event="${2:-*}" id="${3:-*}"
   pa_subscribe | (
     read pid
-    #echo >&2 pa_subscribe started with PID $pid
+    #echo >&2 pa_subscribe started with PID $pid, waiting for $type/$event/$id
     while read lead xevent on xtype xid; do
       xid=${xid#\#}
       #echo >&2 "pa_subscribe: $xtype/$xevent/$xid ($type/$event/$id)"