Page MenuHomeFreeBSD

D2616.id5666.diff
No OneTemporary

D2616.id5666.diff

Index: usr.bin/xargs/xargs.1
===================================================================
--- usr.bin/xargs/xargs.1
+++ usr.bin/xargs/xargs.1
@@ -33,7 +33,7 @@
.\" $FreeBSD$
.\" $xMach: xargs.1,v 1.2 2002/02/23 05:23:37 tim Exp $
.\"
-.Dd March 16, 2012
+.Dd May 21, 2015
.Dt XARGS 1
.Os
.Sh NAME
@@ -207,6 +207,11 @@
invocations of
.Ar utility
at once.
+If
+.Ar maxprocs
+is negative or 0,
+.Nm
+will run as many processes as possible at a time.
.It Fl p
Echo each command to be executed and ask the user whether it should be
executed.
Index: usr.bin/xargs/xargs.c
===================================================================
--- usr.bin/xargs/xargs.c
+++ usr.bin/xargs/xargs.c
@@ -46,8 +46,10 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/param.h>
#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <err.h>
#include <errno.h>
@@ -63,6 +65,8 @@
#include "pathnames.h"
+#define BASE_DECIMAL 10
+
static void parse_input(int, char *[]);
static void prerun(int, char *[]);
static int prompt(void);
@@ -100,12 +104,15 @@
long arg_max;
int ch, Jflag, nargs, nflag, nline;
size_t linelen;
+ struct rlimit reslimit;
+ int proclim;
char *endptr;
inpline = replstr = NULL;
ep = environ;
eofstr = "";
Jflag = nflag = 0;
+ proclim = 1;
(void)setlocale(LC_ALL, "");
@@ -159,8 +166,15 @@
oflag = 1;
break;
case 'P':
- if ((maxprocs = atoi(optarg)) <= 0)
- errx(1, "max. processes must be >0");
+ if (getrlimit(RLIMIT_NPROC , &reslimit) == 0)
+ proclim = reslimit.rlim_cur;
+ maxprocs = strtol(optarg, &endptr, BASE_DECIMAL);
+ if (*endptr != '\0')
+ errx(1, "max processes must be a number");
+ if (maxprocs > proclim)
+ errx(1, "max processes must be less than RLIMIT_NPROC: %d", proclim);
+ if (maxprocs < 1)
+ maxprocs = proclim;
break;
case 'p':
pflag = 1;

File Metadata

Mime Type
text/plain
Expires
Fri, Feb 6, 4:30 AM (13 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28446654
Default Alt Text
D2616.id5666.diff (1 KB)

Event Timeline