My gtk3 application can either run within a GUI or in daemon-mode. In order to realize daemon-mode, I use g_application_hold().
So far this works great, however as soon as I logout from my session while running the application in daemon mode, my system freezes for 8 seconds, until OS kills it. Like that my clean shutdown procedure is not executed. That only happens for the daemon, not while in GUI-mode.
Currently I solved the problem by hooking the SIGHUP signal, which can be used to realize a session logout:
static void
handle_hangup_signal (int signal)
{
MyApplication *application = my_application_get ();
g_application_release (G_APPLICATION (application));
}
...
signal(SIGHUP, handle_hangup_signal);
This fixes my bug. No 8 second delay, my clean-shutdown is executed.
However I wonder if there is a more clean gtk3 solution? Is it fine to use g_application_hold(), or is there some better gtk3 way to launch something in daemon-mode ?
Finally I know the reason for this strange behavior. It was caused by a direct gtk_main_quit()
, triggered by the session-manager.
If a g_application_release(..).
is executed one line before, there is no logout-delay any more.
Actually even a Gtk-CRITICAL got triggered by this gtk_main_quit()
:
Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops != NULL' failed
Till now I just did not see the message because the session-manager already closed the owning console.