Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 40 lines (35 sloc) 1.23 KB
#!/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