mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
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>
This commit is contained in:
parent
bb7efee2ca
commit
fe0faa005d
2 changed files with 36 additions and 48 deletions
|
@ -893,7 +893,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
|
||||||
int sig;
|
int sig;
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
long ret, timeout = 0;
|
long ret, timeout;
|
||||||
|
|
||||||
if (sigsetsize != sizeof(sigset_t))
|
if (sigsetsize != sizeof(sigset_t))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -904,25 +904,20 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
|
||||||
sigdelsetmask(&s,sigmask(SIGKILL)|sigmask(SIGSTOP));
|
sigdelsetmask(&s,sigmask(SIGKILL)|sigmask(SIGSTOP));
|
||||||
signotset(&s);
|
signotset(&s);
|
||||||
|
|
||||||
|
timeout = MAX_SCHEDULE_TIMEOUT;
|
||||||
if (uts) {
|
if (uts) {
|
||||||
if (get_compat_timespec (&t, uts))
|
if (get_compat_timespec (&t, uts))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0
|
if (!timespec_valid(&t))
|
||||||
|| t.tv_sec < 0)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
timeout = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
sig = dequeue_signal(current, &s, &info);
|
sig = dequeue_signal(current, &s, &info);
|
||||||
if (!sig) {
|
if (!sig && timeout) {
|
||||||
timeout = MAX_SCHEDULE_TIMEOUT;
|
|
||||||
if (uts)
|
|
||||||
timeout = timespec_to_jiffies(&t)
|
|
||||||
+(t.tv_sec || t.tv_nsec);
|
|
||||||
if (timeout) {
|
|
||||||
current->real_blocked = current->blocked;
|
current->real_blocked = current->blocked;
|
||||||
sigandsets(¤t->blocked, ¤t->blocked, &s);
|
sigandsets(¤t->blocked, ¤t->blocked, &s);
|
||||||
|
|
||||||
recalc_sigpending();
|
recalc_sigpending();
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
|
|
||||||
|
@ -934,7 +929,6 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
|
||||||
siginitset(¤t->real_blocked, 0);
|
siginitset(¤t->real_blocked, 0);
|
||||||
recalc_sigpending();
|
recalc_sigpending();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
|
|
||||||
if (sig) {
|
if (sig) {
|
||||||
|
@ -943,7 +937,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
|
||||||
if (copy_siginfo_to_user32(uinfo, &info))
|
if (copy_siginfo_to_user32(uinfo, &info))
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
ret = timeout?-EINTR:-EAGAIN;
|
ret = timeout?-EINTR:-EAGAIN;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -2519,7 +2519,7 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
|
||||||
sigset_t these;
|
sigset_t these;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
long timeout = 0;
|
long timeout;
|
||||||
|
|
||||||
/* XXX: Don't preclude handling different sized sigset_t's. */
|
/* XXX: Don't preclude handling different sized sigset_t's. */
|
||||||
if (sigsetsize != sizeof(sigset_t))
|
if (sigsetsize != sizeof(sigset_t))
|
||||||
|
@ -2535,23 +2535,18 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
|
||||||
sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
|
sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
|
||||||
signotset(&these);
|
signotset(&these);
|
||||||
|
|
||||||
|
timeout = MAX_SCHEDULE_TIMEOUT;
|
||||||
if (uts) {
|
if (uts) {
|
||||||
if (copy_from_user(&ts, uts, sizeof(ts)))
|
if (copy_from_user(&ts, uts, sizeof(ts)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
|
if (!timespec_valid(&ts))
|
||||||
|| ts.tv_sec < 0)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
timeout = timespec_to_jiffies(&ts) + (ts.tv_sec || ts.tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
sig = dequeue_signal(current, &these, &info);
|
sig = dequeue_signal(current, &these, &info);
|
||||||
if (!sig) {
|
if (!sig && timeout) {
|
||||||
timeout = MAX_SCHEDULE_TIMEOUT;
|
|
||||||
if (uts)
|
|
||||||
timeout = (timespec_to_jiffies(&ts)
|
|
||||||
+ (ts.tv_sec || ts.tv_nsec));
|
|
||||||
|
|
||||||
if (timeout) {
|
|
||||||
/*
|
/*
|
||||||
* None ready -- temporarily unblock those we're
|
* None ready -- temporarily unblock those we're
|
||||||
* interested while we are sleeping in so that we'll
|
* interested while we are sleeping in so that we'll
|
||||||
|
@ -2570,7 +2565,6 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
|
||||||
siginitset(¤t->real_blocked, 0);
|
siginitset(¤t->real_blocked, 0);
|
||||||
recalc_sigpending();
|
recalc_sigpending();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
|
|
||||||
if (sig) {
|
if (sig) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue