Skip to content

Commit

Permalink
ipc/sem.c: handle spurious wakeups
Browse files Browse the repository at this point in the history
semtimedop() does not handle spurious wakeups, it returns -EINTR to user
space.  Most other schedule() users would just loop and not return to user
space.  The patch adds such a loop to semtimedop()

Signed-off-by: Manfred Spraul <[email protected]>
Reported-by: Peter Zijlstra <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Mike Galbraith <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
manfred-colorfu authored and torvalds committed Nov 2, 2011
1 parent 3c24783 commit 0b0577f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,

queue.status = -EINTR;
queue.sleeper = current;

sleep_again:
current->state = TASK_INTERRUPTIBLE;
sem_unlock(sma);

Expand Down Expand Up @@ -1478,6 +1480,13 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
*/
if (timeout && jiffies_left == 0)
error = -EAGAIN;

/*
* If the wakeup was spurious, just retry
*/
if (error == -EINTR && !signal_pending(current))
goto sleep_again;

unlink_queue(sma, &queue);

out_unlock_free:
Expand Down

0 comments on commit 0b0577f

Please sign in to comment.