Subject: session manager hang due to block on ice_fd (failure to check for EINTR in select)

From: Karl Tomlinson <[email-masked]>
Date: Wed, 06 May 2009 09:00:49 +1200

x_session_check_input in xmsfns.c has this code:

  if (select (ice_fd+1, &read_fds,
              (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout) < 0)
    {
      ice_fd = -1;
      return 0;
    }

So ice_fd is set to -1 when select returns due to a signal
(with errno == EINTR).  This leaves the fd open but prevents
further processing.

ksmserver then blocks on this connection and so other apps opening
an ICE connection also block during start-up.

The simple solution that I have tested is to only set ice_fd to -1
when errno != EINTR.  x_session_check_input can still return early
in this situation as it will be called again in the future.

(Perhaps ice_fd never needs to be set to -1 here.  I don't know if
there is ever a good reason why is should be set to -1.)

In GNU Emacs 22.3.1 (x86_64-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2009-01-16 on blackhawk
Windowing system distributor `The X.Org Foundation', version 11.0.10503000
configured using `configure  '--prefix=/usr' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--program-suffix=-emacs-22' '--infodir=/usr/share/info/emacs-22' '--without-carbon' '--with-sound' '--with-x' '--without-toolkit-scroll-bars' '--with-jpeg' '--with-tiff' '--with-gif' '--with-png' '--with-xpm' '--with-x-toolkit=gtk' '--without-hesiod' '--with-kerberos' '--with-kerberos5' '--libdir=/usr/lib64' '--build=x86_64-pc-linux-gnu' '--enable-new-ldflags' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-pc-linux-gnu' 'CFLAGS=-O2 -pipe -march=nocona -g1' 'LDFLAGS=-Wl,-O1''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: C
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_NZ.UTF-8
  locale-coding-system: utf-8
  default-enable-multibyte-characters: t

Major mode: Group

Minor modes in effect:
  gnus-undo-mode: t
  msb-mode: t
  minibuffer-electric-default-mode: t
  auto-image-file-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  unify-8859-on-encoding-mode: t
  utf-translate-cjk-mode: t
  auto-compression-mode: t
  temp-buffer-resize-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t