[BusyBox] Re: [patch] Why busybox xargs is broken.

Vladimir N. Oleynik dzo at simtreas.ru
Fri Oct 3 09:39:12 UTC 2003


Erik,

>>diff -ru busybox-old/findutils/xargs.c busybox/findutils/xargs.c
>>--- busybox-old/findutils/xargs.c	2003-06-20 04:01:54.000000000 -0500
>>+++ busybox/findutils/xargs.c	2003-10-02 06:11:29.689202848 -0500
>>@@ -1,3 +1,4 @@
>>+/* vi: set sw=4 ts=4: */
>> /*
>>  * Mini xargs implementation for busybox
>>  * Only "-prt" options are supported in this version of xargs.
>>@@ -24,6 +25,7 @@
>> 
>> #include <stdio.h>
>> #include <stdlib.h>
>>+#include <string.h>
>> #include <unistd.h>
>> #include <getopt.h>
>> #include <errno.h>
>>@@ -36,80 +38,162 @@
>>    This function have special algorithm.
>>    Don`t use fork and include to main!
>> */
>>-static void xargs_exec(char * const * args)
>>+static int xargs_exec(char * const * args)
>> {
>> 	int p;
>>-	int common[4];  /* shared vfork stack */
>> 
>>-	common[0] = 0;
>> 	if ((p = vfork()) >= 0) {
>> 		if (p == 0) {
>> 			/* vfork -- child */
>> 			execvp(args[0], args);
>>-			common[0] = errno; /* set error to shared stack */
>>-			_exit(1);
>>+			_exit(127);
>> 		} else {
>>+			int retval;
>> 			/* vfork -- parent */
>>-			wait(NULL);
>>-			if(common[0]) {
>>-				errno = common[0];
>>-				bb_perror_msg_and_die("%s", args[0]);
>>-			}
>>+			waitpid(p,&retval,0);
> 
> 
> I recommend using just wait(&retval) 
> 
> 
>>+			return retval>>8;

I do not understand, what for to change this my piece of a code.
I for a long time have noticed, that many do not understand
as vfork() function works and try to get rid of it. :-(


> There is no need to reinvent getopt here.  bb_getopt_ulflags is a
> much more compact wrapper on top of getopt.  It is admitedly not
> well documented, but it works nicely and produces very compact
> arg parsing. 

Yes! ;-)


--w
vodz







More information about the busybox mailing list