Date: Tue, 12 Jan 2016 05:51:12 +0000 (UTC) From: Allan Jude <allanjude@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r293726 - in stable/10/usr.bin/xargs: . tests Message-ID: <201601120551.u0C5pCfj053201@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: allanjude Date: Tue Jan 12 05:51:12 2016 New Revision: 293726 URL: https://svnweb.freebsd.org/changeset/base/293726 Log: MFC: r285552 Use strtonum(3) instead of atoi(3) MFC: r286289 Introduce -P0, creating as many concurrent processes as possible Relnotes: yes MFC: r286461 Fix regression in xargs -Px, add more regression tests MFC: r287004 MFC: r287005 Fix the racy xargs -P0 -n2 test added in r286289 PR: 199976 Submitted by: Nikolai Lifanov <lifanov@mail.lifanov.com> Added: stable/10/usr.bin/xargs/tests/regress.0P1.out - copied unchanged from r286461, head/usr.bin/xargs/tests/regress.0P1.out stable/10/usr.bin/xargs/tests/regress.P1.out - copied unchanged from r286461, head/usr.bin/xargs/tests/regress.P1.out stable/10/usr.bin/xargs/tests/regress.n2P0.out - copied, changed from r286461, head/usr.bin/xargs/tests/regress.n2P0.out Modified: stable/10/usr.bin/xargs/tests/Makefile stable/10/usr.bin/xargs/tests/regress.sh stable/10/usr.bin/xargs/xargs.1 stable/10/usr.bin/xargs/xargs.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/xargs/tests/Makefile ============================================================================== --- stable/10/usr.bin/xargs/tests/Makefile Tue Jan 12 04:23:26 2016 (r293725) +++ stable/10/usr.bin/xargs/tests/Makefile Tue Jan 12 05:51:12 2016 (r293726) @@ -10,13 +10,16 @@ FILES+= regress.0.out FILES+= regress.0I.out FILES+= regress.0J.out FILES+= regress.0L.out +FILES+= regress.0P1.out FILES+= regress.I.out FILES+= regress.J.out FILES+= regress.L.out +FILES+= regress.P1.out FILES+= regress.R.out FILES+= regress.in FILES+= regress.n1.out FILES+= regress.n2.out +FILES+= regress.n2P0.out FILES+= regress.n3.out FILES+= regress.normal.out FILES+= regress.quotes.in Copied: stable/10/usr.bin/xargs/tests/regress.0P1.out (from r286461, head/usr.bin/xargs/tests/regress.0P1.out) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/usr.bin/xargs/tests/regress.0P1.out Tue Jan 12 05:51:12 2016 (r293726, copy of r286461, head/usr.bin/xargs/tests/regress.0P1.out) @@ -0,0 +1,4 @@ +quick ' brown fox jumped +over "the lazy dog +quick brown fox jumped over the lazy dog + Copied: stable/10/usr.bin/xargs/tests/regress.P1.out (from r286461, head/usr.bin/xargs/tests/regress.P1.out) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/usr.bin/xargs/tests/regress.P1.out Tue Jan 12 05:51:12 2016 (r293726, copy of r286461, head/usr.bin/xargs/tests/regress.P1.out) @@ -0,0 +1 @@ +quick brown fox jumped over the lazy dog Copied and modified: stable/10/usr.bin/xargs/tests/regress.n2P0.out (from r286461, head/usr.bin/xargs/tests/regress.n2P0.out) ============================================================================== --- head/usr.bin/xargs/tests/regress.n2P0.out Sat Aug 8 18:37:20 2015 (r286461, copy source) +++ stable/10/usr.bin/xargs/tests/regress.n2P0.out Tue Jan 12 05:51:12 2016 (r293726) @@ -1,4 +1,4 @@ -quick brown fox jumped -over the lazy dog +over the +quick brown Modified: stable/10/usr.bin/xargs/tests/regress.sh ============================================================================== --- stable/10/usr.bin/xargs/tests/regress.sh Tue Jan 12 04:23:26 2016 (r293725) +++ stable/10/usr.bin/xargs/tests/regress.sh Tue Jan 12 05:51:12 2016 (r293726) @@ -1,6 +1,6 @@ # $FreeBSD$ -echo 1..13 +echo 1..16 REGRESSION_START($1) @@ -8,14 +8,17 @@ REGRESSION_TEST(`normal', `xargs echo Th REGRESSION_TEST(`I', `xargs -I% echo The % % % %% % % <${SRCDIR}/regress.in') REGRESSION_TEST(`J', `xargs -J% echo The % again. <${SRCDIR}/regress.in') REGRESSION_TEST(`L', `xargs -L3 echo <${SRCDIR}/regress.in') +REGRESSION_TEST(`P1', `xargs -P1 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`R', `xargs -I% -R1 echo The % % % %% % % <${SRCDIR}/regress.in') REGRESSION_TEST(`n1', `xargs -n1 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`n2', `xargs -n2 echo <${SRCDIR}/regress.in') +REGRESSION_TEST(`n2P0',`xargs -n2 -P0 echo <${SRCDIR}/regress.in | sort') REGRESSION_TEST(`n3', `xargs -n3 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`0', `xargs -0 -n1 echo <${SRCDIR}/regress.0.in') REGRESSION_TEST(`0I', `xargs -0 -I% echo The % %% % <${SRCDIR}/regress.0.in') REGRESSION_TEST(`0J', `xargs -0 -J% echo The % again. <${SRCDIR}/regress.0.in') REGRESSION_TEST(`0L', `xargs -0 -L2 echo <${SRCDIR}/regress.0.in') +REGRESSION_TEST(`0P1', `xargs -0 -P1 echo <${SRCDIR}/regress.0.in') REGRESSION_TEST(`quotes', `xargs -n1 echo <${SRCDIR}/regress.quotes.in') REGRESSION_END() Modified: stable/10/usr.bin/xargs/xargs.1 ============================================================================== --- stable/10/usr.bin/xargs/xargs.1 Tue Jan 12 04:23:26 2016 (r293725) +++ stable/10/usr.bin/xargs/xargs.1 Tue Jan 12 05:51:12 2016 (r293726) @@ -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 @@ -208,6 +208,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: stable/10/usr.bin/xargs/xargs.c ============================================================================== --- stable/10/usr.bin/xargs/xargs.c Tue Jan 12 04:23:26 2016 (r293725) +++ stable/10/usr.bin/xargs/xargs.c Tue Jan 12 05:51:12 2016 (r293726) @@ -46,9 +46,11 @@ static char sccsid[] = "@(#)xargs.c 8.1 #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/param.h> +#include <sys/types.h> #include <sys/wait.h> - +#include <sys/time.h> +#include <sys/limits.h> +#include <sys/resource.h> #include <err.h> #include <errno.h> #include <fcntl.h> @@ -100,7 +102,9 @@ 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; inpline = replstr = NULL; ep = environ; @@ -148,19 +152,27 @@ main(int argc, char *argv[]) replstr = optarg; break; case 'L': - Lflag = atoi(optarg); + Lflag = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "-L %s: %s", optarg, errstr); break; case 'n': nflag = 1; - if ((nargs = atoi(optarg)) <= 0) - errx(1, "illegal argument count"); + nargs = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr) + errx(1, "-n %s: %s", optarg, errstr); break; case 'o': oflag = 1; break; case 'P': - if ((maxprocs = atoi(optarg)) <= 0) - errx(1, "max. processes must be >0"); + maxprocs = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "-P %s: %s", optarg, errstr); + if (getrlimit(RLIMIT_NPROC, &rl) != 0) + errx(1, "getrlimit failed"); + if (maxprocs == 0 || maxprocs > rl.rlim_cur) + maxprocs = rl.rlim_cur; break; case 'p': pflag = 1; @@ -179,7 +191,9 @@ main(int argc, char *argv[]) errx(1, "replsize must be a number"); break; case 's': - nline = atoi(optarg); + nline = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "-s %s: %s", optarg, errstr); break; case 't': tflag = 1;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601120551.u0C5pCfj053201>