it's a bunch of ugly C code imported from gnome-session. Will clean it up a bit but I don't plan to make it too shiny :)