diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-09-10 23:00:30 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-09-10 23:00:30 +0000 |
commit | 87d628039c21fa36723e62b3e2ff7b7bf033c7d8 (patch) | |
tree | d337e90f42f674668e8e0609de52d64e7582285b /usr.bin | |
parent | f4a29f27f10f769aa96175eedfb93b6fd630b886 (diff) |
Make xargs run [utility] program even when zero arguements are provided,
makes xargs POSIX compliant.
Original diff from jason@, better diff provided by millert@
Resolves PR 4262
ok deraadt@ millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xargs/xargs.1 | 15 | ||||
-rw-r--r-- | usr.bin/xargs/xargs.c | 14 |
2 files changed, 20 insertions, 9 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1 index 8fb7163e0e8..f632998df16 100644 --- a/usr.bin/xargs/xargs.1 +++ b/usr.bin/xargs/xargs.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: xargs.1,v 1.13 2003/06/12 17:55:01 jmc Exp $ +.\" $OpenBSD: xargs.1,v 1.14 2005/09/10 23:00:29 brad Exp $ .\" $FreeBSD: xargs.1,v 1.30 2003/05/21 21:07:28 ru Exp $$ .\" .\" Copyright (c) 1990, 1991, 1993 @@ -43,7 +43,7 @@ .Sh SYNOPSIS .Nm xargs .Bk -words -.Op Fl 0opt +.Op Fl 0oprt .Op Fl E Ar eofstr .Oo .Fl I Ar replstr @@ -74,7 +74,8 @@ upon each invocation, followed by some number of the arguments read from standard input. The .Ar utility -is repeatedly executed until standard input is exhausted. +is repeatedly executed one or more times until standard input +is exhausted. .Pp Spaces, tabs and newlines may be embedded in arguments using single .Pq Ql ' @@ -222,6 +223,10 @@ will do replacement in. If .Ar replacements is negative, the number of arguments in which to replace is unbounded. +.It Fl r +Do not run the command if there are no arguments. +Normally the command is executed at least once +even if there are no arguments. .It Fl s Ar size Set the maximum number of bytes for the command line length provided to .Ar utility . @@ -311,9 +316,9 @@ utility is expected to be .St -p1003.2 compliant. The -.Fl J , o , P +.Fl J , o , P , R and -.Fl R +.Fl r options are non-standard extensions which may not be available on other operating systems. .Pp diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 6b3ec60bfad..e6a7cd330a3 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xargs.c,v 1.20 2005/06/20 18:52:19 millert Exp $ */ +/* $OpenBSD: xargs.c,v 1.21 2005/09/10 23:00:29 brad Exp $ */ /* $FreeBSD: xargs.c,v 1.51 2003/05/03 19:09:11 obrien Exp $ */ /*- @@ -45,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: xargs.c,v 1.20 2005/06/20 18:52:19 millert Exp $"; +static const char rcsid[] = "$OpenBSD: xargs.c,v 1.21 2005/09/10 23:00:29 brad Exp $"; #endif #endif /* not lint */ @@ -79,7 +79,7 @@ static char **av, **bxp, **ep, **endxp, **xp; static char *argp, *bbp, *ebp, *inpline, *p, *replstr; static const char *eofstr; static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag; -static int cnt, Iflag, jfound, Lflag, wasquoted, xflag; +static int cnt, Iflag, jfound, Lflag, wasquoted, xflag, runeof = 1; static int curprocs, maxprocs; static size_t inpsize; @@ -122,7 +122,7 @@ main(int argc, char *argv[]) nline -= strlen(*ep++) + 1 + sizeof(*ep); } maxprocs = 1; - while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1) + while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:rs:tx")) != -1) switch (ch) { case 'E': eofstr = optarg; @@ -156,6 +156,9 @@ main(int argc, char *argv[]) case 'p': pflag = 1; break; + case 'r': + runeof = 0; + break; case 'R': Rflag = strtol(optarg, &endptr, 10); if (*endptr != '\0') @@ -257,6 +260,8 @@ parse_input(int argc, char *argv[]) case EOF: /* No arguments since last exec. */ if (p == bbp) { + if (runeof) + prerun(0, av); waitchildren(*argv, 1); exit(rval); } @@ -404,6 +409,7 @@ prerun(int argc, char *argv[]) int repls; repls = Rflag; + runeof = 0; if (argc == 0 || repls == 0) { *xp = NULL; |