- int job_state = 0;
- int any_stopped = 0;
- int any_tstped = 0;
-
- child = jobs[job]->pipe;
- jobs[job]->flags &= ~J_NOTIFIED;
-
- /* If all children are not running, but any of them is
- stopped, then the job is stopped, not dead. */
- do
- {
- job_state |= child->running;
- if (!child->running)
- {
- any_stopped |= WIFSTOPPED (child->status);
- any_tstped |= interactive && job_control &&
- WIFSTOPPED (child->status) &&
- WSTOPSIG (child->status) == SIGTSTP;
- }
- child = child->next;
- }
- while (child != jobs[job]->pipe);
-
- if (job_state == 0)
- {
- if (any_stopped)
- {
- jobs[job]->state = JSTOPPED;
- jobs[job]->flags &= ~J_FOREGROUND;
- call_set_current++;
- last_stopped_job = job;
- /* Suspending a job in a loop from the keyboard
- breaks out of all active loops. */
- if (any_tstped && loop_level)
- breaking = loop_level;
- }
- else
- {
- jobs[job]->state = JDEAD;
-
- if (job == last_stopped_job)
- last_stopped_job = NO_JOB;
-
- /* If the foreground job is killed by SIGINT when
- job control is not active, we need to perform
- some special handling. */
- /* The check of wait_sigint_received is a way to
- determine if the SIGINT came from the keyboard
- (in which case the shell has already seen it,
- and wait_sigint_received is non-zero, because
- keyboard signals are sent to process groups)
- or via kill(2) to the foreground process by
- another process (or itself). If the shell did
- receive the SIGINT, it needs to perform normal
- SIGINT processing. */
- if ((WTERMSIG (jobs[job]->pipe->status) == SIGINT) &&
- (jobs[job]->flags & J_FOREGROUND) &&
- (jobs[job]->flags & J_JOBCONTROL) == 0 &&
- wait_sigint_received)
- {
- wait_sigint_received = 0;
-
- /* If SIGINT is trapped, set the exit status so
- that the trap handler can see it. */
- if (signal_is_trapped (SIGINT))
- last_command_exit_value = process_exit_status
- (jobs[job]->pipe->status);
-
- /* If the signal is trapped, let the trap handler
- get it no matter what and simply return if
- the trap handler returns.
- maybe_call_trap_handler may cause dead jobs
- to be removed from the job table because of
- a call to execute_command. Watch out for
- this. */
- if (maybe_call_trap_handler (SIGINT) == 0 &&
- old_sigint_handler != INVALID_SIGNAL_HANDLER)
- {
- /* wait_sigint_handler () has already
- seen SIGINT and allowed the wait
- builtin to jump out. We need to
- call the original SIGINT handler. */
- SigHandler *temp_handler;
- temp_handler = old_sigint_handler;
- restore_sigint_handler ();
- if (temp_handler != SIG_IGN)
- (*temp_handler) (SIGINT);
- }
- }
- }
- }