From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 18 21:10:54 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65EF7106566C for ; Sat, 18 Feb 2012 21:10:54 +0000 (UTC) (envelope-from matthewstory@gmail.com) Received: from mail-vx0-f182.google.com (mail-vx0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id 0F5418FC12 for ; Sat, 18 Feb 2012 21:10:53 +0000 (UTC) Received: by vcmm1 with SMTP id m1so4285560vcm.13 for ; Sat, 18 Feb 2012 13:10:53 -0800 (PST) Received-SPF: pass (google.com: domain of matthewstory@gmail.com designates 10.52.71.226 as permitted sender) client-ip=10.52.71.226; Authentication-Results: mr.google.com; spf=pass (google.com: domain of matthewstory@gmail.com designates 10.52.71.226 as permitted sender) smtp.mail=matthewstory@gmail.com; dkim=pass header.i=matthewstory@gmail.com Received: from mr.google.com ([10.52.71.226]) by 10.52.71.226 with SMTP id y2mr6810629vdu.78.1329599453312 (num_hops = 1); Sat, 18 Feb 2012 13:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=VqdVM7Eyrb/LcWII9y+mtoWELyASJtHIRslvofayGC0=; b=pdcT8suYqUoAG/XJ0Yol4CVgSmbibVctKEOtIOhqEdm5IqtRoANbLgB8EjORXPub7/ xjE1vdFoAAAZXfVzvmkipyrfFTJP434PSxvBrc3OqVfDfrhBqFBeVBc12doPSnqcd+lA E0ujfy+QOmefwZZyYwT878UK28qr4NqZ1+6h4= MIME-Version: 1.0 Received: by 10.52.71.226 with SMTP id y2mr5488803vdu.78.1329599452655; Sat, 18 Feb 2012 13:10:52 -0800 (PST) Received: by 10.52.21.84 with HTTP; Sat, 18 Feb 2012 13:10:52 -0800 (PST) In-Reply-To: References: <20120214193530.GA42580@stack.nl> Date: Sat, 18 Feb 2012 16:10:52 -0500 Message-ID: From: Matthew Story To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: xargs short-circuit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Feb 2012 21:10:54 -0000 On Tue, Feb 14, 2012 at 3:25 PM, Matthew Story wrote: > On Tue, Feb 14, 2012 at 2:37 PM, Matthew Story wrote: > >> On Tue, Feb 14, 2012 at 2:35 PM, Jilles Tjoelker wrote: >> >>> On Tue, Feb 14, 2012 at 01:34:49PM -0500, Matthew Story wrote: >>> > After reading the man-page, and browsing around the internet for a >>> minute, >>> > I was just wondering if there is an option in (any) xargs to >>> short-circuit >>> > on first failure of [utility [arguments]]. >>> >>> > e.g. >>> >>> > $ jot - 1 10 | xargs -e -n1 sh -c 'echo "$*"; echo exit 1' worker || >>> echo $? >>> > 1 >>> > 1 >>> >>> > such that any non-0 exit code in a child process would cause xargs to >>> stop >>> > processing. seems like this would be a nice feature to have. >>> >>> As per xargs(1), you can do this by having the command exit on a signal >>> or with a value of 255. >>> >> > exit 255 with -P, and SIGTERM (with or without -P) causes FreeBSD xargs to > orphan, is this desirable behavior? findutils xargs orphans on 255 and > SIGTERM (with -P), but does not orphan without -P when SIGTERM is sent. I > would expect xargs to propegate the signal, or wait, although the man page > does say "immediately", the POSIX specification is less clear ... this > makes it more-or-less unsuitable for my needs, but i guess i could do > something like: > > ... | xargs sh -c '... exit 255;' > if [ $? -ne 0 ]; then > wait > # cleanup > exit 1 > fi > I have patched xargs behavior on exit 255 from utility, or termination of utility via signal to wait on existing utility processes before exiting 1. This make the exit 255 behavior much more predictable. I sent a lengthier explanation of the patch and reasoning to arch@, but figured I would follow up in thread as well. Patch available here: http://axe0.blackskyresearch.net/patches/matt/xargs.no_orphan.patch.txt Hoping this patch will make it back into xargs, it makes exit 255 predictable with -P > 1. > > >> >> Yes indeed it does ... should have scoured further, thanks! >> >> >>> >>> -- >>> Jilles Tjoelker >>> >> >> >> >> -- >> regards, >> matt >> > > > > -- > regards, > matt > -- regards, matt