Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Feb 2012 16:10:52 -0500
From:      Matthew Story <matthewstory@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: xargs short-circuit
Message-ID:  <CAB%2B9oge5LG%2B7%2B_Hno69K8OjDHevH3pMyK6qpLCd2PMsvDi2_jw@mail.gmail.com>
In-Reply-To: <CAB%2B9ogfqyXb5PAWLWt3MFTcvbhi_1vF0ffOByT8TiMqS9sOsoQ@mail.gmail.com>
References:  <CAB%2B9ogcT3OxMKwTY%2B8KfzJfcBiHRBnSdSxcy2eYR6bn=uoL1UQ@mail.gmail.com> <20120214193530.GA42580@stack.nl> <CAB%2B9ogfWXOGyv7uSDomSP0QY4goeaSGncGCTD10Jjh0fZ627FQ@mail.gmail.com> <CAB%2B9ogfqyXb5PAWLWt3MFTcvbhi_1vF0ffOByT8TiMqS9sOsoQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 14, 2012 at 3:25 PM, Matthew Story <matthewstory@gmail.com>wrote:

> On Tue, Feb 14, 2012 at 2:37 PM, Matthew Story <matthewstory@gmail.com>wrote:
>
>> On Tue, Feb 14, 2012 at 2:35 PM, Jilles Tjoelker <jilles@stack.nl> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAB%2B9oge5LG%2B7%2B_Hno69K8OjDHevH3pMyK6qpLCd2PMsvDi2_jw>