Commit Graph

137 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav
90c69417b6 Wording tweaks.
PR:		not quite docs/84620
MFC after:	2 weeks
2005-12-07 12:33:52 +00:00
Dag-Erling Smørgrav
2d14e0e547 Add -r option for GNU compatibility.
MFC after:	2 weeks
2005-12-07 12:20:08 +00:00
Ruslan Ermilov
f682f10c76 Sync program's usage() with manpage's SYNOPSIS. 2005-05-21 09:55:10 +00:00
Garance A Drosehn
46793db95b MFC 1.22: Fix -0 vs -L/-I processing, mainly so that 'xargs -0 -I []' will
do something sensible (namely: treat then '\0' as the EOL character, when
deciding what "a line" is for -N).  Note that  -I implies -N.

MFC after:	3 days
2005-02-27 01:35:54 +00:00
Ruslan Ermilov
a866e17077 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
Colin Percival
5578bd8c99 Modify behaviour of xargs -I in order to:
1. Conform to IEEE Std 1003.1-2004, which state that "Constructed
arguments cannot grow larger than 255 bytes", and
2. Avoid a buffer overflow.

Unfortunately the standard doesn't indicate how xargs is supposed to
handle arguments which (with the appropriate substitutions) would grow
larger than 255 bytes; this solution handles those by making as many
substitutions as possible without overflowing the buffer.

OpenBSD's xargs resolves this in a different direction, by making
all the substitutions and then silently truncating the resulting string.

Since this change may break existing scripts which rely upon the buffer
overflow (255 bytes isn't really all that long...) it will not be MFCed.
2004-10-18 15:40:47 +00:00
Tim J. Robbins
f8fb286a84 Document incorrect handling of multibyte characters with -I and -J options. 2004-08-02 03:07:42 +00:00
Tim J. Robbins
f58b94cba4 Call setlocale() with category LC_ALL instead of LC_MESSAGES. We need
LC_CTYPE and LC_COLLATE to correctly interpret regular expressions
returned by nl_langinfo(YESEXPR), and it doesn't hurt to include the
rest.
2004-07-12 04:18:44 +00:00
Dima Dorfman
5c3fd35c88 Fix spelling error in my own paragraph. 2004-06-28 11:18:47 +00:00
Maxime Henrion
0792992c73 - Use _PATH_TTY and _PATH_DEVNULL macros.
- Don't fail if we can't open /dev/null since this can happen if
  xargs is jail'ed or chroot'ed.

These fixes were submitted by Todd Miller from the OpenBSD project.
There was one problem in those fixes that broke -o, which is corrected
here and should be committed to the OpenBSD repo by Todd soon.

MFC in:	3 days
2003-06-13 17:05:41 +00:00
Juli Mallett
004bd28e40 Use waitpid, instead of wait3, which is more portable.
Submitted by:	"Todd C. Miller" <Todd.Miller@courtesan.com>
Obtained from:	OpenBSD
Reviewed by:	tjr
2003-06-13 07:37:45 +00:00
Juli Mallett
815e414e17 Remove redundant return; from void function.
Submitted by:	"Todd C. Miller" <Todd.Miller@courtesan.com>
Obtained from:	OpenBSD
2003-06-13 07:25:15 +00:00
Ruslan Ermilov
fa7f4291ff Markup bits.
Approved by:	re (blanket)
2003-05-21 21:07:28 +00:00
David E. O'Brien
8eb2a3de8f Don't shaddow exp(3). 2003-05-03 19:09:11 +00:00
Warner Losh
30aaff1192 Migrate to a new way of dealing with building from old revisions of
FreeBSD.  This method attempts to centralize all the necessary hacks
or work arounds in one of two places in the tree (src/Makefile.inc1
and src/tools/build).  We build a small compatibility library
(libbuild.a) as well as selectively installing necessary include
files.  We then include this directory when building host binaries.

This removes all the past release compatibilty hacks from various
places in the tree.  We still build on tip of stable and current.  I
will work with those that want to support more, although I anticipate
it will just work.

Many thanks to ru@, obrien@ and jhb@ for providing valuable input at
various stage of implementation, as well as for working together to
positively effect a change for the better.
2003-04-05 20:30:30 +00:00
Warner Losh
76d94537fe Simplify compatibility ifdef. 2003-04-04 04:39:29 +00:00
Maxime Henrion
4351e43f7e xargs(1) is WARNS=6 clean.
Tested on:	i386, sparc64
2003-03-28 16:24:11 +00:00
Maxime Henrion
cec1ba8c9c When -o isn't specified, open /dev/null as stdin.
Suggested by:	jhb
2003-03-28 16:22:54 +00:00
Maxime Henrion
98186e89da Add a new -o option to tell xargs(1) to reopen /dev/tty as stdin in
the child process, before executing the command.  This is very useful
when you do stuff like ``find ... | xargs interactive_application''.
Without -o, the application would inherit the pipe as its stdin, and
you thus lose any control over it.

This flag has been carefully chosen to not conflit with other options
of other xargs utilities like GNU xargs.

Reviewed by:	jmallett
2003-03-23 18:29:52 +00:00
Juli Mallett
3c67516766 Extend our -R extension which sets the number of arguments in which -I will
replace to support magic values less than zero, which mean to just go nuts
and expand as many as we want.

MFC after:	2 weeks
2003-02-26 22:44:32 +00:00
Juli Mallett
08f16c7ae4 De-typo usage string. 2003-02-26 22:36:55 +00:00
Tom Rhodes
4bb2c6860a A few changes for clarity.
PR:		47170
Submitted by:	Gary W. Swearingen <swear@attbi.com> (original version)
2003-01-27 18:16:36 +00:00
Jens Schweikhardt
57bd0fc6e8 english(4) police. 2002-12-27 12:15:40 +00:00
Ruslan Ermilov
5a9a189b52 mdoc(7) police: most -mdoc macros can take multiple arguments. 2002-12-23 15:15:35 +00:00
Tim J. Robbins
330d23f50e Add the -P option which executes multiple copies of the specified utility
in parallel. Idea from GNU xargs.
2002-12-21 10:17:13 +00:00
Ruslan Ermilov
40c6b893d8 Take __FreeBSD_version into account when BOOTSTRAPPING. 2002-11-13 13:49:29 +00:00
Jens Schweikhardt
2b239dd118 Fix typos; each file has at least one s/seperat/separat/
(I skipped those in contrib/, gnu/ and crypto/)
While I was at it, fixed a lot more found by ispell that I
could identify with certainty to be errors. All of these
were in comments or text, not in actual code.

Suggested by:	bde
MFC after:	3 days
2002-08-11 13:05:30 +00:00
Tim J. Robbins
99a84ce108 Declare environ as char **environ like in environ(7), not char *environ[].
This corrects a problem whereby xargs could not walk the environment table
to count the amount of space it used, and treated it as if it were empty.
This problem was introduced in rev 1.15.

MFC after:	2 days
2002-07-01 03:21:05 +00:00
Juli Mallett
1926d4aaad Stylistic nit:
main()'s argv argument is char*[], and functions that may inherit that arg
should use char*[] as well.
2002-06-22 12:59:40 +00:00
Juli Mallett
5058dcb497 Check for results of repeated calls to strnsubst(), as well as for the
behaviour with NULL match string, as that has changed over time.
2002-06-22 12:58:42 +00:00
Juli Mallett
893305fe5e When giving an example that relies on shell expansion/globbing, don't use a
replstr for -J that will be interpereted by the shell.

MFC after:	1 day
2002-06-22 12:47:56 +00:00
Juli Mallett
6fc8ba94c6 Note that this appeared at least as early as PWB UNIX.
Use the literal string 'PWB UNIX', as we still have no .At macro for it.
2002-06-10 22:59:59 +00:00
Juli Mallett
51f7a48bf0 Err, duh, free(3) doesn't set its argument to NULL... Fix realloc of a freed
chunk.
2002-06-04 04:08:18 +00:00
Juli Mallett
6ea89183fc Restructure sanity checks so that -I and -J just override eachother, rather
than triggering a usage().  Allow -R and -I to be specified in any order, and
thus change how -R checks for -I not being given and triggering a usage().

Partially requested by:	gad
2002-05-30 19:34:31 +00:00
Juli Mallett
986d829b8f Allow the input line to be NULL, and teach strnsubst() that NULL means to use
a nil-string.
2002-05-30 19:24:08 +00:00
Ruslan Ermilov
809a3054f6 mdoc(7) police: punctuation, miscellaneous. 2002-05-30 06:50:52 +00:00
Juli Mallett
be70f7d4da Simplify prerun() in the case where there are no arguments. Can't do -I or -J
substitution if `utility' is not specified and we're using the buildin echo;
It has no arguments for us to abuse.
2002-05-17 07:55:24 +00:00
Juli Mallett
5706d2e811 Fix a "tiny and squeeby and little" markup mistake.
Submitted by:	fenner
2002-05-14 22:55:31 +00:00
Ruslan Ermilov
8e0a87c1b3 xargs.c,v 1.33 broke the upgrade path from old versions of 4.x and 5.0. 2002-05-10 13:06:34 +00:00
Juli Mallett
b23de8a352 -I and -J both set the same variable, replstr, to the string to replace with
a line of input, and both work differently, so prevent them from both being
passed to xargs(1).
2002-05-06 03:38:28 +00:00
Juli Mallett
305e39f49b Modify the -p implementation to use a user's locale, so they can respond to
the prompt in their native language.

Also make the prompt fit what POSIX asks for (?...).

This should not affect use of -p with yes(1) [as every locale I know of matches
'y' as YESEXPR as well], but that's what -t is for anyway.  -p is meant to be
really used interactively.

Submitted by:	tjr, jmallett
2002-05-05 06:42:44 +00:00
Juli Mallett
5eb40323b0 Fix a typo.
Submitted by:	Carl Schmidt <cschmidt@slackerbsd.org>

Wrap an obscenely long line while I'm here.
2002-05-05 05:15:16 +00:00
Juli Mallett
9104507502 In an effort to make this utility easier to work with at a source level, move
out the parse loop to a seperate function, and move local variables around as
is needed.  To keep the state of some variables and keep from having huge arg
lists to functions, make a bunch global.

Change use of err(3) in situations where malloc(3) will be setting errno to
errx(3) since assuming malloc(3) sets errno is non-portable, and provides no
more useful information in the context of FreeBSD.

Submitted by:	bde (err/errx), Carl Schmidt <cschmidt@slackerbsd.org> (some
		of the movement of the input loop to a function)
Approved by:	src/tools/regression/usr.bin/xargs
2002-05-05 02:46:53 +00:00
Juli Mallett
9bf450b850 Grouping changes.
Submitted by:	Carl Schmidt <cschmidt@slackerbsd.org>
2002-05-04 06:00:19 +00:00
Juli Mallett
3dca1afc60 Don't use pointers as booleans. 2002-05-04 05:53:02 +00:00
Juli Mallett
b6594dba8b Replace calloc(3) with malloc(3), and set the tail of the
argument list to NULL, to terminate the arguments passed
to execvp(2).

Thanks to:	bde (for pointing out some missing parens)

And with apologies to Ozzy Osbourne:

	On his way to dinner
	It took him by surprise
	When an email from bde
	Said his code was full of lies

	Style (indentation)
	And his bracing were all wrong
	He casted to size_t
	When he should have cast to long

	I don't mind

	Single letter identifiers
	Unwrapped Line
	Over 80 chars
	Far over 80 chars

	Who can we get to send diffs
	We need Bruce D. Evans
	Shows you comparason to his
	We need Bruce D. Evans again
2002-05-04 00:08:06 +00:00
Juli Mallett
38dff9a439 Fix a bug whereby we were getting ~0 and comparing it to maxsize, i.e. if
s1 was 0 length, and replstr was 0 length, etc., we would end up subtracting
one from zero and seeing if it was greater than the size_t (unsigned) var
maxsize...  This would cause us to return a string consisting of essentially
only match, which is not the right behaviour if we have 0 length inpline.
2002-05-03 19:45:41 +00:00
Juli Mallett
263dc775f2 Move substitution out to a function, prerun(), and replace use of run() with
it.  It handles everything (right now) that needs done before run(), except
the -J case, because while that would be easy, I don't quite understand -J.

Reviewed by:	src/tools/regression/usr.bin/xargs
2002-05-03 17:41:54 +00:00
Juli Mallett
b9b03ba0bc Get rid of bogus holder for realloc(3). 2002-05-03 17:13:29 +00:00
Juli Mallett
1925cb245c Rewrite the loop that handles substitution in the -I case, and try to make
it easier to understand.  Making it easy to understand isn't all that easy,
so litter the code with comments so some other poor soul can come along some
day and work on this if they see fit to do so.  Avoid calling strlen(3) to
check for a nil-string, when we can just check for *str=='\0'.

Approved by:    src/tools/regression/usr.bin/xargs/
2002-05-03 17:05:25 +00:00
Juli Mallett
4f49da74db Rename lflag' to Lflag' to match the option's case. 2002-05-03 16:32:03 +00:00
Juli Mallett
d7a43b245d Revert revision 1.22. I incorrectly modified the Berkeley identifiers.
Requested by:	bde, mike
2002-05-03 14:50:31 +00:00
Juli Mallett
eee11f05b4 __COPYRIGHT() and __SCCSID(). 2002-05-02 05:21:35 +00:00
Juli Mallett
76ccb81ef2 An explicit cast to size_t for an inline integer, since the two are not the
same on Alpha and lint(1) pointed that out.

lint(1) on the same architecture pointed out how silly a cast to (u_int) to
malloc(3)'s argument was.  Change that to size_t.
2002-05-02 05:07:13 +00:00
Juli Mallett
943e841433 A markup fix, and document -R as non-standard. 2002-05-02 03:29:38 +00:00
Juli Mallett
b50a72861d Make -J a proper flag internal to the code (rather than just check for
use of replstr and lack of Iflag), and add -R, which when given with
-I controls the number of arguments on which replacement will be done.

Some people happen to think it's idiotic to limit to 5 arguments, so
let the user override it if they like.
2002-05-02 02:42:34 +00:00
Juli Mallett
299ea75ab7 *str is spelled 's1' inside the body of the code.
Make 'this' not a local variable, since it isn't necessary or complex enough
to warrant such.
2002-05-02 02:15:06 +00:00
Juli Mallett
0fa5e8dc42 Rework some of the -I support so I can't find a way to make xargs(1) core or
corrupt memory.  Simplifies the code in one or two places, also removes some
code that looks like it was bogus or incomplete.

Update strnsubst to have one or two extra conditions which maybe would make
it more efficient, or at least more versatile.  This is likely a no-op.
2002-05-02 02:06:03 +00:00
Juli Mallett
91ae52cb17 In the case where we can't open /dev/tty, fall back to -t behaviour.
Submitted by:	fenner
2002-04-19 23:58:00 +00:00
Juli Mallett
5e61dfa3ca Bump WARNS to 4. 2002-04-19 23:46:45 +00:00
Juli Mallett
0c7c579ba6 Compound two fprintf(3)s into 1 using string concatenation. 2002-04-19 23:41:56 +00:00
Juli Mallett
fc17b349c8 After 3 months...
Merge xargs(1) with that of xMach.

Bring in xargs(1) changes to add -L and -I as per the Single Unix Specification
version 3.  Proper exit status numbers are implemented, and the manual page has
been updated to reflect reality.

The code has been ANSIfied, and a new file has been added to xargs(1) to do the
substring substitution as SUSv3 requires.

Traditional behaviour should not be affected, use of -J should be deprecated
in favor of the more portable -I (though -J has been left, for now).

Submitted by:	me, tjr (the exit status stuff)
Obtained from:	xMach
2002-04-19 23:28:54 +00:00
Juli Mallett
73385ac644 ANSIfy: Function declarations and prototypes, use of environ(7).
Reviewed by:	mike
Approved by:	mike
2002-03-15 22:54:58 +00:00
Dag-Erling Smørgrav
8ad749a45d Change back to using vfork() now that execvp() is vfork()-safe. If execvp()
fails, errno is saved to a volatile variable that the parent later inspects.

PR:		bin/34898
Submitted by:	Tim J. Robbins <tim@robbins.dropbear.id.au>
MFC after:	1 week
2002-03-09 22:08:14 +00:00
Mike Barcroft
064692095c Leave the `copyright' variable exposed, since the main purpose of it
is to put a copyright in the object file.

Submitted by:	bde
2002-03-07 10:06:00 +00:00
Mike Barcroft
51883012f6 Fix vendor ID (mostly obtained from Rev 1.1). 2002-03-05 05:17:30 +00:00
Mark Murray
16b07a33f9 WARNS=2 fixes, remove register keyword, use __FBSDID() 2001-12-11 22:36:26 +00:00
Dima Dorfman
ffb9c240d7 Spelling police: extention -> extension. 2001-07-05 08:51:08 +00:00
Dima Dorfman
8d904f1537 Add a -J replstr option that allows the user to tell xargs to insert
the data read from standard input at a specific point in the command
line arguments rather than at the end.

Submitted by:	dd, gad
Reviewed by:	gad, brian
2001-05-15 00:31:19 +00:00
Dima Dorfman
a9bc34c882 Alphabetize command-line options in the synopsis. 2001-05-02 06:41:46 +00:00
Ruslan Ermilov
471b9c332c mdoc(7) police: Fixed typo and markup in rev.1.11. 2001-04-13 09:15:16 +00:00
Brian Somers
c42584e853 o The -s limit is ARG_MAX - 4K, not ARG_MAX - 2K.
o Mention that the current environment is part of the -s calculation.
o Add a BUGS section that warns against executing a program that increases
  the size of the argument list or the size of the environment.

  I have wondered for a while what the difference is between

    get a big list | xargs sudo command

  which fails and

    get a big list | sudo xargs command

  which succeeds.  The answer is that in the first case, sudo expands
  the environment and pushes the amount of data passed into execve over
  the E2BIG threshold.
2001-04-10 23:16:55 +00:00
Ruslan Ermilov
f4ddfb3865 Prepare for mdoc(7)NG. 2000-12-27 16:52:31 +00:00
Ruslan Ermilov
9b88faecd3 Prepare for mdoc(7)NG. 2000-12-19 16:00:12 +00:00
Ruslan Ermilov
8fe908ef0c mdoc(7) police: use the new features of the Nm macro. 2000-11-20 19:21:22 +00:00
Philippe Charnier
5e8eb81aac Use .Xr 2000-03-26 15:05:40 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
Nik Clayton
3be5f1f5ce Add $Id$, to make it simpler for members of the translation teams to
track.

The $Id$ line is normally at the bottom of the main comment block in the
man page, separated from the rest of the manpage by an empty comment,
like so;

     .\"    $Id$
     .\"

If the immediately preceding comment is a @(#) format ID marker than the
the $Id$ will line up underneath it with no intervening blank lines.
Otherwise, an additional blank line is inserted.

Approved by:            bde
1999-07-12 20:24:20 +00:00
Jean-Marc Zucconi
ef9866be68 xargs was spliting the input in a very different way from everyone else,
and was also a bit inconsistent: leading blanks, or any double blanks
generated empty arguments, but a trailing blank did not.

PR:		bin/2630, bin/10914
Submitted by:	Arne Henrik Juul <arnej@imf.unit.no>
1999-05-23 15:58:22 +00:00
Dag-Erling Smørgrav
1fd98d7d88 Calls one or more of malloc(), warn(), err(), syslog(), execlp() or
execvp() in the child branch of a vfork(). Changed to use fork()
instead.

Some of these (mv, find, apply, xargs) might benefit greatly from
being rewritten to use vfork() properly.

PR:		Loosely related to bin/8252
Approved by:	jkh and bde
1998-10-13 14:52:33 +00:00
Joseph Koshy
a3e5bc4fb5 Remove compile time dependency on ARG_MAX.
This fix only removes the dependency on compile time constants.  The code
has other (old) problems that need to be addressed.

PR: 1791
Reviewed-by: bde, tegge
1998-06-17 12:58:43 +00:00
Daniel O'Callaghan
749f6a2934 Submitted by: Peter Hawkins <peter@clari.net.au>
Spelling police.
1997-12-13 06:34:47 +00:00
Philippe Charnier
a51024e289 Use err(3) instead of local redefinition. 1997-08-27 06:26:23 +00:00
Warner Losh
1c8af87873 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-29 04:34:07 +00:00
Warner Losh
d919888163 Reviewed by: Warner Losh <imp@village.org>
Submitted by:	Marc Slemko <marcs@znep.com>
Obtained from:	OpenBSD

Add -0 for reading the results of find -0.
1996-11-01 18:46:05 +00:00
Satoshi Asami
e5009da0f9 Make xargs take into account the bytes occupied by the environment.
Original by: peter
1996-03-05 07:43:40 +00:00
Rodney W. Grimes
9b50d90275 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00