loosing the connection to the X server



Dear all,

I observed the following: when a GTK application loses its
connection to the X-server (eg. because of a window manager
destroy function; see below for how to reproduce) there are two
possibilities what can happen:

1. the application prints 

     The application 'exitbutton.run' lost its connection to the display :0.0;
     most likely the X server was shut down or you killed/destroyed
     the application.

   calls the functions that have been installed with g_atexit and
   finally exits.

2. the application dies on SIGPIPE when it tries to write
   something on the X-server socket. Especially the g_atexit
   functions are NOT run.


Is this diversity a bug or a feature? If it is a feature, what is
the recommended way of executing something on exit?

(Sorry if this is a FAQ; I searched the FAQ, the reference manual
and mailing list archives to no avail. Any pointers are
appreciated)


HOW TO REPRODUCE:

I have libgtk2 version 2.0.6-3 with libglib2 version 2.2.1-3 on
debian sarge.

- Modify the button example to call g_atexit (source attached)
- compile with 

     gcc -Wall -g exitbutton.c -o exitbutton.run `pkg-config --cflags --libs gtk+-2.0`

to observe 1:

- run exitbutton.run and kill your X-session

Alternatively:

- run exitbutton.run under fvwm2
- get the fvwm Window-Ops button bar
- choose the "Destroy" in the Window-Ops button bar
- click ON THE WINDOW TITLE BAR of exitbutton.run 

In this case the trailer of strace is

  poll([{fd=3, events=POLLIN, revents=POLLIN|POLLHUP}], 1, -1) = 1
  ioctl(3, FIONREAD, [0])                 = 0
  select(4, [3], NULL, NULL, {0, 0})      = 1 (in [3], left {0, 0})
  ioctl(3, FIONREAD, [0])                 = 0
  read(3, "", 32)                         = 0
  write(2, "The application \'exitbutton.run\'"..., 154The application 'exitbutton.run' lost its connection to the display :0.0;
  most likely the X server was shut down or you killed/destroyed
  the application.
  ) = 154
  open("/usr/lib/charset.alias", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
  brk(0)                                  = 0x8103000
  brk(0x810b000)                          = 0x810b000
  fstat64(1, {st_mode=S_IFREG|0644, st_size=75692, ...}) = 0
  old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40018000
  write(1, "do at exit\n", 11do at exit
  )            = 11
  munmap(0x40018000, 4096)                = 0
  exit_group(1)                           = ?



to observe 2:

- run exitbutton.run under fvwm2
- get a Destroy from the Window-Ops button bar and DROP IT ON the
  "Hello World" Button

Now the strace trailer is

  ioctl(3, FIONREAD, [64])                = 0
  read(3, "\7\1\244\0\342\33\200\306:\0\0\0\3\0 \3\34\0 \3R\3\213"..., 64) = 64
  poll([{fd=3, events=POLLIN, revents=POLLIN|POLLHUP}], 1, 0) = 1
  poll([{fd=3, events=POLLIN, revents=POLLIN|POLLHUP}], 1, 0) = 1
  ioctl(3, FIONREAD, [0])                 = 0
  poll([{fd=3, events=POLLIN, revents=POLLIN|POLLHUP}], 1, 0) = 1
  ioctl(3, FIONREAD, [0])                 = 0
  write(3, "5\30\4\0 \0 \3\3\0 \3U\0\32\0007E\6\0!\0 \3 \0 \3\4\0\1"..., 1028) = -1 EPIPE (Broken pipe)
  --- SIGPIPE (Broken pipe) @ 0 (0) ---
  +++ killed by SIGPIPE +++


Bye,

Hendrik

-----------------------------------------------------------------
Hendrik Tews     Department of Theoretical Computer Science
                 Dresden University of Technology, Germany

Telefon:   	 +49 351 463 38351
e-mail:    	 tews tcs inf tu-dresden de
www:       	 http://home.pages.de/~tews/
pgp key:         http://home.pages.de/~tews/pgpkey.asc
-----------------------------------------------------------------

#include <gtk/gtk.h>

/* This is a callback function. The data arguments are ignored
 * in this example. More on callbacks below. */
void hello( GtkWidget *widget,
            gpointer   data )
{
    g_print ("Hello World\n");
}

gint delete_event( GtkWidget *widget,
                   GdkEvent  *event,
		   gpointer   data )
{
    /* If you return FALSE in the "delete_event" signal handler,
     * GTK will emit the "destroy" signal. Returning TRUE means
     * you don't want the window to be destroyed.
     * This is useful for popping up 'are you sure you want to quit?'
     * type dialogs. */

    g_print ("delete event occurred\n");

    /* Change TRUE to FALSE and the main window will be destroyed with
     * a "delete_event". */

    return TRUE;
}

/* Another callback */
void destroy( GtkWidget *widget,
              gpointer   data )
{
    gtk_main_quit ();
}

void do_at_exit(void){
  g_print("do at exit\n"); 
}

int main( int   argc,
          char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
    GtkWidget *button;
    
    /* This is called in all GTK applications. Arguments are parsed
     * from the command line and are returned to the application. */
    gtk_init (&argc, &argv);
    
    g_atexit(do_at_exit);

    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    /* When the window is given the "delete_event" signal (this is given
     * by the window manager, usually by the "close" option, or on the
     * titlebar), we ask it to call the delete_event () function
     * as defined above. The data passed to the callback
     * function is NULL and is ignored in the callback function. */
    g_signal_connect (G_OBJECT (window), "delete_event",
		      G_CALLBACK (delete_event), NULL);
    
    /* Here we connect the "destroy" event to a signal handler.  
     * This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete_event" callback. */
    g_signal_connect (G_OBJECT (window), "destroy",
		      G_CALLBACK (destroy), NULL);
    
    /* Sets the border width of the window. */
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    /* Creates a new button with the label "Hello World". */
    button = gtk_button_new_with_label ("Hello World");
    
    /* When the button receives the "clicked" signal, it will call the
     * function hello() passing it NULL as its argument.  The hello()
     * function is defined above. */
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (hello), NULL);
    
    /* This will cause the window to be destroyed by calling
     * gtk_widget_destroy(window) when "clicked".  Again, the destroy
     * signal could come from here, or the window manager. */
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (gtk_widget_destroy),
                              window);
    
    /* This packs the button into the window (a gtk container). */
    gtk_container_add (GTK_CONTAINER (window), button);
    
    /* The final step is to display this newly created widget. */
    gtk_widget_show (button);
    
    /* and the window */
    gtk_widget_show (window);
    
    /* All GTK applications must have a gtk_main(). Control ends here
     * and waits for an event to occur (like a key press or
     * mouse event). */
    gtk_main ();
    
    return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]