From owner-svn-src-head@freebsd.org Tue Aug 4 14:27:27 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0A12B9B29DA; Tue, 4 Aug 2015 14:27:27 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D5183164D; Tue, 4 Aug 2015 14:27:26 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t74ERQYr034862; Tue, 4 Aug 2015 14:27:26 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t74ERQ9W034860; Tue, 4 Aug 2015 14:27:26 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201508041427.t74ERQ9W034860@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Tue, 4 Aug 2015 14:27:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286289 - head/usr.bin/xargs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2015 14:27:27 -0000 Author: allanjude Date: Tue Aug 4 14:27:25 2015 New Revision: 286289 URL: https://svnweb.freebsd.org/changeset/base/286289 Log: xargs now takes -P0, creating as many concurrent processes as possible PR: 199976 Submitted by: Nikolai Lifanov Reviewed by: mjg, bjk Approved by: bapt (mentor) MFC after: 1 month Relnotes: yes Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D2616 Modified: head/usr.bin/xargs/xargs.1 head/usr.bin/xargs/xargs.c Modified: head/usr.bin/xargs/xargs.1 ============================================================================== --- head/usr.bin/xargs/xargs.1 Tue Aug 4 13:50:52 2015 (r286288) +++ head/usr.bin/xargs/xargs.1 Tue Aug 4 14:27:25 2015 (r286289) @@ -33,7 +33,7 @@ .\" $FreeBSD$ .\" $xMach: xargs.1,v 1.2 2002/02/23 05:23:37 tim Exp $ .\" -.Dd March 16, 2012 +.Dd August 4, 2015 .Dt XARGS 1 .Os .Sh NAME @@ -207,6 +207,11 @@ Parallel mode: run at most invocations of .Ar utility at once. +If +.Ar maxprocs +is set to 0, +.Nm +will run as many processes as possible. .It Fl p Echo each command to be executed and ask the user whether it should be executed. Modified: head/usr.bin/xargs/xargs.c ============================================================================== --- head/usr.bin/xargs/xargs.c Tue Aug 4 13:50:52 2015 (r286288) +++ head/usr.bin/xargs/xargs.c Tue Aug 4 14:27:25 2015 (r286289) @@ -46,9 +46,11 @@ static char sccsid[] = "@(#)xargs.c 8.1 #include __FBSDID("$FreeBSD$"); -#include +#include #include - +#include +#include +#include #include #include #include @@ -100,6 +102,7 @@ main(int argc, char *argv[]) long arg_max; int ch, Jflag, nargs, nflag, nline; size_t linelen; + struct rlimit rl; char *endptr; const char *errstr; @@ -166,6 +169,14 @@ main(int argc, char *argv[]) maxprocs = strtonum(optarg, 1, INT_MAX, &errstr); if (errstr) errx(1, "-P %s: %s", optarg, errstr); + if (getrlimit(RLIMIT_NPROC, &rl) != 0) + errx(1, "getrlimit failed"); + if (*endptr != '\0') + errx(1, "invalid number for -P option"); + if (maxprocs < 0) + errx(1, "value for -P option should be >= 0"); + if (maxprocs == 0 || maxprocs > rl.rlim_cur) + maxprocs = rl.rlim_cur; break; case 'p': pflag = 1;