You are not logged in.
Hi everyone!
I wrote some bash daemons designed to be started by xdg autostart mechanism.
The problem is: unlike X clients, bash scripts do not exit on logout from X session or when X is killed.
subproblem: script needs to do some housekeeping when exiting.
I'm looking for DE/DM-independent way of telling if current user X session still exist, or not. Or a way to catch the end of session.
Testing for $DISPLAY is meaningless
Testing for X PID is unreliable (for example, xdm reuses same X process for itself and user sessions)
Not every session manager gives its PID to child processes as PPID.
env of script started via xdg autostart differs across DEs/DMs.
I've made a very dirty workaround: start empty dummy conky and use it as an indicator that session still exist.
But there should be a cleaner way!
Offline
I have fbpanel installed on my system. Included with this package is a script named 'xlogout' see below. Perhaps there is something in this that may help you.
#!/bin/bash
# xlogout - logs user out of its X session
# Linux specific since uses /proc
# get display name without screen number
[ -z "$DISPLAY" ] && exit 1
DPY=${DISPLAY:1}
DPY=${DPY/.*/}
echo "DPY=${DPY}"
# get X pid
XPID=`< /tmp/.X${DPY}-lock`
XPID=`echo $XPID`
echo "XPID=$XPID"
# get pid of xdm (or gdm, kdm, etc). usually it's parent of X
XDMPID=`ps -o ppid --pid=$XPID | awk '{if (FNR != 1) print $1}'`
echo "XDMPID=$XDMPID"
# recursivly find child of xdm that was started in home dir -
# it's user's session start up script
function pid_scan()
{
rm -f $PF
while [ $# != 0 ]; do
ps --no-headers -o pid --ppid=$1 >> $PF
shift
done
for pid in `< $PF`; do
if cwd=`ls -al /proc/$pid/cwd 2>/dev/null`; then
cwd=`sed 's/.*-> //' <<< $cwd`
[ "$cwd" == "$HOME" ] && echo $pid && return
fi
done
pids=`< $PF`
[ -n "$pids" ] && pid_scan `< $PF`;
}
PF=/tmp/$$-pids
SPID=`pid_scan $XDMPID`
rm -f $PF
[ -z "$SPID" ] && exit 1
echo "Session start up script"
ps -o uid,pid,ppid,sess,cmd --pid $SPID
kill -SIGTERM -$SPID
Offline
or when X is killed.
That should be easy. Just use a wrapper for startx, e.g. ~/bin/startx
/usr/bin/startx
do-whatever-you-want-at-end
Offline
Included with this package is a script named 'xlogout'
Wow! that's a nice one! Works even when no DM is used, detects xinitrc as $XDMPID.
Just use a wrapper for startx.
That`s not from the inside.
Offline