#!/bin/sh

LIST=`ps ax --format "%p:%a" | grep "$0.bin" | grep -v grep | cut -d : -f 1 | tail -n +1`
RD=`echo $DISPLAY|cut -f2 -d:|cut -f1 -d.`

echo $LIST on $RD | logger -t "kdesktop_lock"
# check if DISPLAY is open, if not TTFN
test -n "$RD" || exit

# loop through all kdesktop_locks.bin, and 
# check if any are running on current display
for P in $LIST; do
	D=`grep -z DISPLAY /proc/$P/environ|cut -f2 -d:|cut -f1 -d.`
	if [ $D -eq $RD ];then
		exit
	fi
done

# run lock
$0.bin "$@"

# i do not see a reason to run kill here, 
# as the script ends here, after kdesktop_lock.bin has exited.
# and following which kdesktop_lock exits

