-
Notifications
You must be signed in to change notification settings - Fork 6
/
terminal-screensaverd
executable file
·39 lines (35 loc) · 1.23 KB
/
terminal-screensaverd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
function conf() {
# Improved function still relies on tilde expansion, but should be safe.
# Feel free to create user accounts named '`rm -rf /`' if you like :)
# This also only returns the first match in the file, rather than
# potentially returning a confusing mess if multiple options match.
# Exception handling is non-existant, but that's nothing new.
# Thanks to cut's nature, matching lines containing no spaces
# will be returned unaltered.
if [ "x$2" = "x" ]; then
homedir=~
else
eval homedir="$(printf "~%q" "$2")"
fi
[ -d "$homedir" ] || return 2 # user has a home directory?
[ -e "$homedir/.terminal-screensaver.conf" ] || return 3 # that directory has a config file?
[ -O "$homedir/.terminal-screensaver.conf" ] || return 4 # that config file is safe?
grep -m 1 -e "^$1" -- "$homedir/.terminal-screensaver.conf" | cut -d' ' -f2-
}
PID_DIR=/var/run/terminal-screensaver
mkdir -p $PID_DIR
chmod a+w $PID_DIR
while :; do
echo "screensaverd called"
for pid in `ls $PID_DIR`; do
echo "checking $pid"
user=`ps -o user= $pid`
idle="`conf 'idle-minutes-until-start' $user`"
if test `find $PID_DIR/$pid -mmin +$idle`; then
echo "too old"
kill -SIGALRM $pid || rm $PID_DIR/$pid
fi
done
sleep 15
done