How exactly should this behave? I haven't been able to decipher what POSIX has to say about the subject. The GNU version executes the command with no arguments, so that "xargs" with blank input is equivalent to "echo" and "xargs ls" with blank input is equivalent to "ls". Toybox currently appears to do nothing, but actually forks a child process which silently seg-faults as a result of calling xexec() with argv[0] == NULL. Patching toybox to implement the GNU behavior fixes a lot of scripts on my test system that broke when I switched the xargs implementation from busybox to toybox, including the Linux build scripts. I included the patch below, but I haven't tested it with all the numerous options that are available to xargs. I'm still investigating whether this toybox behavior is the only factor contributing to behavior I observed.

William Haddon

diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c
index e1611ec..6238af8 100644
--- a/toys/posix/xargs.c
+++ b/toys/posix/xargs.c
@@ -160,17 +160,16 @@ void xargs_main(void)
     if (data && !TT.entries) error_exit("argument too long");
     out = xzalloc((entries+TT.entries+1)*sizeof(char *));

-    if (dlist) {
-      struct double_list *dtemp;
+    struct double_list *dtemp;

-      // Fill out command line to exec
-      memcpy(out, toys.optargs, entries*sizeof(char *));
-      TT.entries = 0;
-      TT.bytes = bytes;
+    // Fill out command line to exec
+    memcpy(out, toys.optargs, entries*sizeof(char *));
+    TT.entries = 0;
+    TT.bytes = bytes;
+    if (dlist)
       dlist->prev->next = 0;
-      for (dtemp = dlist; dtemp; dtemp = dtemp->next)
-        handle_entries(dtemp->data, out+entries);
-    }
+    for (dtemp = dlist; dtemp; dtemp = dtemp->next)
+      handle_entries(dtemp->data, out+entries);
     pid_t pid=fork();
     if (!pid) {
       xclose(0);
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to