Xubuntu / lightdm-gtk-greeter

A GTK greeter for LightDM
GNU General Public License v3.0
155 stars 31 forks source link

Crash on first login #173

Closed paisleyrob closed 2 months ago

paisleyrob commented 2 months ago

Upon first login to my machine the greeter crashes and I have to login a second time. The second time everything behaves properly. This morning I finally dug into the cause.

I don't understand how surface ends up with NULL after the call

    surface = create_root_surface(priv->screen);

from src/greeterbackground.c L1088

Nor do I understand why it works flawlessly after the first crash.

Here's the gdb back trace:

(gdb) bt
#0  cairo_surface_get_type (surface=surface@entry=0x0) at ../src/cairo-surface.c:228
#1  0x000055e70162af4f in set_surface_as_root (surface=0x0, screen=0x55e71b7f5100) at /usr/src/debug/lightdm-gtk-2.0.8-9.fc40.x86_64/src/greeterbackground.c:1743
#2  greeter_background_save_xroot (background=<optimized out>) at /usr/src/debug/lightdm-gtk-2.0.8-9.fc40.x86_64/src/greeterbackground.c:1104
#3  0x000055e70162c624 in start_session () at /usr/src/debug/lightdm-gtk-2.0.8-9.fc40.x86_64/src/lightdm-gtk-greeter.c:2245
#4  0x00007ffbae423254 in _g_closure_invoke_va (closure=0x55e71b955e60, return_value=0x0, instance=0x55e71b9d8ee0, args=0x7ffe30b272d0, n_params=<optimized out>, param_types=0x0)
    at ../gobject/gclosure.c:897
#5  signal_emit_valist_unlocked (instance=instance@entry=0x55e71b9d8ee0, signal_id=signal_id@entry=183, detail=detail@entry=0, var_args=var_args@entry=0x7ffe30b272d0)
    at ../gobject/gsignal.c:3424
#6  0x00007ffbae423361 in g_signal_emit_valist (instance=0x55e71b9d8ee0, signal_id=183, detail=0, var_args=var_args@entry=0x7ffe30b272d0) at ../gobject/gsignal.c:3263
#7  0x00007ffbae423423 in g_signal_emit (instance=instance@entry=0x55e71b9d8ee0, signal_id=<optimized out>, detail=detail@entry=0) at ../gobject/gsignal.c:3583
#8  0x00007ffbae3dbbde in handle_end_authentication (greeter=0x55e71b9d8ee0, message=0x55e71bae6870 "", message_length=<optimized out>, offset=0x7ffe30b273d0)
    at /usr/src/debug/lightdm-1.32.0-10.fc40.x86_64/liblightdm-gobject/greeter.c:714
#9  handle_message (greeter=0x55e71b9d8ee0, message=0x55e71bae6870 "", message_length=<optimized out>)
    at /usr/src/debug/lightdm-1.32.0-10.fc40.x86_64/liblightdm-gobject/greeter.c:804
#10 0x00007ffbae3dbdf0 in from_server_cb (source=<optimized out>, condition=<optimized out>, data=0x55e71b9d8ee0)
    at /usr/src/debug/lightdm-1.32.0-10.fc40.x86_64/liblightdm-gobject/greeter.c:918
#11 0x00007ffbad711e8c in g_main_dispatch (context=0x55e71b7d7d10) at ../glib/gmain.c:3344
#12 g_main_context_dispatch_unlocked (context=0x55e71b7d7d10) at ../glib/gmain.c:4152
#13 0x00007ffbad773c98 in g_main_context_iterate_unlocked.isra.0 (context=0x55e71b7d7d10, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>)
    at ../glib/gmain.c:4217
#14 0x00007ffbad717f37 in g_main_loop_run (loop=0x55e71bb2a2d0) at ../glib/gmain.c:4419
#15 0x00007ffbaddefb35 in gtk_main () at ../gtk/gtkmain.c:1329
#16 0x000055e7016249dc in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/lightdm-gtk-2.0.8-9.fc40.x86_64/src/lightdm-gtk-greeter.c:3437
paisleyrob commented 2 months ago

I played with this a little today. I've applied the following diff:

diff --git a/src/greeterbackground.c b/src/greeterbackground.c
index c2bc29e..f20b8a5 100644
--- a/src/greeterbackground.c
+++ b/src/greeterbackground.c
@@ -10,6 +10,11 @@
  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
  * license.
  */
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>

 #include <math.h>
 #include <cairo-xlib.h>
@@ -1079,14 +1084,27 @@ greeter_background_save_xroot(GreeterBackground* background)
     cairo_surface_t          *surface;
     cairo_t                  *cr;
     gsize                     i;
+    int fd = -1;
+
+    if(-1 == (fd = open("/tmp/lightdm-greeter-gtk.log", O_APPEND | O_CREAT | O_WRONLY | O_CLOEXEC, 0644))) {
+       perror("Aborting");
+       exit(0);
+    }
+
+    dprintf(fd, "%s:%d Entering\n", __FILE__, __LINE__);

     const GdkRGBA             ROOT_COLOR = {1.0, 1.0, 1.0, 1.0};

     g_return_if_fail(GREETER_IS_BACKGROUND(background));

+    dprintf(fd, "%s:%d %p background\n", __FILE__, __LINE__, background);
+
     priv = background->priv;
+    dprintf(fd, "%s:%d %p priv\n", __FILE__, __LINE__, priv);
     surface = create_root_surface(priv->screen);
+    dprintf(fd, "%s:%d %p surface\n", __FILE__, __LINE__, surface);
     cr = cairo_create(surface);
+    dprintf(fd, "%s:%d %p cr\n", __FILE__, __LINE__, cr);

     gdk_cairo_set_source_rgba(cr, &ROOT_COLOR);
     cairo_paint(cr);
@@ -1105,6 +1123,7 @@ greeter_background_save_xroot(GreeterBackground* background)

     cairo_destroy(cr);
     cairo_surface_destroy(surface);
+    close(fd);
 }

 const GdkRectangle*

As usual, the first login crashed, the second login succeeded. Here's the output of the log file that was generated:

greeterbackground.c:1094 Entering
greeterbackground.c:1100 0x2aebad20 background
greeterbackground.c:1103 0x2aebac60 priv
greeterbackground.c:1105 (nil) surface
greeterbackground.c:1107 0x7fcab6c97010 cr
greeterbackground.c:1094 Entering
greeterbackground.c:1100 0x395cca60 background
greeterbackground.c:1103 0x395cc9a0 priv
greeterbackground.c:1105 0x395d4640 surface
greeterbackground.c:1107 0x39546cf0 cr
paisleyrob commented 2 months ago

After removing the segfault the greeter still exits. No core dump this time but the behavior is identical. First login exits, second login works like nothing was ever wrong.

I'm not sure what's going on here.

My next thought is to see if I can get the greeter spawned with additional debugging enabled. Looks like it's set to WARNING at the moment.

paisleyrob commented 2 months ago

I found my answer https://wiki.archlinux.org/title/LightDM#Login_always_segfaults_on_first_attempt

Evidently my hostname is changing to the dhcp hostname as referenced in the following bugs/links. I manually set the hostname and the issue has gone away. I'll close this issue.