1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Mark stopped jobs as background (re: adc6a64b)

Reproducer:

  $ /bin/sleep 100
  ^Z[1] + Stopped                  /bin/sleep 100
  $ kill %%	<--- no notification shown
  $ jobs	<--- nothing: it was in fact killed

Expected behaviour:

  $ /bin/sleep 100
  ^Z[1] + Stopped                  /bin/sleep 100
  $ kill %%
  [1] + Terminated               /bin/sleep 100

In the reproducer, the job in fact gets killed, but no notification
is printed of this fact. This is because notifications now require
the P_BG (background job) flag, and it is not set if a foreground
job is stopped. It should be: stopping moves it to the background.

When the 'sleep' builtin is used instead of the external command,
the notice says 'Done' instead of 'Terminated' because SIGTERM is
being handled via sh_fault() instead of set to SIG_DFL. It remains
to be considered if anything needs to change about that.

src/cmd/ksh93/sh/jobs.c: job_reap():
- Also set a job's P_BG bit when it was stopped.
This commit is contained in:
Martijn Dekker 2022-07-22 23:49:16 +02:00
parent 39e467dab3
commit aa468f4c55

View file

@ -374,7 +374,7 @@ int job_reap(register int sig)
pw->p_flag &= ~(P_NOTIFY|P_SIGNALLED|P_STOPPED);
else if(WIFSTOPPED(wstat))
{
pw->p_flag |= (P_NOTIFY|P_SIGNALLED|P_STOPPED);
pw->p_flag |= (P_NOTIFY|P_SIGNALLED|P_STOPPED|P_BG);
pw->p_exit = WSTOPSIG(wstat);
if(pw->p_pgrp && pw->p_pgrp==job.curpgid && sh_isstate(SH_STOPOK))
kill(sh.current_pid,pw->p_exit);