- if (noinvoke || !WIFEXITED(status) || WIFSIGNALED(status))
- exit(127);
- if (!fflag && WEXITSTATUS(status))
- exit(WEXITSTATUS(status));
+ if (noinvoke)
+ exit(noinvoke);
+
+ /*
+ * According to POSIX, we have to exit if the utility exits with
+ * a 255 status, or is interrupted by a signal. xargs is allowed
+ * to return any exit status between 1 and 125 in these cases, but
+ * we'll use 124 and 125, the same values used by GNU xargs.
+ */
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS (status) == 255) {
+ fprintf (stderr, "xargs: %s exited with status 255\n",
+ argv[0]);
+ exit(124);
+ } else if (WEXITSTATUS (status) != 0) {
+ exit_status = 123;
+ }
+ } else if (WIFSTOPPED (status)) {
+ fprintf (stderr, "xargs: %s terminated by signal %d\n",
+ argv[0], WSTOPSIG (status));
+ exit(125);
+ } else if (WIFSIGNALED (status)) {
+ fprintf (stderr, "xargs: %s terminated by signal %d\n",
+ argv[0], WTERMSIG (status));
+ exit(125);
+ }