Notes |
(0010174)
vda
08-03-08 12:10
|
> The patch I attach below fixes both these issues, but does have the disadvantage of introducing an incompatible change in behaviour.
Well, we match what GNU xargs does:
# true | xargs -e | hexdump -vC
00000000 0a |.|
00000001
# true | /usr/bin/xargs -e | hexdump -vC
00000000 0a |.|
00000001
# /usr/bin/xargs --version
GNU xargs version 4.1.20
> However, the current behaviour is both broken and undocumented
It is documented in GNU xargs manpage.
The bug is that busybox "xargs -e" does not switch off EOF string detection. Fix:
diff -d -urpN busybox.5/findutils/xargs.c busybox.6/findutils/xargs.c
--- busybox.5/findutils/xargs.c 2008-07-22 01:04:20.000000000 +0200
+++ busybox.6/findutils/xargs.c 2008-08-03 21:10:47.000000000 +0200
@@ -376,6 +376,8 @@ enum {
int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int xargs_main(int argc, char **argv)
{
+ static const char const_eof_str[] ALIGN1 = "_";
+
char **args;
int i, n;
xlist_t *list = NULL;
@@ -385,7 +387,7 @@ int xargs_main(int argc, char **argv)
int n_max_arg;
size_t n_chars = 0;
long orig_arg_max;
- const char *eof_str = "_";
+ const char *eof_str = const_eof_str;
unsigned opt;
size_t n_max_chars;
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
@@ -396,6 +398,10 @@ int xargs_main(int argc, char **argv)
opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &eof_str);
+ /* -e without optional param? */
+ if ((opt & OPT_EOF_STRING) && eof_str == const_eof_str)
+ eof_str = NULL;
+
if (opt & OPT_ZEROTERM)
USE_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin); |
|
(0010204)
Araneidae
08-03-08 15:09
|
> Well, we match what GNU xargs does:
Well, that's odd. From Debian xargs(1):
-Eeof-str
Set the end of file string to eof-str. If the end of file string occurs as a
line of input, the rest of the input is ignored. If neither -E nor -e is used,
no end of file string is used.
--eof[=eof-str], -e[eof-str]
This option is a synonym for the ‘-E’ option. Use ‘-E’ instead, because it is
POSIX compliant while this option is not. If eof-str is omitted, there is no
end of file string. If neither -E nor -e is used, no end of file string is
used.
Well, you've demonstrated in the test that xargs (rather futilely) allows -e to be specified with no string (alas, this means that an empty string cannot be specified as eof, which actually could be useful). Interestingly, reading that man page at face value, I can specify -E'' or --eof='' to specify an empty eof string (yes, I know '' expands to nothing), so it's just the -e (non Posix) which is odd.
However, I can't see any evidence that the default eof string is _, and the man page I've quoted suggests that the default should be NULL -- that's how I interpret "no end of file string is used".
So if we remove the "_" default this const_eof_str to be lost, which can't be a bad thing.
To test: we current have
# echo $'one\n_\ntwo' | xargs
one
and I suggest (unless there's some other implementation we'll take as reference) that we should see
# echo $'one\n_\ntwo' | xargs
one
_
two |
|
(0010214)
vda
08-03-08 15:20
edited on: 08-03-08 15:20
|
> Well, that's odd. From Debian xargs(1):
There is no "debian xargs". What your "xargs --version" prints?
> Well, you've demonstrated in the test that xargs (rather futilely) allows -e to be specified with no string (alas, this means that an empty string cannot be specified as eof, which actually could be useful)
This is fixed now in svn. "xargs -e" with no param means "don't use any EOF string" now.
> However, I can't see any evidence that the default eof string is _, and the man page I've quoted suggests that the default should be NULL -- that's how I interpret "no end of file string is used".
My xargs' manpage does explicitly say that _ is a default EOF string. But I may have somewhat dated GNU xargs here (as I said, it's 4.1.20).
|
|
(0010234)
Araneidae
08-03-08 22:43
|
$ xargs --version
GNU xargs version 4.2.28 |
|
(0010244)
bernhardf
08-04-08 06:42
|
debian:
$ xargs --version
xargs (GNU findutils) 4.4.0
$ echo $'one\n_\ntwo' | xargs
one _ two
RHEL5:
$ xargs --version
GNU xargs version 4.2.27
$ echo $'one\n_\ntwo' | xargs
one _ two
RHAS4.4:
$ xargs --version
GNU xargs version 4.1.20
$ echo $'one\n_\ntwo' | xargs
one
SuSE-10.3:
$ xargs --version
GNU xargs version 4.2.31
$ echo $'one\n_\ntwo' | xargs
one _ two
so i'd go for the 4.4.0 behaviour, as suggested by vda. |
|
(0010254)
vda
08-04-08 14:32
edited on: 08-04-08 14:32
|
Fixed in svn: -e defaults to "no EOF string", SUS-mandated -E added.
|
|