Project

General

Profile

Bug #3356

xargs needlessly duplicates stdio buffering

Added by Garrett D'Amore about 7 years ago. Updated about 6 years ago.

Status:
Resolved
Priority:
Normal
Category:
cmd - userland programs
Start date:
2012-11-14
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:

Description

For reasons that are unfathomable to me, xargs seems to have its own limited implementation of getchar() and company. It seems that this could be greatly simplified to use the stdio library.

This will help with another issue filed separately, the RFE to add -0 for GNU xargs compatibility.


Files

xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch (1.71 KB) xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch This patch should be applied on top of http://cr.illumos.org/~gdamore/xargs/ Prasad Joshi, 2013-08-28 12:06 PM

History

#1

Updated by Prasad Joshi over 6 years ago

Hello, Garrett D'Amore would it be okay if I work on this?

#2

Updated by Garrett D'Amore over 6 years ago

I've long since had the code for this written, but I've not had good luck in getting anyone to code review it.

http://cr.illumos.org/~gdamore/xargs/

I'd welcome a code review. ;-)

#3

Updated by Gary Mills over 6 years ago

I was unable to find the original review request e-mail message to the developers list. Your changes are complex, although they appear correct. Could you provide us with test results, comparing the two xarg versions? That way we could be confident that the new version works, even in unusual cases.

#4

Updated by Prasad Joshi over 6 years ago

  • File xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch added

The changes look good to me. There are few (not so important) changes I would like to suggest.

In function parseargs(int ac, char **av)
The av[i][index] is compared or assigned with NULL pointer, though this will work without an error, however in my humble opinion this should have been compared/assigned with '\\0' or 0.

Just above this function, there is typo in the comment, which again is not very important, but may be fixed.

- * -l -> "-i "1"
- * -l10 -> "-i "10"
+ * -l -> "-l "1"
+ * -l10 -> "-l "10"

In main function, I feel it is good to add extra brackets around && and || conditional if statement.
- (PER_LINE && N_lines 0 || N_ARGS && N_args 0))
+ ((PER_LINE && N_lines) 0 || (N_ARGS && N_args) 0))

I am attaching a patch with all of these changes. Please check if they are acceptable.

#5

Updated by Garrett D'Amore about 6 years ago

  • Assignee set to Garrett D'Amore
  • % Done changed from 0 to 90
#6

Updated by Garrett D'Amore about 6 years ago

Prasad, you changed the code and broke it with your changes -- it doesn't work at all due to changing the specific logic of the boolean tests. I'm rejecting your diff.

#7

Updated by Prasad Joshi about 6 years ago

Garrett D'Amore wrote:

Prasad, you changed the code and broke it with your changes -- it doesn't work at all due to changing the specific logic of the boolean tests. I'm rejecting your diff.

Strange it worked for me.
It would be very kind if you can share more details. Can you please, if possible, let me know the testcase which fails?

#8

Updated by Garrett D'Amore about 6 years ago

Very simple tests, like find . -print0 | xargs -0 echo fail.

Even without -print0 and -0, the output is flat out wrong. You've misinterpreted the boolean expressions and placed grouping operators at the wrong locations, causing the expressions to be mis-evaluated and resulting in early termination of the result.

Try comparing against stock xargs, or gxargs, to verify your test results. And use a non-trivial directory as well. :-)

#9

Updated by Prasad Joshi about 6 years ago

  • File xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch added

It was my mistake during testing. There are 2 xargs, which I did not know initially. I had modified xargs compiled and installed on my machine. This modified binary is located at /bin/xargs.

However the default xargs which supports all of these options (has support for -0) and is located at /usr/bin/. When I had ran xargs it must have picked /usr/bin/xargs and it worked for me.

Anyways the modified patch is attached and it is test, it works correctly.

Please let me know if it works on your machine. I am sorry for any inconvenience this might have caused.

#10

Updated by Prasad Joshi about 6 years ago

  • File deleted (xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch)
#12

Updated by Prasad Joshi about 6 years ago

  • File deleted (xargs_diff_top_of_gdamore_xargs_bug_3356_changes.patch)
#13

Updated by Garrett D'Amore about 6 years ago

You probably have GNU xargs as /usr/bin/xargs. I'm guessing. I don't know.

Apart from changing some NULLs to 0s (this was old code, actually), I don't see any functional changes intended. They look like style fixes only (again, NULLs to 0s, and an attempt to make order of precedence explicit by adding parenthesis.)

#14

Updated by Prasad Joshi about 6 years ago

Garrett D'Amore wrote:

You probably have GNU xargs as /usr/bin/xargs. I'm guessing. I don't know.

I think so.

Apart from changing some NULLs to 0s (this was old code, actually), I don't see any functional changes intended. They look like style fixes only (again, NULLs to 0s, and an attempt to make order of precedence explicit by adding parenthesis.)

It makes sense to change NULL to 0 since, the quantity (or variable) used in comparison is a character and not a pointer. I have dropped the parenthesis fix in new patch since, there are so many places in the code where it is apparent.

#15

Updated by Garrett D'Amore about 6 years ago

  • Status changed from New to Resolved
  • % Done changed from 90 to 100

commit 03fc868668dd42b1b163d1fb8af3968f7283a7eb
Author: Garrett D'Amore <>
Date: Tue Aug 27 13:00:09 2013 -0700

672 xargs doesn't support -0
3356 xargs needlessly duplicates stdio buffering
Reviewed by: Prasad Joshi &lt;&gt;
Reviewed by: Gary Mills &lt;&gt;
Approved by: Robert Mustacchi &lt;&gt;
#16

Updated by Garrett D'Amore about 6 years ago

Prasad, if you want to submit your patch with the changes of NULLs to 0s, please open a new bug. That's legacy code anyway.

Also available in: Atom PDF