Skip to content

Commit

Permalink
10216 xargs does not properly detect when -P is negative
Browse files Browse the repository at this point in the history
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Andy Fiddaman <af@citrus-it.net>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
rmustacc committed Jan 16, 2019
1 parent 1bf8e91 commit 7c71d71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions usr/src/cmd/xargs/xargs.c
Expand Up @@ -21,7 +21,7 @@
/*
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
* Copyright 2012 DEY Storage Systems, Inc.
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*
* Portions of this file developed by DEY Storage Systems, Inc. are licensed
* under the terms of the Common Development and Distribution License (CDDL)
Expand Down Expand Up @@ -163,7 +163,7 @@ int
main(int argc, char **argv)
{
int j;
unsigned long l;
long l;
struct inserts *psave;
int c;
int initsize;
Expand Down Expand Up @@ -316,13 +316,19 @@ main(int argc, char **argv)

case 'P': /* -P maxprocs: # of child processses */
errno = 0;
l = strtoul(optarg, &eptr, 10);
l = strtol(optarg, &eptr, 10);
if (*eptr != '\0' || errno != 0) {
ermsg(_("failed to parse maxprocs (-P): %s\n"),
optarg);
break;
}

if (l < 0) {
ermsg(_("maximum number of processes (-P) "
"cannot be negative\n"));
break;
}

/*
* Come up with an upper bound that'll probably fit in
* memory.
Expand Down
7 changes: 5 additions & 2 deletions usr/src/man/man1/xargs.1
Expand Up @@ -43,8 +43,9 @@
.\" Copyright 1989 AT&T
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright (c) 2018, Joyent, Inc.
.\"
.TH XARGS 1 "May 28, 2017"
.TH XARGS 1 "September 13, 2018"
.SH NAME
xargs \- construct argument lists and invoke utility
.SH SYNOPSIS
Expand Down Expand Up @@ -211,7 +212,9 @@ otherwise, that particular invocation of \fIutility\fR is skipped.
.ad
.RS 15n
Invokes \fIutility\fR using at most \fImaxprocs\fR (a positive decimal integer)
parallel child processes.
parallel child processes. If \fImaxprocs\fR is zero, then the system
will set a large upper bound to try and run as many processes as
possible.
.RE

.sp
Expand Down

0 comments on commit 7c71d71

Please sign in to comment.