emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-24 r116966: Fix some xgselect-vs-pselect bugs.


From: Paul Eggert
Subject: [Emacs-diffs] emacs-24 r116966: Fix some xgselect-vs-pselect bugs.
Date: Tue, 15 Apr 2014 15:43:46 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116966
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17172
committer: Paul Eggert <address@hidden>
branch nick: emacs-24
timestamp: Tue 2014-04-15 08:43:41 -0700
message:
  Fix some xgselect-vs-pselect bugs.
  
  This may not fix Bug#17172, but it fixes some bugs discovering
  while auditing xgselect.c for that bug.
  when one of glib's file descriptors is greater than FDS_LIM.
  Treat rfds, wfds, efds consistently, and test G_IO_PRI too.
  Clear input masks when pselect returns zero.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/xgselect.c                 xgselect.c-20091121171556-bypaf8oo9ygoo13w-2
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-04-15 13:21:18 +0000
+++ b/src/ChangeLog     2014-04-15 15:43:41 +0000
@@ -1,12 +1,11 @@
-2014-04-15  Stefan Monnier  <address@hidden>
-
-       * buffer.c (Foverlays_at): Add argument `sorted'.
-
-2014-04-14  Eli Zaretskii  <address@hidden>
-
-       * insdel.c (invalidate_buffer_caches): When deleting or replacing
-       text, invalidate the bidi_paragraph_cache upto and including the
-       preceding newline.
+2014-04-15  Paul Eggert  <address@hidden>
+
+       Fix some xgselect-vs-pselect bugs (Bug#17172).
+       This may not fix Bug#17172, but it fixes some bugs discovering
+       while auditing xgselect.c for that bug.
+       when one of glib's file descriptors is greater than FDS_LIM.
+       Treat rfds, wfds, efds consistently, and test G_IO_PRI too.
+       Clear input masks when pselect returns zero.
 
 2014-04-13  Paul Eggert  <address@hidden>
 

=== modified file 'src/xgselect.c'
--- a/src/xgselect.c    2014-03-05 06:31:57 +0000
+++ b/src/xgselect.c    2014-04-15 15:43:41 +0000
@@ -33,16 +33,15 @@
 xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
           struct timespec const *timeout, sigset_t const *sigmask)
 {
-  fd_set all_rfds, all_wfds;
+  fd_set all_rfds, all_wfds, all_efds;
   struct timespec tmo;
   struct timespec const *tmop = timeout;
 
   GMainContext *context;
-  int have_wfds = wfds != NULL;
   GPollFD gfds_buf[128];
   GPollFD *gfds = gfds_buf;
   int gfds_size = sizeof gfds_buf / sizeof *gfds_buf;
-  int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
+  int n_gfds, retval = 0, all_lim = fds_lim;
   int i, nfds, tmo_in_millisec;
   bool need_to_dispatch;
   USE_SAFE_ALLOCA;
@@ -59,6 +58,8 @@
   else FD_ZERO (&all_rfds);
   if (wfds) all_wfds = *wfds;
   else FD_ZERO (&all_wfds);
+  if (efds) all_efds = *efds;
+  else FD_ZERO (&all_efds);
 
   n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,
                                 gfds, gfds_size);
@@ -71,19 +72,22 @@
     }
 
   for (i = 0; i < n_gfds; ++i)
-    {
-      if (gfds[i].events & G_IO_IN)
-        {
-          FD_SET (gfds[i].fd, &all_rfds);
-          if (gfds[i].fd > max_fds) max_fds = gfds[i].fd;
-        }
-      if (gfds[i].events & G_IO_OUT)
-        {
-          FD_SET (gfds[i].fd, &all_wfds);
-          if (gfds[i].fd > max_fds) max_fds = gfds[i].fd;
-          have_wfds = 1;
-        }
-    }
+    if (gfds[i].events & (G_IO_IN | G_IO_OUT | G_IO_PRI))
+      {
+       int fd = gfds[i].fd;
+       for (; all_lim <= fd; all_lim++)
+         {
+           FD_CLR (all_lim, &all_rfds);
+           FD_CLR (all_lim, &all_wfds);
+           FD_CLR (all_lim, &all_efds);
+         }
+       if (gfds[i].events & G_IO_IN)
+         FD_SET (fd, &all_rfds);
+       if (gfds[i].events & G_IO_OUT)
+         FD_SET (fd, &all_wfds);
+       if (gfds[i].events & G_IO_PRI)
+         FD_SET (fd, &all_efds);
+      }
 
   SAFE_FREE ();
 
@@ -95,34 +99,35 @@
        tmop = &tmo;
     }
 
-  fds_lim = max_fds + 1;
-  nfds = pselect (fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL,
-                 efds, tmop, sigmask);
+  nfds = pselect (all_lim, &all_rfds, &all_wfds, &all_efds, tmop, sigmask);
 
   if (nfds < 0)
     retval = nfds;
-  else if (nfds > 0)
+  else
     {
       for (i = 0; i < fds_lim; ++i)
         {
-          if (FD_ISSET (i, &all_rfds))
-            {
-              if (rfds && FD_ISSET (i, rfds)) ++retval;
-              else ++our_fds;
-            }
-          else if (rfds)
-            FD_CLR (i, rfds);
-
-          if (have_wfds && FD_ISSET (i, &all_wfds))
-            {
-              if (wfds && FD_ISSET (i, wfds)) ++retval;
-              else ++our_fds;
-            }
-          else if (wfds)
-            FD_CLR (i, wfds);
-
-          if (efds && FD_ISSET (i, efds))
-            ++retval;
+         if (rfds && FD_ISSET (i, rfds))
+           {
+             if (FD_ISSET (i, &all_rfds))
+               retval++;
+             else
+               FD_CLR (i, rfds);
+           }
+         if (wfds && FD_ISSET (i, wfds))
+           {
+             if (FD_ISSET (i, &all_wfds))
+               retval++;
+             else
+               FD_CLR (i, wfds);
+           }
+         if (efds && FD_ISSET (i, efds))
+           {
+             if (FD_ISSET (i, &all_efds))
+               retval++;
+             else
+               FD_CLR (i, efds);
+           }
         }
     }
 
@@ -142,7 +147,7 @@
     }
 
   /* To not have to recalculate timeout, return like this.  */
-  if ((our_fds > 0 || (nfds == 0 && tmop == &tmo)) && (retval == 0))
+  if (retval == 0 && (0 < nfds || tmop == &tmo))
     {
       retval = -1;
       errno = EINTR;


reply via email to

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