Running a script on logout from Gnome

There's a nice Python script for the job at linuxquestions.org written by Seamus Phelan. I've tested it, found a few problems and fixed them.

  • The script triggered a Python error while Gnome was shutting down. The error message is:
    gnome-logout-daemon.py: Fatal IO error 11 (Resource temporarily unavailable) on X server localhost:11.0.
    I've found that catching the "die" event and calling sys.exit() avoided the error message. I'm not familiar with Gnome internals thus I don't know whether the script is expected to handle "die" events explicitly or the gtk.main() call should exit on its own, when a "die" event occurs. However I've found a number of similiar errors in my .xsession-errors file from other python scripts that shipped with Ubuntu. Either those scripts are flawed too or the above error is a bug in Gnome/GTK or whatever.
  • The script launched a fixed command (you had to change the python script if you wanted to customize the command to be executed upon logout from Gnome) and it did this twice in a row. I've modified it to launch a shell script with a specific name if it exists in the user's HOME directory and fixed the double execution of the save-yourself event handler.

During my googling I've found a number of interesting pages that helped me understand the logout process:
  • Description of the signals Gnome sends to the listening clients
  • The execution of the script omits a warning on some versions of GTK:
    /home/demo/bin/gnome-logout-daemon.py:34: Warning: g_set_prgname() called multiple times
      prog = gnome.init("gnome-logout-daemon", "1.0", gnome.libgnome_module_info_get(), sys.argv, [])
    This is due to a bug in glib2.0 which appeared as an unexpected side-effect of a bugfix. This happens sometimes and fortunately the problem has already been resolved in the latest version of the GTK library (the upcoming version of the libglib2.0-0 package in Ubuntu will already have the fix).

I've also learned about the sequence of events sent by Gnome to the clients. It's fairly simple:
  1. save-yourself (phase = 1)
  2. save-complete
  3. save-yourself (phase = 2)
  4. save-complete
  5. die
Unfortunately the save-yourself event's phase parameter has a buggy implementation. In both cases of the save-yourself event the phase parameter equals "1" ... while the documentation clearly states that it should equal "2" in the second phase.

AttachmentSize
gnome-logout-daemon.py2.52 KB
Syndicate content