summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVon Random <von@vdrandom.org>2019-10-21 17:28:37 +0300
committerVon Random <von@vdrandom.org>2019-10-21 17:28:37 +0300
commit2fb479e4ec2db62fca2723080dc30ebe914841ab (patch)
treeb64919c6f763abeba83f81326538597dcc35fe19
parent2a1f535eebc3aab14c99cd8d85f34e672e2cc6bf (diff)
xscreensaver-companion: pidfile check
-rwxr-xr-xxscreensaver-companion19
1 files changed, 19 insertions, 0 deletions
diff --git a/xscreensaver-companion b/xscreensaver-companion
index 7a76fca..799e098 100755
--- a/xscreensaver-companion
+++ b/xscreensaver-companion
@@ -1,5 +1,23 @@
#!/usr/bin/env zsh
+pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid
+trap "rm -f $pidfile" INT KILL
+
+function init_pidfile
+{
+ local pid
+ if read pid < $pidfile; then
+ if kill -0 $pid; then
+ echo 'I am already running!' >&2
+ exit 1
+ else
+ echo 'Remove stale lock file.' >&2
+ rm $pidfile
+ fi
+ fi
+ echo $$ > $pidfile
+}
+
function parse_actions
{
while read action _; do
@@ -17,4 +35,5 @@ function parse_actions
done
}
+init_pidfile
/usr/bin/xscreensaver-command -watch | parse_actions