From nobody@FreeBSD.org  Tue Aug 20 17:38:56 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 071F980D
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Aug 2013 17:38:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id CF4492F78
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Aug 2013 17:38:55 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r7KHctrB052756
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Aug 2013 17:38:55 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r7KHctWf052750;
	Tue, 20 Aug 2013 17:38:55 GMT
	(envelope-from nobody)
Message-Id: <201308201738.r7KHctWf052750@oldred.freebsd.org>
Date: Tue, 20 Aug 2013 17:38:55 GMT
From: Steffen <sdaoden@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sh(1) wait(1) builtin fails after bg job was SIG(STOP|TSTP|CONT) controlled
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181435
>Category:       bin
>Synopsis:       sh(1) wait(1) builtin fails after bg job was SIG(STOP|TSTP|CONT) controlled
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 20 17:40:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Sun Mar 02 21:39:03 UTC 2014
>Originator:     Steffen
>Release:        10.0-CURRENT
>Organization:
>Environment:
FreeBSD fbsd10 10.0-CURRENT FreeBSD 10.0-CURRENT #0: Sun Jun 23 02:55:37 UTC 2013     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
I simply paste over, i somehow lost the log of the FreeBSD session (sorry!)

* [steffen <at> nhead]$ /bin/sleep 30 &
* [steffen <at> nhead]$ jobs
[1] + Running                 /bin/sleep 30
* [steffen <at> nhead]$ kill -STOP %1
* [steffen <at> nhead]$ jobs
[1] + Running                 /bin/sleep 30
* [steffen <at> nhead]$ wait %1
[1] + Suspended (signal)      /bin/sleep 30
* [steffen <at> nhead]$ kill -CONT %1
* [steffen <at> nhead]$ jobs
[1] + Suspended (signal)      /bin/sleep 30
* [steffen <at> nhead]$ wait %1
* [steffen <at> nhead]$ wait
* [steffen <at> nhead]$ jobs
[1] + Suspended (signal)      /bin/sleep 30
* [steffen <at> nhead]$ 
[1]   Done                    /bin/sleep 30
* [steffen <at> nhead]$ 


Of the tested mksh(1), NetBSD sh(1), dash(1), FreeBSD sh(1), Mac OS X /bin/ksh and bash(1), only the latter two "do the right thing" (satisfy me, that is):


Mac OS X /bin/ksh(1):

?0[steffen <at> sherwood]$ /bin/sleep 30 &
[1]	43762
?0[steffen <at> sherwood]$ jobs
[1] +  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ wait  
^C?258[steffen <at> sherwood]$ jobs
[1] +  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ kill -STOP %1
?0[steffen <at> sherwood]$ jobs         
[1] +  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ wait %1
[1] + Stopped (SIGSTOP)        /bin/sleep 30 &
?0[steffen <at> sherwood]$ kill -CONT %1
?0[steffen <at> sherwood]$ jobs
[1] +  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ wait %1

^C?258[steffen <at> sherwood]$ jobs
?0[steffen <at> sherwood]$ 


bash(1):

?0[steffen <at> sherwood]$ /bin/sleep 30 &
[1] 43752
?0[steffen <at> sherwood]$ wait %1
^C
?1[steffen <at> sherwood]$ kill -STOP %1
?0[steffen <at> sherwood]$ jobs
[1]+  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ wait %1

[1]+  Stopped                 /bin/sleep 30
?145[steffen <at> sherwood]$ wait %1
bash: warning: wait_for_job: job 1 is stopped
?145[steffen <at> sherwood]$ kill -CONT %1
?0[steffen <at> sherwood]$ jobs
[1]+  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ wait %1
^C
?1[steffen <at> sherwood]$ jobs
[1]+  Running                 /bin/sleep 30 &
?0[steffen <at> sherwood]$ 
[1]+  Done                    /bin/sleep 30
>How-To-Repeat:

>Fix:
no. sorry.

>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, sdaoden@gmail.com
Cc:  
Subject: Re: bin/181435: sh(1) wait(1) builtin fails after bg job was
 SIG(STOP|TSTP|CONT) controlled
Date: Thu, 22 Aug 2013 00:16:01 +0200

 In PR bin/181435, you wrote:
 > sh(1) wait(1) builtin fails after bg job was
 > SIG(STOP|TSTP|CONT) controlled
 
 There is definitely a bug here because the wait builtin may delete a
 stopped job named on the command line, as if it were done.
 
 Additionally, handling of stopped jobs in general is not as prescribed
 by POSIX, and the handling prescribed by POSIX may be undesirable as
 well.
 
 It looks like POSIX allows 'wait' only on jobs whose "process IDs are
 known in the shell environment", in other words (for jobs that have not
 been waited for yet) when the job was started as an asynchronous list
 and was not used with 'fg', or the job was used with 'bg' and the last
 use with 'bg' was after the last use (if any) with 'fg'. Therefore, kill
 -STOP or -CONT do not affect this. If an explicit job is given and it is
 not "known", it shall be as if it exited with status 127; there shall be
 no error message. This is certainly not nice.
 
 The POSIX behaviour for operandless wait seems less strange. However, it
 is still harder to understand than sh's current behaviour of waiting for
 all jobs that are not stopped (it is the same if you do not use kill to
 stop or continue processes). Note that sh only uses WUNTRACED |
 WCONTINUED if interactive (and job control is compiled in).
 
 A further related change is r238865 which makes 10-current sh use
 WCONTINUED. This is not in older branches.
 
 -- 
 Jilles Tjoelker

From: Steffen "Daode" Nurpmeso <sdaoden@gmail.com>
To: Jilles Tjoelker <jilles@stack.nl>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/181435: sh(1) wait(1) builtin fails after bg job was
 SIG(STOP|TSTP|CONT) controlled
Date: Thu, 22 Aug 2013 12:50:08 +0200

 Jilles Tjoelker <jilles@stack.nl> wrote:
  |In PR bin/181435, you wrote:
  |>sh(1) wait(1) builtin fails after bg job was
  |>SIG(STOP|TSTP|CONT) controlled
  |
  |There is definitely a bug here because the wait builtin may delete a
  |stopped job named on the command line, as if it were done.
 
 yes =E2=80=93=C2=A0disappearing jobs are an annoyance.
 
 :-))
 
  |Jilles Tjoelker
 
 Ciao,
 
 --steffen

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/181435: commit references a PR
Date: Sat, 24 Aug 2013 09:57:45 +0000 (UTC)

 Author: jilles
 Date: Sat Aug 24 09:57:32 2013
 New Revision: 254767
 URL: http://svnweb.freebsd.org/changeset/base/254767
 
 Log:
   sh: Do not prematurely discard stopped jobs in a wait builtin.
   
   If a job is specified to 'wait', wait for it to complete. Formerly, in
   interactive mode, the job was deleted if it stopped.
   
   If no jobs are specified in interactive mode, 'wait' still waits for all jobs
   to complete or stop.
   
   In non-interactive mode, WUNTRACED is not passed to wait3() so stopped jobs
   are not detected.
   
   PR:		bin/181435
 
 Modified:
   head/bin/sh/jobs.c
 
 Modified: head/bin/sh/jobs.c
 ==============================================================================
 --- head/bin/sh/jobs.c	Sat Aug 24 09:42:14 2013	(r254766)
 +++ head/bin/sh/jobs.c	Sat Aug 24 09:57:32 2013	(r254767)
 @@ -495,14 +495,10 @@ waitcmdloop(struct job *job)
  	in_waitcmd++;
  	do {
  		if (job != NULL) {
 -			if (job->state) {
 +			if (job->state == JOBDONE) {
  				status = job->ps[job->nprocs - 1].status;
  				if (WIFEXITED(status))
  					retval = WEXITSTATUS(status);
 -#if JOBS
 -				else if (WIFSTOPPED(status))
 -					retval = WSTOPSIG(status) + 128;
 -#endif
  				else
  					retval = WTERMSIG(status) + 128;
  				if (! iflag || ! job->changed)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun Mar 2 21:38:07 UTC 2014 
State-Changed-Why:  
I think the fix in SVN r254767 (in stable/10 and head) is sufficient. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Mar 2 21:38:07 UTC 2014 
Responsible-Changed-Why:  
I fixed the bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=181435 
>Unformatted:
