Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[pandora-kernel.git] / fs / select.c
index 41c3571..47f4792 100644 (file)
@@ -177,11 +177,6 @@ get_max:
        return max;
 }
 
-#define BIT(i)         (1UL << ((i)&(__NFDBITS-1)))
-#define MEM(i,m)       ((m)+(unsigned)(i)/__NFDBITS)
-#define ISSET(i,m)     (((i)&*(m)) != 0)
-#define SET(i,m)       (*(m) |= (i))
-
 #define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
 #define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
 #define POLLEX_SET (POLLPRI)
@@ -586,7 +581,7 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
        /* Optimise the no-wait case */
        if (!(*timeout))
                pt = NULL;
+
        for (;;) {
                struct poll_list *walk;
                long __timeout;
@@ -616,10 +611,12 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
                 * a poll_table to them on the next loop iteration.
                 */
                pt = NULL;
-               if (count || !*timeout || signal_pending(current))
-                       break;
-               count = wait->error;
-               if (count)
+               if (!count) {
+                       count = wait->error;
+                       if (signal_pending(current))
+                               count = -EINTR;
+               }
+               if (count || !*timeout)
                        break;
 
                if (*timeout < 0) {
@@ -689,8 +686,6 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout)
 
        poll_initwait(&table);
        fdcount = do_poll(nfds, head, &table, timeout);
-       if (!fdcount && signal_pending(current))
-               fdcount = -EINTR;
        poll_freewait(&table);
 
        for (walk = head; walk; walk = walk->next) {
@@ -714,10 +709,28 @@ out_fds:
        return err;
 }
 
+static long do_restart_poll(struct restart_block *restart_block)
+{
+       struct pollfd __user *ufds = (struct pollfd __user*)restart_block->arg0;
+       int nfds = restart_block->arg1;
+       s64 timeout = ((s64)restart_block->arg3<<32) | (s64)restart_block->arg2;
+       int ret;
+
+       ret = do_sys_poll(ufds, nfds, &timeout);
+       if (ret == -EINTR) {
+               restart_block->fn = do_restart_poll;
+               restart_block->arg2 = timeout & 0xFFFFFFFF;
+               restart_block->arg3 = (u64)timeout >> 32;
+               ret = -ERESTART_RESTARTBLOCK;
+       }
+       return ret;
+}
+
 asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
                        long timeout_msecs)
 {
        s64 timeout_jiffies;
+       int ret;
 
        if (timeout_msecs > 0) {
 #if HZ > 1000
@@ -732,7 +745,18 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
                timeout_jiffies = timeout_msecs;
        }
 
-       return do_sys_poll(ufds, nfds, &timeout_jiffies);
+       ret = do_sys_poll(ufds, nfds, &timeout_jiffies);
+       if (ret == -EINTR) {
+               struct restart_block *restart_block;
+               restart_block = &current_thread_info()->restart_block;
+               restart_block->fn = do_restart_poll;
+               restart_block->arg0 = (unsigned long)ufds;
+               restart_block->arg1 = nfds;
+               restart_block->arg2 = timeout_jiffies & 0xFFFFFFFF;
+               restart_block->arg3 = (u64)timeout_jiffies >> 32;
+               ret = -ERESTART_RESTARTBLOCK;
+       }
+       return ret;
 }
 
 #ifdef TIF_RESTORE_SIGMASK