Is there a universal way to identify X session from the inside?

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 meaninglessTesting 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!