emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r99478: Fix for bug#5512, don't rely


From: Jan D.
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r99478: Fix for bug#5512, don't rely on SIGIO alone.
Date: Wed, 10 Feb 2010 10:31:24 +0100
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 99478 [merge]
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Wed 2010-02-10 10:31:24 +0100
message:
  Fix for bug#5512, don't rely on SIGIO alone.
  
  * xsmfns.c (x_session_initialize): Move initialization of ice_fd and
  doing_interact here.
  (ice_connection_closed): New function.
  (x_session_check_input, smc_die_CB, ice_io_error_handler)
  (ice_conn_watch_CB, x_session_close): Call ice_connection_closed.
  (x_session_check_input): Call IceCloseConnection if IceProcessMessages
  returns I/O error.
  (ice_conn_watch_CB): Call add_keyboard_wait_descriptor on ice_fd,
  bug #5512.
modified:
  src/ChangeLog
  src/xsmfns.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2010-02-09 05:43:23 +0000
+++ b/src/ChangeLog     2010-02-10 09:29:28 +0000
@@ -1,3 +1,15 @@
+2010-02-10  Jan Djärv  <address@hidden>
+
+       * xsmfns.c (x_session_initialize): Move initialization of ice_fd and
+       doing_interact here.
+       (ice_connection_closed): New function.
+       (x_session_check_input, smc_die_CB, ice_io_error_handler)
+       (ice_conn_watch_CB, x_session_close): Call ice_connection_closed.
+       (x_session_check_input): Call IceCloseConnection if IceProcessMessages
+       returns I/O error.
+       (ice_conn_watch_CB): Call add_keyboard_wait_descriptor on ice_fd,
+       bug #5512.
+
 2010-02-08  Francis Devereux  <address@hidden>  (tiny change)
 
        * nsfont.m (nsfont_open): The system's value for the font descent

=== modified file 'src/xsmfns.c'
--- a/src/xsmfns.c      2010-01-13 08:35:10 +0000
+++ b/src/xsmfns.c      2010-02-10 09:29:28 +0000
@@ -52,11 +52,11 @@
 
 /* The descriptor that we use to check for data from the session manager.  */
 
-static int ice_fd = -1;
+static int ice_fd;
 
 /* A flag that says if we are in shutdown interactions or not.  */
 
-static int doing_interact = False;
+static int doing_interact;
 
 /* The session manager object for the session manager connection.  */
 
@@ -90,6 +90,14 @@
 
 #define NOSPLASH_OPT "--no-splash"
 
+static void
+ice_connection_closed ()
+{
+  if (ice_fd >= 0)
+    delete_keyboard_wait_descriptor (ice_fd);
+  ice_fd = -1;
+}
+
 
 /* Handle any messages from the session manager.  If no connection is
    open to a session manager, just return 0.
@@ -101,9 +109,9 @@
 {
   SELECT_TYPE read_fds;
   EMACS_TIME tmout;
+  int ret;
 
   if (ice_fd == -1) return 0;
-
   FD_ZERO (&read_fds);
   FD_SET (ice_fd, &read_fds);
 
@@ -116,26 +124,33 @@
      will be called.  */
   emacs_event.kind = NO_EVENT;
 
-  if (select (ice_fd+1, &read_fds,
-              (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout) < 0)
-    {
-      ice_fd = -1;
-      return 0;
-    }
-
-
-  if (FD_ISSET (ice_fd, &read_fds))
-    IceProcessMessages (SmcGetIceConnection (smc_conn),
-                        (IceReplyWaitInfo *)0, (Bool *)0);
-
+  ret = select (ice_fd+1, &read_fds,
+                (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout);
+
+  if (ret < 0)
+    {
+      ice_connection_closed ();
+    }
+  else if (ret > 0 && FD_ISSET (ice_fd, &read_fds))
+    {
+      ret = IceProcessMessages (SmcGetIceConnection (smc_conn),
+                                (IceReplyWaitInfo *)0, (Bool *)0);
+      if (ret != IceProcessMessagesSuccess)
+        {
+          /* Either IO error or Connection closed.  */
+          if (ret == IceProcessMessagesIOError)
+            IceCloseConnection (SmcGetIceConnection (smc_conn));
+
+          ice_connection_closed ();
+        }
+    }
 
   /* Check if smc_interact_CB was called and we shall generate a
      SAVE_SESSION_EVENT.  */
-  if (emacs_event.kind == NO_EVENT)
-    return 0;
+  if (emacs_event.kind != NO_EVENT)
+    bcopy (&emacs_event, bufp, sizeof (struct input_event));
 
-  bcopy (&emacs_event, bufp, sizeof (struct input_event));
-  return 1;
+  return emacs_event.kind != NO_EVENT ? 1 : 0;
 }
 
 /* Return non-zero if we have a connection to a session manager.  */
@@ -284,7 +299,7 @@
      SmPointer clientData;
 {
   SmcCloseConnection (smcConn, 0, 0);
-  ice_fd = -1;
+  ice_connection_closed ();
 }
 
 /* We don't use the next two but they are mandatory, leave them empty.
@@ -356,7 +371,7 @@
      IceConn iceConn;
 {
   /* Connection probably gone.  */
-  ice_fd = -1;
+  ice_connection_closed ();
 }
 
 /* This is called when the ICE connection is created or closed.  The SM library
@@ -371,7 +386,7 @@
 {
   if (! opening)
     {
-      ice_fd = -1;
+      ice_connection_closed ();
       return;
     }
 
@@ -384,6 +399,8 @@
   if (interrupt_input)
     init_sigio (ice_fd);
 #endif /* ! defined (SIGIO) */
+
+  add_keyboard_wait_descriptor (ice_fd);
 }
 
 /* Create the client leader window.  */
@@ -426,6 +443,9 @@
   SmcCallbacks callbacks;
   int  name_len = 0;
 
+  ice_fd = -1;
+  doing_interact = False;
+
   /* Check if we where started by the session manager.  If so, we will
      have a previous id.  */
   if (! EQ (Vx_session_previous_id, Qnil) && STRINGP (Vx_session_previous_id))
@@ -497,7 +517,7 @@
 void
 x_session_close ()
 {
-  ice_fd = -1;
+  ice_connection_closed ();
 }
 
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]