job control: reorganize wait_task_stopped()
authorTejun Heo <tj@kernel.org>
Thu, 12 May 2011 08:47:23 +0000 (10:47 +0200)
committerOleg Nesterov <oleg@redhat.com>
Fri, 13 May 2011 16:56:02 +0000 (18:56 +0200)
commit19e274630c9e23a84d5940af83cf5db35103f968
tree334344b87c92cf9d9ec6ea04151e1bf65742c58f
parent40ae717d1e78d982bd469b2013a4cbf4ec1ca434
job control: reorganize wait_task_stopped()

wait_task_stopped() tested task_stopped_code() without acquiring
siglock and, if stop condition existed, called wait_task_stopped() and
directly returned the result.  This patch moves the initial
task_stopped_code() testing into wait_task_stopped() and make
wait_consider_task() fall through to wait_task_continue() on 0 return.

This is for the following two reasons.

* Because the initial task_stopped_code() test is done without
  acquiring siglock, it may race against SIGCONT generation.  The
  stopped condition might have been replaced by continued state by the
  time wait_task_stopped() acquired siglock.  This may lead to
  unexpected failure of WNOHANG waits.

  This reorganization addresses this single race case but there are
  other cases - TASK_RUNNING -> TASK_STOPPED transition and EXIT_*
  transitions.

* Scheduled ptrace updates require changes to the initial test which
  would fit better inside wait_task_stopped().

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
kernel/exit.c