Bug 202152

Summary: xargs -PN either crashes or always returns an error
Product: Base System Reporter: Jan Beich <jbeich>
Component: binAssignee: Allan Jude <allanjude>
Status: Closed FIXED    
Severity: Affects Only Me CC: allanjude, lifanov
Priority: --- Keywords: patch, regression
Version: CURRENT   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 199976    
Attachments:
Description Flags
v0 none

Description Jan Beich freebsd_committer freebsd_triage 2015-08-07 07:45:08 UTC
Created attachment 159633 [details]
v0

Looking under tests/ directory there're none for -P option, so not surprising based 286289 regressed it. The issue appears to be improper rebase against base r285552.

$ getconf CHILD_MAX
100

$ printf 'a\nb\nc\n' | xargs -P0 echo
xargs: -P 0: too small

# -O2 build (default)
$ printf 'a\nb\nc\n' | xargs -P2 echo
Segmentation fault

# -O0 build
$ printf 'a\nb\nc\n' | xargs -P2 echo
xargs: invalid number for -P option

$ lldb ./xargs --core /path/to/xargs.core
(lldb) target create "./xargs" --core "/path/to/xargs.core"
Core file '/path/to/xargs.core' (x86_64) was loaded.
Process 0 stopped
* thread #1: tid = 0, 0x00000000004019aa xargs`main + 570, name = 'xargs', stop reason = signal SIGSEGV
    frame #0: 0x00000000004019aa xargs`main + 570
-> 0x4019aa <main+570>: cmpb   $0x0, (%rax)
   0x4019ad <main+573>: jne    0x402426                  ; main + 3254
   0x4019b3 <main+579>: movslq 0x201d06(%rip), %rcx      ; maxprocs
   0x4019ba <main+586>: testq  %rcx, %rcx
(lldb) bt
* thread #1: tid = 0, 0x00000000004019aa xargs`main + 570, name = 'xargs', stop reason = signal SIGSEGV
  * frame #0: 0x00000000004019aa xargs`main + 570
    frame #1: 0x000000000040168f xargs`_start + 367
Comment 1 Nikolai Lifanov 2015-08-07 13:01:32 UTC
Please apply. I arrived at the same patch and it's just a bad rebase.
I will write tests for xargs.
Comment 2 Nikolai Lifanov 2015-08-07 13:43:38 UTC
I created a Differential D3330 about this.
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-08-08 18:37:35 UTC
A commit references this bug:

Author: allanjude
Date: Sat Aug  8 18:37:23 UTC 2015
New revision: 286461
URL: https://svnweb.freebsd.org/changeset/base/286461

Log:
  fix regression in xargs -Px (introduced in r286289) and add regression tests

  PR:		202152
  Submitted by:	jbeich (original),  Nikolai Lifanov (final)
  Reviewed by:	jbeich
  Approved by:	bapt (mentor)
  Differential Revision:	https://reviews.freebsd.org/D3330

Changes:
  head/usr.bin/xargs/tests/Makefile
  head/usr.bin/xargs/tests/regress.0P1.out
  head/usr.bin/xargs/tests/regress.P1.out
  head/usr.bin/xargs/tests/regress.n2P0.out
  head/usr.bin/xargs/tests/regress.sh
  head/usr.bin/xargs/xargs.c