From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 9AC2D2552C for ; Sat, 20 Jan 2024 13:31:26 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705753886; b=Buo38P4tkzgX7tO6rCLG5qXXlkpn8nMwmxSIxRCme8oDx3astA3z1S6K9ecxwYhtbW+eaBtiS/ tRKLYuNUzNYZWoVNU2qetU97ez7CyCXk94sdmz7WWt/0vkQMCsnbljXWll11aQtLP/uESkc5G3 dAMB/wT/EwhfRwCrnd71JYcVkckb/nm5u5FzihgwIDPAjl3h9dTuL+SHXPuVUlvIvU0p/DyFYX WEyvHx6IkBnVKQIcBcU0XEiAn62q41IRNWBo2OsCaxSqLkP+HEymplnZzx3F9OyHnaTbQ6eLty tN2m017zG7MQb8Jb8vROiqqaI3CRN9iGlhoGTJlzB9LDUw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (lxh-heta-035.node.capitar.com) smtp.remote-ip=159.69.139.61; dmarc=none header.from=opperschaap.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1705753886; bh=7Bzpq284wYJaGJrluJoKtDrEPUsMCOBqJL38GW2g7sk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:DKIM-Signature; b=Z8RQt7L++ZdmdlzokaH7LkDvQnmSwcGxadA6Dtf1rc19rLMBG+bby7Lk3XHnSA7VwSOqLNkDn7 yX5iSlyQtTsyXyFEv6xSAZk78PMyODTyTnoaTYP4h8nzvxtsQENFfwvDwB42g3+uI+C4J6F/S7 YuVIab0WikHA2GB8YCEu8d/wAFHAMgXcPsvhNpaKAWZgaPLyGHVK+/9J9IKVNj4qL2oEGMwwP0 q9XcYFddXwbeWsxDohjM0gfMDpE/2HJ9SlVxtQPB7GFwKtNCe2st+6DrZX1nSANmIo+PgznpNi EpfrV1i5n+86LGrtnFELROmqtiaETKxx9O97H6DBaTivtA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=VqA7c1YRRcU7cSUvHNQUBjayS4ZpwiBy3XQ1Ag5MA78=; b=mj84t7c0qu+cw54GmihNgawC6C Md0t4h013SbhM84Kbg7zMx1LiUdSsJh+Q6HTRGe1yHcakW/36a+GrM2/ntbWudTUwrXn1UO6rm4B1 PQhvAWVBiLJ3MC0eSYbkfjMytsYMNsQugWNCkzVwb2iHo2Kp+2QFjytyh8WYH+IY16ZFnQX8BM288 Oya2XgoeBDx16MRcQ4ePebbg8BqTGu5qftSrCvwHWj6W+Gv0iru4/DEDinBv5cp3QPoSszzo7IJLF 47zc2fALrD3iUYvd7b9SeiaD+j1aIAnY6o3E0PNyrGIVUZYZYEnEA4Qg8TmQUuwJja8D1bzFDqj8I QwtMcZug==; Received: by zero.zsh.org with local id 1rRAVP-0004NB-Sj; Sat, 20 Jan 2024 12:31:23 +0000 Authentication-Results: zsh.org; iprev=pass (lxh-heta-035.node.capitar.com) smtp.remote-ip=159.69.139.61; dmarc=none header.from=opperschaap.net; arc=none Received: from lxh-heta-035.node.capitar.com ([159.69.139.61]:56222 helo=eur-mail-proxy-p01.zt.capitar.com) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rRAV6-00044b-HG; Sat, 20 Jan 2024 12:31:07 +0000 Received: from eur-mail-proxy-p01.zt.capitar.com (localhost [127.0.0.1]) by eur-mail-proxy-p01.zt.capitar.com (Postfix) with ESMTPS id 79ECB1D878; Sat, 20 Jan 2024 13:31:03 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by eur-mail-proxy-p01.zt.capitar.com (Postfix) with ESMTP id F2A6F1D9C3; Sat, 20 Jan 2024 13:31:02 +0100 (CET) Received: from eur-mail-proxy-p01.zt.capitar.com ([127.0.0.1]) by localhost (eur-mail-proxy-p01.zt.capitar.com [127.0.0.1]) (amavis, port 10026) with ESMTP id JQMyKboCZBkw; Sat, 20 Jan 2024 13:31:02 +0100 (CET) Received: from sputnik-odin.setarnet.aw (186-189-151-106.setardsl.aw [186.189.151.106]) by eur-mail-proxy-p01.zt.capitar.com (Postfix) with ESMTPSA id 813C31DCA2; Sat, 20 Jan 2024 13:31:01 +0100 (CET) From: Wesley Schwengle To: zsh-workers@zsh.org Subject: [PATCH v2] Fix jobs -p to be POSIX compliant Date: Sat, 20 Jan 2024 08:30:54 -0400 Message-ID: <20240120123054.290214-1-wesleys@opperschaap.net> X-Mailer: git-send-email 2.42.0.1140.gf01f4dc781 In-Reply-To: <20240119232229.177255-1-wesleys@opperschaap.net> References: <20240119232229.177255-1-wesleys@opperschaap.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=OJFZIhSB c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=NNsMJ0FP/O/2rce1Ysg3eA==:17 a=dEuoMetlWLkA:10 a=xNf9USuDAAAA:8 a=N3miCFJ7AAAA:8 a=nNxROEWhurgGX-JtIWcA:9 a=SEwjQc04WA-l_NiBhQ7s:22 a=V5H4rQgsk92nlYCD-KPC:22 X-Seq: 52493 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: In Debian the following bug was reported a couple of year ago and someone re-raised it: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D346162 POSIX says that with "jobs -p", only the PID is output, whereas zsh outputs full information. There is discussion in the bug regarding POSIX_BUILTINS and refers to workers/21366. The latter is interesting because it refers to setopt long_list_jobs. I would want to argue that jobs -p should only show the PID regardless of that setting and POSIX_BUILTINS. jobs has the -l option, where the full line is displayed. From that point it doesn't make a whole lot of sense to have jobs -p do the same thing. From a UI standpoint I think it is more logical to let jobs -l do a long listing and jobs -p only show the pid. Than there is the issue where its argued that zsh shows the group pid and not the actual pid of the process that is running. I looked at the output of bash and with this patch zsh and bash act similar. They both show the pid of the command group: On bash: $ ( sleep 20 && echo foo) & sleep 5 & $ jobs -p && jobs -l 255028 255029 [1]- 255028 Running ( sleep 20 && echo foo ) & [2]+ 255029 Done sleep 5 On zsh with this patch: $ ( sleep 20 && echo foo) & sleep 5 & $ jobs -l && jobs -p [1] 255065 [2] 255066 [1] - 255065 running ( sleep 20 && echo foo; ) [2] + 255066 running sleep 5 255065 255066 Signed-off-by: Wesley Schwengle --- Src/jobs.c | 16 ++++++---------- Test/W02jobs.ztst | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Src/jobs.c b/Src/jobs.c index 118c5e61b..14f1be831 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1209,6 +1209,11 @@ printjob(Job jn, int lng, int synch) putc('\n', fout); } for (pn =3D jn->procs; pn;) { + if (lng & 2) { + fprintf(fout, "%ld\n", (long) jn->gleader); + doneprint =3D 1; + break; + } len2 =3D (thisfmt ? 5 : 10) + len; /* 2 spaces */ if (lng & 3) qn =3D pn->next; @@ -1235,16 +1240,7 @@ printjob(Job jn, int lng, int synch) fprintf(fout, "zsh: "); if (lng & 1) fprintf(fout, "%ld ", (long) pn->pid); - else if (lng & 2) { - pid_t x =3D jn->gleader; - - fprintf(fout, "%ld ", (long) x); - do - skip++; - while ((x /=3D 10)); - skip++; - lng &=3D ~3; - } else + else fprintf(fout, "%*s", skip, ""); if (pn->status =3D=3D SP_RUNNING) { if (!conted) diff --git a/Test/W02jobs.ztst b/Test/W02jobs.ztst index d52888dd9..11bbdbf43 100644 --- a/Test/W02jobs.ztst +++ b/Test/W02jobs.ztst @@ -128,7 +128,7 @@ 0:`jobs -l` and `jobs -p` with running job *>\[1] [0-9]## *>\[1] + [0-9]## running*sleep* -*>\[1] + [0-9]## running*sleep* +*>[0-9]## *>zsh:*SIGHUPed* =20 zpty_start --=20 2.42.0.1140.gf01f4dc781