aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2011-04-27 21:24:19 +0200
committerOleg Nesterov <oleg@redhat.com>2011-04-28 13:01:38 +0200
commitfe0faa005d43bc44c357631d51c273806086caa4 (patch)
tree7977c5ec7c452ed3a0036747b8d8861b742c30b3 /kernel
parentbb7efee2ca63b08795ffb3cda96fc89d2e641b79 (diff)
signal: sys_rt_sigtimedwait: simplify the timeout logic
No functional changes, cleanup compat_sys_rt_sigtimedwait() and sys_rt_sigtimedwait(). Calculate the timeout before we take ->siglock, this simplifies and lessens the code. Use timespec_valid() to check the timespec. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Matt Fleming <matt.fleming@linux.intel.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/compat.c42
-rw-r--r--kernel/signal.c48
2 files changed, 39 insertions, 51 deletions
diff --git a/kernel/compat.c b/kernel/compat.c
index 38b1d2c1cbe..06cbb061953 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -893,7 +893,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
int sig;
struct timespec t;
siginfo_t info;
- long ret, timeout = 0;
+ long ret, timeout;
if (sigsetsize != sizeof(sigset_t))
return -EINVAL;
@@ -904,36 +904,30 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
sigdelsetmask(&s,sigmask(SIGKILL)|sigmask(SIGSTOP));
signotset(&s);
+ timeout = MAX_SCHEDULE_TIMEOUT;
if (uts) {
if (get_compat_timespec (&t, uts))
return -EFAULT;
- if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0
- || t.tv_sec < 0)
+ if (!timespec_valid(&t))
return -EINVAL;
+ timeout = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
}
spin_lock_irq(&current->sighand->siglock);
sig = dequeue_signal(current, &s, &info);
- if (!sig) {
- timeout = MAX_SCHEDULE_TIMEOUT;
- if (uts)
- timeout = timespec_to_jiffies(&t)
- +(t.tv_sec || t.tv_nsec);
- if (timeout) {
- current->real_blocked = current->blocked;
- sigandsets(&current->blocked, &current->blocked, &s);
-
- recalc_sigpending();
- spin_unlock_irq(&current->sighand->siglock);
-
- timeout = schedule_timeout_interruptible(timeout);
-
- spin_lock_irq(&current->sighand->siglock);
- sig = dequeue_signal(current, &s, &info);
- current->blocked = current->real_blocked;
- siginitset(&current->real_blocked, 0);
- recalc_sigpending();
- }
+ if (!sig && timeout) {
+ current->real_blocked = current->blocked;
+ sigandsets(&current->blocked, &current->blocked, &s);
+ recalc_sigpending();
+ spin_unlock_irq(&current->sighand->siglock);
+
+ timeout = schedule_timeout_interruptible(timeout);
+
+ spin_lock_irq(&current->sighand->siglock);
+ sig = dequeue_signal(current, &s, &info);
+ current->blocked = current->real_blocked;
+ siginitset(&current->real_blocked, 0);
+ recalc_sigpending();
}
spin_unlock_irq(&current->sighand->siglock);
@@ -943,7 +937,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
if (copy_siginfo_to_user32(uinfo, &info))
ret = -EFAULT;
}
- }else {
+ } else {
ret = timeout?-EINTR:-EAGAIN;
}
return ret;
diff --git a/kernel/signal.c b/kernel/signal.c
index bb9200070ea..c734619554f 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2519,7 +2519,7 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
sigset_t these;
struct timespec ts;
siginfo_t info;
- long timeout = 0;
+ long timeout;
/* XXX: Don't preclude handling different sized sigset_t's. */
if (sigsetsize != sizeof(sigset_t))
@@ -2535,41 +2535,35 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
signotset(&these);
+ timeout = MAX_SCHEDULE_TIMEOUT;
if (uts) {
if (copy_from_user(&ts, uts, sizeof(ts)))
return -EFAULT;
- if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
- || ts.tv_sec < 0)
+ if (!timespec_valid(&ts))
return -EINVAL;
+ timeout = timespec_to_jiffies(&ts) + (ts.tv_sec || ts.tv_nsec);
}
spin_lock_irq(&current->sighand->siglock);
sig = dequeue_signal(current, &these, &info);
- if (!sig) {
- timeout = MAX_SCHEDULE_TIMEOUT;
- if (uts)
- timeout = (timespec_to_jiffies(&ts)
- + (ts.tv_sec || ts.tv_nsec));
+ if (!sig && timeout) {
+ /*
+ * None ready -- temporarily unblock those we're
+ * interested while we are sleeping in so that we'll
+ * be awakened when they arrive.
+ */
+ current->real_blocked = current->blocked;
+ sigandsets(&current->blocked, &current->blocked, &these);
+ recalc_sigpending();
+ spin_unlock_irq(&current->sighand->siglock);
- if (timeout) {
- /*
- * None ready -- temporarily unblock those we're
- * interested while we are sleeping in so that we'll
- * be awakened when they arrive.
- */
- current->real_blocked = current->blocked;
- sigandsets(&current->blocked, &current->blocked, &these);
- recalc_sigpending();
- spin_unlock_irq(&current->sighand->siglock);
-
- timeout = schedule_timeout_interruptible(timeout);
-
- spin_lock_irq(&current->sighand->siglock);
- sig = dequeue_signal(current, &these, &info);
- current->blocked = current->real_blocked;
- siginitset(&current->real_blocked, 0);
- recalc_sigpending();
- }
+ timeout = schedule_timeout_interruptible(timeout);
+
+ spin_lock_irq(&current->sighand->siglock);
+ sig = dequeue_signal(current, &these, &info);
+ current->blocked = current->real_blocked;
+ siginitset(&current->real_blocked, 0);
+ recalc_sigpending();
}
spin_unlock_irq(&current->sighand->siglock);