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 <lifa...@mail.lifanov.com>
  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 <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,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;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to