From owner-freebsd-standards@FreeBSD.ORG Wed Mar 13 12:20:01 2013 Return-Path: Delivered-To: freebsd-standards@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 608BB6AC for ; Wed, 13 Mar 2013 12:20:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 46DF6D7B for ; Wed, 13 Mar 2013 12:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r2DCK1lg054691 for ; Wed, 13 Mar 2013 12:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r2DCK1hV054690; Wed, 13 Mar 2013 12:20:01 GMT (envelope-from gnats) Resent-Date: Wed, 13 Mar 2013 12:20:01 GMT Resent-Message-Id: <201303131220.r2DCK1hV054690@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Vadim S. Goncharov" Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A4AB8573 for ; Wed, 13 Mar 2013 12:18:25 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 95015D58 for ; Wed, 13 Mar 2013 12:18:25 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r2DCIOIG048935 for ; Wed, 13 Mar 2013 12:18:24 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id r2DCIO9u048934; Wed, 13 Mar 2013 12:18:24 GMT (envelope-from nobody) Message-Id: <201303131218.r2DCIO9u048934@red.freebsd.org> Date: Wed, 13 Mar 2013 12:18:24 GMT From: "Vadim S. Goncharov" To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: standards/176916: [patch] sh(1): implement multiple arguments to wait builtin X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Mar 2013 12:20:01 -0000 >Number: 176916 >Category: standards >Synopsis: [patch] sh(1): implement multiple arguments to wait builtin >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Mar 13 12:20:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Vadim S. Goncharov >Release: FreeBSD 9.0-RELEASE amd64 >Organization: RU-CENTER (www.nic.ru) >Environment: FreeBSD noc-42.nic.ru 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: POSIX.2 requires that wait(1) built-in in sh(1) shall support multiple arguments, and that unknown (e.g. errorneous) job specification be treated as known with exit status 127 (it is currently 2), see http://pubs.opengroup.org/onlinepubs/009695399/utilities/wait.html The patch attached implements this functionality which was absent in our shell. This feature is essential for implementing e.g. parallel execution of rc.d scripts, so please commit/MFC it as soon as possible :) >How-To-Repeat: Try to do sleep 33 & sleep 44 & wait %2 %1 echo $? other args are ignored. >Fix: Patch attached. Patch attached with submission follows: Index: bin/sh/sh.1 =================================================================== --- bin/sh/sh.1 (revision 248189) +++ bin/sh/sh.1 (working copy) @@ -2598,12 +2598,17 @@ option is specified, the .Ar name arguments are treated as function names. -.It Ic wait Op Ar job -Wait for the specified +.It Ic wait Op Ar job ... +Wait for each specified .Ar job to complete and return the exit status of the last process in the +last specified .Ar job . -If the argument is omitted, wait for all jobs to complete +If any +.Ar job +specified is incorrect or unknown to shell, it is treated as if it +were known job that exited with exit status 127. +If arguments are omitted, wait for all jobs to complete and return an exit status of zero. .El .Ss Commandline Editing Index: bin/sh/jobs.c =================================================================== --- bin/sh/jobs.c (revision 248189) +++ bin/sh/jobs.c (working copy) @@ -95,6 +95,7 @@ static void restartjob(struct job *); #endif static void freejob(struct job *); +static int waitcmdloop(struct job *); static struct job *getjob(char *); pid_t getjobpgrp(char *); static pid_t dowait(int, struct job *); @@ -461,15 +462,35 @@ waitcmd(int argc, char **argv) { struct job *job; + struct jmploc jmploc; + struct jmploc *const savehandler = handler; + int retval = 0; + + if (argc <= 1) + return waitcmdloop(NULL); + + do { + if (setjmp(jmploc.loc)) { + retval = 127; /* Posix.2, section 4.70.2 */ + handler = savehandler; + continue; + } else { + handler = &jmploc; + job = getjob(*++argv); + } + handler = savehandler; + retval = waitcmdloop(job); + } while (--argc > 1); + + return (retval); +} + +static int +waitcmdloop(struct job *job) +{ int status, retval; struct job *jp; - if (argc > 1) { - job = getjob(argv[1]); - } else { - job = NULL; - } - /* * Loop until a process is terminated or stopped, or a SIGINT is * received. >Release-Note: >Audit-Trail: >Unformatted: