bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: xargs 4.1 uses broken _spawnvp


From: Robert Bassett
Subject: FW: xargs 4.1 uses broken _spawnvp
Date: Mon, 15 Nov 2004 22:49:46 -0500


-----Original Message-----
From: Robert Bassett 
Sent: Monday, November 15, 2004 10:49 PM
To: 'address@hidden'
Subject: xargs 4.1 uses broken _spawnvp

Using findutils-4.1-2-src.zip from http://gnuwin32.sourceforge.net/, 
running on Windows XP.  The GnuWin32 compilation links to Microsoft's 
MSVCRT implementation of _spawnvp, which has a problem handling args 
with spaces in them.  

I run the following command to create an index of a large directory:

 find . -type f -print0 | xargs -0 md5sum

The directory has files with spaces in their paths.  Find delimits 
things correctly, xargs parses things correctly, and then xargs 
calls _spawnvp; for example, 

 char *argv[] = { "file1", "file2 has spaces", "file3", NULL };
 _spawnvp (..., "md5sum", argv);

Xargs (reasonably) expects that _spawnvp will be implemented so that 
md5sum's main() will have argc/argv such that

 argv[0] = "md5sum"
 argv[1] = "file1"
 argv[2] = "file2 has spaces"
 argv[3] = "file3"

Instead, due to a strange implementation of _spawnvp (see Visual 
Studio .NET 2003 vc7\crt\src\dospawn.c), md5sum sees

 argv[0] = "md5sum"
 argv[1] = "file1"
 argv[2] = "file2"
 argv[3] = "has"
 argv[4] = "spaces"
 argv[5] = "file3" 

This problem was solved in groff by wrapping the call to spawnvp.  
See groff-1.19.1/src/libs/libgroff/spawnvp.c; it basically wraps 
up selected argv strings with double quotes before calling the 
MSVCRT _spawnvp, equivalent to 

 char *argv[] = { "file1", "\"file2 has spaces\"", "file3", NULL };
 _spawnvp (..., "md5sum", argv);

See also

 http://lists.gnu.org/archive/html/groff/2004-01/msg00077.html

I suspect that most MSVCRT implementations of the exec/spawn family 
will suffer from the same problem.

Seems like the Microsoft implementation in dospawn.c should work 
together with the code in vc7\crt\src\stdargv.c, which takes the 
process command line and splits it into argc/argv before calling 
main() as described in 

 http://msdn.microsoft.com/library/en-us/vccelng/htm/progs_12.asp

Since that won't really help since the MSCVRT horse is out of the 
barn, I wonder if a workaround similar to groff's may be applied.

Thanks for your consideration,
Robert Bassett




reply via email to

[Prev in Thread] Current Thread [Next in Thread]