Gtk3 - logout during g_application_hold ()
My gtk3 application can run in GUI or daemon mode. To implement daemon mode, I use g_application_hold () .
So far this works great, however, as soon as I log out of the session while running the app in daemon mode, my system freezes for 8 seconds until the OS kills it. Similar to my clean shutdown routine failing. This only happens for the daemon, not in GUI mode.
I currently solved the problem by connecting a SIGHUP signal that can be used to implement 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 mistake. No 8 second delay, my clean completion is in progress.
However I am wondering if there is a cleaner gtk3 solution? Can g_application_hold () be used, or is there some better gtk3 way to run something in daemon mode?
source to share
Finally, I know the reason for this strange behavior. It was caused by a direct gtk_main_quit()
one called by the session manager.
If a g_application_release(..).
is executed one line earlier, there is no longer any logout delay.
In fact even this Gtk-CRITICAL was caused by this gtk_main_quit()
:
Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops != NULL' failed
So far, I just haven't seen the message because the session manager has already closed the console for the owner.
source to share