Module: xenomai-2.6
Branch: master
Commit: 0f790a44838a99407087a650370b7d47cfb56934
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=0f790a44838a99407087a650370b7d47cfb56934

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat Dec 15 15:32:27 2012 +0100

posix: fix select syscall

When a timeout occurs, the polled fd_set should be zeroed upon select return.

This fixes the bug reported by and which fix was tested by Alexandre Duch
as Debian bug #695657.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=695657

---

 ksrc/nucleus/select.c      |   16 ++++++----------
 ksrc/skins/posix/syscall.c |    2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/ksrc/nucleus/select.c b/ksrc/nucleus/select.c
index e25dd38..987ef30 100644
--- a/ksrc/nucleus/select.c
+++ b/ksrc/nucleus/select.c
@@ -248,7 +248,7 @@ fd_set_and(fd_set *result, fd_set *first, fd_set *second, 
unsigned n)
        return not_empty;
 }
 
-static void fd_set_zerofill(fd_set *set, unsigned n)
+static void fd_set_zeropad(fd_set *set, unsigned n)
 {
        unsigned i;
 
@@ -334,6 +334,10 @@ int xnselect(struct xnselector *selector,
 
        thread = xnpod_current_thread();
 
+       for (i = 0; i < XNSELECT_MAX_TYPES; i++)
+               if (out_fds[i])
+                       fd_set_zeropad(out_fds[i], nfds);
+
        xnlock_get_irqsave(&nklock, s);
        for (i = 0; i < XNSELECT_MAX_TYPES; i++)
                if (out_fds[i]
@@ -342,12 +346,8 @@ int xnselect(struct xnselector *selector,
                        not_empty = 1;
        xnlock_put_irqrestore(&nklock, s);
 
-       if (not_empty) {
-               for (i = 0; i < XNSELECT_MAX_TYPES; i++)
-                       if (out_fds[i])
-                               fd_set_zerofill(out_fds[i], nfds);
+       if (not_empty)
                return -ECHRNG;
-       }
 
        xnlock_get_irqsave(&nklock, s);
        for (i = 0; i < XNSELECT_MAX_TYPES; i++)
@@ -373,10 +373,6 @@ int xnselect(struct xnselector *selector,
        if (not_empty) {
                unsigned count;
 
-               for (i = 0; i < XNSELECT_MAX_TYPES; i++)
-                       if (out_fds[i])
-                               fd_set_zerofill(out_fds[i], nfds);
-
                for (count = 0, i = 0; i < XNSELECT_MAX_TYPES; i++)
                        if (out_fds[i])
                                count += fd_set_popcount(out_fds[i], nfds);
diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 6c78244..a30ee8f 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -2501,7 +2501,7 @@ static int __select(struct pt_regs *regs)
                        return -EFAULT;
        }
 
-       if (err > 0)
+       if (err >= 0)
                for (i = 0; i < XNSELECT_MAX_TYPES; i++)
                        if (ufd_sets[i]
                            && __xn_copy_to_user((void __user *) ufd_sets[i],


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to