[systemd-devel] How to Listen for SessionRemoved Signal

Kurt von Laven kurt at endlessm.com
Thu Jul 10 21:18:20 PDT 2014


Hello folks,

Apologies if anybody is getting this message twice; I originally posted on
dbus at lists.freedesktop.org and was directed here.

I am attempting to listen to the SessionRemoved signal from the login
manager <http://www.freedesktop.org/wiki/Software/systemd/logind/>. I have
no trouble in the case where the user logs out and waits for ~15 seconds
before shutting down, but when the user shuts down the system without first
logging out I don't hear the SessionRemoved signal in time. I would've
thought that inhibiting shutdown (by calling the Inhibit method of the
login manager <http://www.freedesktop.org/wiki/Software/systemd/inhibit/>)
would be the appropriate way to keep my process alive long enough to record
the SessionRemoved signal before my process gets killed. Apparently that is
not the case though. I am fairly certain that I am actually inhibiting
shutdown, because my process shows up when I call ListInhibitors in D-Feet
<https://wiki.gnome.org/action/show/Apps/DFeet>.

In case it's relevant, I'm using the delay mode of the inhibit method, and
my process runs as root. To test whether my process was running in the user
session, I called getsid (0)
<http://linux.about.com/library/cmd/blcmdl2_getsid.htm>. It returned the
PID of my process, which does not match the session ID of the
SessionRemoved signals I was able to record. Is this a legitimate way to
verify that my process isn't running in the user session? My original
assumption was that my process couldn't possibly be in the user session
because I am able to hear the SessionRemoved signal when the user logs out
and waits for ~15 seconds. Is that a bad assumption to make?

I was advised that some shutdown commands bypass logind, so I tried
shutting down several different ways (systemctl shutdown, shutdown now,
sudo shutdown now, calling Shutdown method on org.gnome.SessionManager from
D-Feet, and the typical GUI way). In all cases I got the same result: I
didn't hear the SessionRemoved signal. If anyone has any suggestions on how
to debug this or knows what I am missing here, that would be greatly
appreciated. Please let me know if any additional details would be helpful.

Be well,
Kurt

--
Kurt von Laven | Endless Mobile | EndlessM.com <http://endlessm.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140710/ed7af0d8/attachment.html>


More information about the systemd-devel mailing list