NetBSD Problem Report #57894

From www@netbsd.org  Tue Jan 30 13:34:56 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 6316A1A9238
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 30 Jan 2024 13:34:56 +0000 (UTC)
Message-Id: <20240130133455.801D31A9239@mollari.NetBSD.org>
Date: Tue, 30 Jan 2024 13:34:55 +0000 (UTC)
From: koichi@nksm.name
Reply-To: koichi@nksm.name
To: gnats-bugs@NetBSD.org
Subject: sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
X-Send-Pr-Version: www-1.0

>Number:         57894
>Category:       bin
>Synopsis:       sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 30 13:35:00 +0000 2024
>Closed-Date:    Sat Feb 03 22:44:48 +0000 2024
>Last-Modified:  Sat Feb 03 22:44:48 +0000 2024
>Originator:     Koichi Nakashima
>Release:        NetBSD 10.0_RC3
>Organization:
>Environment:
NetBSD vm-netbsd10-0.home 10.0_RC3 NetBSD 10.0_RC3 (GENERIC) #0: Tue Jan 16 08:28:51 UTC 2024  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
on NetBSD 10.0 RC3
$ sh -c 'sleep 3 & echo $!; jobs -l; jobs -p'
7975
[1] + 7975 Running            sleep 3 &
0

on NetBSD 9.3
$ sh -c 'sleep 3 & echo $!; jobs -l; jobs -p'
573
[1] + 573 Running             sleep 3 &
573
>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Tue, 30 Jan 2024 16:23:37 +0000
Responsible-Changed-Why:
I am looking into this PR


From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
Date: Wed, 31 Jan 2024 02:00:44 +0700

     Date:        Tue, 30 Jan 2024 13:35:00 +0000 (UTC)
     From:        koichi@nksm.name
     Message-ID:  <20240130133500.967921A923A@mollari.NetBSD.org>

   | >Synopsis:       sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC

   | $ sh -c 'sleep 3 & echo $!; jobs -l; jobs -p'
   | 7975
   | [1] + 7975 Running            sleep 3 &
   | 0

 This wasn't intended, and I am about to commit a fix, but at
 least according to POSIX, that isn't required to work.

    -p Display only the process IDs for the process group leaders of job-control
       background jobs and the process IDs associated with non-job-control
       background jobs (if supported).

 Non-interactive shells (which is what that is) don't enable job control,
 so that sleep 3 is a non-job-control background job, and we're not required
 to support -p for those.

 If job control were enabled, as in

 	sh -c 'set -m; sleep 3 & echo $!; jobs -l; jobs -p'

 then it would work (in -10, and HEAD, without the coming fix).

 The issue is a fix that was making sure the correct value was
 always output for job-control jobs (there were ways, in more complex
 examples, to get the wrong pid printed).   But the non-job-control
 ones just got forgotten.   Oops...

 For now, in the non-job-control case, sh will just do what it used to do
 (while still doing it the new way for job-controlled background jobs).


From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57894 CVS commit: src/bin/sh
Date: Tue, 30 Jan 2024 19:05:07 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Tue Jan 30 19:05:07 UTC 2024

 Modified Files:
 	src/bin/sh: jobs.c

 Log Message:
 PR bin/57894

 For jobs -p for a non-job-control job, avoid just printing 0 (as
 there is no process group pid) and instead output what we used to,
 the pid of one of the processes in the job (usually the right one!)

 XXX pullup -10 (9 and earlier not affected).


 To generate a diff of this commit:
 cvs rdiff -u -r1.118 -r1.119 src/bin/sh/jobs.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Tue, 30 Jan 2024 19:43:09 +0000
State-Changed-Why:
[pullup-10 #577]


From: Koichi Nakashima <koichi@nksm.name>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on NetBSD
 10.0 RC
Date: Wed, 31 Jan 2024 08:18:08 +0900

 --0000000000006d318e061031faed
 Content-Type: text/plain; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable

 Thanks for the fixing and the detailed explanation.
 My concern was backward compatibility.
 I probably won't use the jobs command with
 non-interactive shells (unless it is absolutely necessary).


 2024=E5=B9=B41=E6=9C=8831=E6=97=A5(=E6=B0=B4) 4:05 Robert Elz <kre@munnari.=
 oz.au>:

 > The following reply was made to PR bin/57894; it has been noted by GNATS.
 >
 > From: Robert Elz <kre@munnari.OZ.AU>
 > To: gnats-bugs@netbsd.org
 > Cc:
 > Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on
 > NetBSD 10.0 RC
 > Date: Wed, 31 Jan 2024 02:00:44 +0700
 >
 >      Date:        Tue, 30 Jan 2024 13:35:00 +0000 (UTC)
 >      From:        koichi@nksm.name
 >      Message-ID:  <20240130133500.967921A923A@mollari.NetBSD.org>
 >
 >    | >Synopsis:       sh(1): PID obtained with jobs -p is always 0 on
 > NetBSD 10.0 RC
 >
 >    | $ sh -c 'sleep 3 & echo $!; jobs -l; jobs -p'
 >    | 7975
 >    | [1] + 7975 Running            sleep 3 &
 >    | 0
 >
 >  This wasn't intended, and I am about to commit a fix, but at
 >  least according to POSIX, that isn't required to work.
 >
 >     -p Display only the process IDs for the process group leaders of
 > job-control
 >        background jobs and the process IDs associated with non-job-contro=
 l
 >        background jobs (if supported).
 >
 >  Non-interactive shells (which is what that is) don't enable job control,
 >  so that sleep 3 is a non-job-control background job, and we're not
 > required
 >  to support -p for those.
 >
 >  If job control were enabled, as in
 >
 >         sh -c 'set -m; sleep 3 & echo $!; jobs -l; jobs -p'
 >
 >  then it would work (in -10, and HEAD, without the coming fix).
 >
 >  The issue is a fix that was making sure the correct value was
 >  always output for job-control jobs (there were ways, in more complex
 >  examples, to get the wrong pid printed).   But the non-job-control
 >  ones just got forgotten.   Oops...
 >
 >  For now, in the non-job-control case, sh will just do what it used to do
 >  (while still doing it the new way for job-controlled background jobs).
 >
 >
 >

 --0000000000006d318e061031faed
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable

 <div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">Thanks for the fixing an=
 d the detailed explanation.</div><div dir=3D"ltr">My concern was backward c=
 ompatibility.</div><div dir=3D"ltr">I probably won&#39;t use the jobs comma=
 nd with</div><div dir=3D"ltr">non-interactive shells (unless it is absolute=
 ly necessary).<br></div><br class=3D"gmail-Apple-interchange-newline"></div=
 ><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">2024=
 =E5=B9=B41=E6=9C=8831=E6=97=A5(=E6=B0=B4) 4:05 Robert Elz &lt;<a href=3D"ma=
 ilto:kre@munnari.oz.au">kre@munnari.oz.au</a>&gt;:<br></div><blockquote cla=
 ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid =
 rgb(204,204,204);padding-left:1ex">The following reply was made to PR bin/5=
 7894; it has been noted by GNATS.<br>
 <br>
 From: Robert Elz &lt;<a href=3D"mailto:kre@munnari.OZ.AU" target=3D"_blank"=
 >kre@munnari.OZ.AU</a>&gt;<br>
 To: <a href=3D"mailto:gnats-bugs@netbsd.org" target=3D"_blank">gnats-bugs@n=
 etbsd.org</a><br>
 Cc: <br>
 Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on Net=
 BSD 10.0 RC<br>
 Date: Wed, 31 Jan 2024 02:00:44 +0700<br>
 <br>
 =C2=A0 =C2=A0 =C2=A0Date:=C2=A0 =C2=A0 =C2=A0 =C2=A0 Tue, 30 Jan 2024 13:35=
 :00 +0000 (UTC)<br>
 =C2=A0 =C2=A0 =C2=A0From:=C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"mailto:koic=
 hi@nksm.name" target=3D"_blank">koichi@nksm.name</a><br>
 =C2=A0 =C2=A0 =C2=A0Message-ID:=C2=A0 &lt;<a href=3D"mailto:20240130133500.=
 967921A923A@mollari.NetBSD.org" target=3D"_blank">20240130133500.967921A923=
 A@mollari.NetBSD.org</a>&gt;<br>
 <br>
 =C2=A0 =C2=A0| &gt;Synopsis:=C2=A0 =C2=A0 =C2=A0 =C2=A0sh(1): PID obtained =
 with jobs -p is always 0 on NetBSD 10.0 RC<br>
 <br>
 =C2=A0 =C2=A0| $ sh -c &#39;sleep 3 &amp; echo $!; jobs -l; jobs -p&#39;<br=
 >
 =C2=A0 =C2=A0| 7975<br>
 =C2=A0 =C2=A0| [1] + 7975 Running=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
 sleep 3 &amp;<br>
 =C2=A0 =C2=A0| 0<br>
 <br>
 =C2=A0This wasn&#39;t intended, and I am about to commit a fix, but at<br>
 =C2=A0least according to POSIX, that isn&#39;t required to work.<br>
 <br>
 =C2=A0 =C2=A0 -p Display only the process IDs for the process group leaders=
  of job-control<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0background jobs and the process IDs associated w=
 ith non-job-control<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0background jobs (if supported).<br>
 <br>
 =C2=A0Non-interactive shells (which is what that is) don&#39;t enable job c=
 ontrol,<br>
 =C2=A0so that sleep 3 is a non-job-control background job, and we&#39;re no=
 t required<br>
 =C2=A0to support -p for those.<br>
 <br>
 =C2=A0If job control were enabled, as in<br>
 <br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sh -c &#39;set -m; sleep 3 &amp; echo $!; jobs =
 -l; jobs -p&#39;<br>
 <br>
 =C2=A0then it would work (in -10, and HEAD, without the coming fix).<br>
 <br>
 =C2=A0The issue is a fix that was making sure the correct value was<br>
 =C2=A0always output for job-control jobs (there were ways, in more complex<=
 br>
 =C2=A0examples, to get the wrong pid printed).=C2=A0 =C2=A0But the non-job-=
 control<br>
 =C2=A0ones just got forgotten.=C2=A0 =C2=A0Oops...<br>
 <br>
 =C2=A0For now, in the non-job-control case, sh will just do what it used to=
  do<br>
 =C2=A0(while still doing it the new way for job-controlled background jobs)=
 .<br>
 <br>
 <br>
 </blockquote></div></div>

 --0000000000006d318e061031faed--

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
Date: Thu, 01 Feb 2024 02:41:19 +0700

     Date:        Tue, 30 Jan 2024 23:20:01 +0000 (UTC)
     From:        Koichi Nakashima <koichi@nksm.name>
     Message-ID:  <20240130232001.A179D1A9239@mollari.NetBSD.org>

   |  Thanks for the fixing and the detailed explanation.
   |  My concern was backward compatibility.

 No problem, and thanks for finding that, it wasn't an intended change.

   |  I probably won't use the jobs command with
   |  non-interactive shells (unless it is absolutely necessary).

 It has one simple use there, which is sometimes worth knowing (not -p)
 "jobs >/dev/null" is a simple way of cleaning up all terminated async
 processes, if you don't care about their exit status, and don't want
 any possibility of hanging waiting for something to finish.

 Most other potential uses are generally better handled some other way.

 kre

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57894 CVS commit: [netbsd-10] src/bin/sh
Date: Sat, 3 Feb 2024 14:31:39 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Feb  3 14:31:38 UTC 2024

 Modified Files:
 	src/bin/sh [netbsd-10]: jobs.c

 Log Message:
 Pull up following revision(s) (requested by kre in ticket #577):

 	bin/sh/jobs.c: revision 1.119

 PR bin/57894

 For jobs -p for a non-job-control job, avoid just printing 0 (as
 there is no process group pid) and instead output what we used to,
 the pid of one of the processes in the job (usually the right one!)


 To generate a diff of this commit:
 cvs rdiff -u -r1.117 -r1.117.2.1 src/bin/sh/jobs.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 03 Feb 2024 22:44:48 +0000
State-Changed-Why:
Pullups completed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.