On Fri, Oct 22, 2010 at 2:30 PM, Markus Duft <md...@gentoo.org> wrote: > Hey :) > > I recently updated my findutils builds on interix (work without > any patches (except a gnulib patch i already submitted), thanks > for the great work ;) ), and stumbled across a small problem: > > mduft xargs $ find /usr/ | ./xargs > ./xargs: /bin/echo: Cannot allocate memory > > mduft xargs $ ./xargs --show-limits > Your environment variables take up 3119 bytes > POSIX upper limit on argument length (this system): 1043409 > POSIX smallest allowable upper limit on argument length (all systems): 4096 > Maximum length of command we could actually use: 1040290 > Size of command buffer we are actually using: 131072 > > > It seems that max argument length is too high... > > Now, i'm pretty aware that interix is doing _many_ things wrong, and > sysconf(_SC_ARG_MAX) may well return a much too high number, but to > consistently handle such cases, would it be wise to cap the max argument > length to a sane value in xargs?
I wonder if that's really the problem. If the argv/environment is too large, the execve attempt is supposed to fail with E2BIG: 25901 [E2BIG] The number of bytes used by the new process image’s argument list and 25902 environment list is greater than the system-imposed limit of {ARG_MAX} 25903 bytes. Contrariwise, ENOMEM as an error code should be interpreted by the caller as indicating that the invoked utility cannot be executed at all because of memory constraints (and hence there would be no point in trying again with fewer arguments): 25935 [ENOMEM] The new process image requires more memory than is allowed by the 25936 hardware or system-imposed memory management constraints. xargs actually has code (now) to reduce argv when we get E2BIG, but this behaviour doesn't activate for ENOMEM, because of the above. The line numbers in the left-hand column are from a recent draft of the POSIX standard, but I'm guessing that previous versions were very similar. Is there any information in the Interix programmer's manual that would indicate what is going on here? As for whether we should make a code change, does it help if you use the -s option here? James.