The 4.3-reno version of xargs contains the following code for actually running
the sub-program with arguments:
run(prog, argv)
char *prog, **argv;
{
union wait pstat;
pid_t pid, waitpid();
char **p;
if (tflag) {
(void)fprintf(stderr, "%s", *argv);
for (p = argv + 1; *p; ++p)
(void)fprintf(stderr, " %s", *p);
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
}
switch(pid = vfork()) {
case -1:
(void)fprintf(stderr,
"xargs: vfork: %s.\n", strerror(errno));
exit(1);
case 0:
execvp(prog, argv);
(void)fprintf(stderr,
"xargs: %s: %s.\n", prog, strerror(errno));
_exit(1);
}
pid = waitpid(pid, &pstat, 0);
if (pid == -1) {
(void)fprintf(stderr,
"xargs: waitpid: %s.\n", strerror(errno));
exit(1);
}
if (pstat.w_status)
exit(1);
Now, either the way the "stat" structure works under 4.3-reno is significantlyQuote:}
different, or the list two lines of this function will cause xargs to exit
completely if the program it's running exits with a non-zero exit status.
This strikes me as very wrong. For example, one of the most common uses for
xargs is to run "find" on a tree and pipe the result through "xargs grep
string". Well, with the behavior I've described above, xargs will exit as
soon as it gets a batch of files that don't have "string" in any of them, and
this strikes me as quite wrong.
So what's the story.... am I misunderstanding what the code does (which I
doubt, since I compiled it under SunOS 4.1.1 and it *is* exiting on the first
failed grep), or does 4.3-reno do things with the stat structure differently,
or does POSIX define the behavior I've described as "correct," or is this a
bug in 4.3-reno's xargs?
--