diff options
author | Elliott Hughes <enh@google.com> | 2017-09-20 13:53:23 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-10-01 16:55:06 -0500 |
commit | b89af5ed5c95ebe0466830d90eedd430593a3584 (patch) | |
tree | 946632d0bceddb6209681b04480bc969d529589c /lib | |
parent | b542295cd8d906647e013056ab049323ce11e910 (diff) | |
download | toybox-b89af5ed5c95ebe0466830d90eedd430593a3584.tar.gz |
Fix xargs to obey POSIX's ARG_MAX restrictions.
This avoids "xargs: exec echo: Argument list too long" errors in practice.
find(1) needs to be fixed too, but that's a bit more complicated and a working
xargs provides a workaround.
Bug: http://b/65818597
Test: find /proc | strace -f -e execve ./toybox xargs echo > /dev/null
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 13 | ||||
-rw-r--r-- | lib/lib.h | 1 |
2 files changed, 14 insertions, 0 deletions
@@ -1293,3 +1293,16 @@ void do_lines(int fd, void (*call)(char **pline, long len)) if (fd) fclose(fp); } + +// Returns the number of bytes taken by the environment variables. For use +// when calculating the maximum bytes of environment+argument data that can +// be passed to exec for find(1) and xargs(1). +long environ_bytes() +{ + long bytes = sizeof(char *); + char **ev; + + for (ev = environ; *ev; ev++) + bytes += sizeof(char *) + strlen(*ev) + 1; + return bytes; +} @@ -241,6 +241,7 @@ int regexec0(regex_t *preg, char *string, long len, int nmatch, char *getusername(uid_t uid); char *getgroupname(gid_t gid); void do_lines(int fd, void (*call)(char **pline, long len)); +long environ_bytes(); #define HR_SPACE 1 // Space between number and units #define HR_B 2 // Use "B" for single byte units |