Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stabilize command -x #17

Open
jelmd opened this issue Aug 26, 2020 · 0 comments
Open

stabilize command -x #17

jelmd opened this issue Aug 26, 2020 · 0 comments

Comments

@jelmd
Copy link
Member

jelmd commented Aug 26, 2020

command -x utility ... can be used as a built-in alternative for xargs. In contrast to xargs implementations it tries to max out the getconf ARG_MAX buffer to reduce the number of utility executions and thus might be faster.

However, its available buf size calculation is wrong: ignores terminating \0 and last char of argv[]/env[]/auxv[] strings. Also, most execve implementations (Solaris, Linux, Darwin, NetBSD, OpenBSD) add a pointer for all related strings to the buffer, so they need to be taken into account as well (FreeBSD seems to be the only exception here).

Furthermore the related error handler does not expect, that execve may return with E2BIG as well, which causes an endless loop if E2BIG occures.

Finally, the command should be enhanced, so that it tries to fail early, if there is no sufficient buf space available and it should try much harder to avoid failing with E2BIG.

See also att/ast#1048

See also ksh93/ksh@acf84e9 - however, this commit is wrong wrt. space calculation, wastes a lot of space, gives up to early, dropped the error handling and thus is not reliable/usable. In contrast to its headline it does definitely not fix the problem on Solaris. Also the alignment statement is wrong - the string section[s] (argv, env, auxv) and str pointer section might be aligned to sizeof(void *) - so max. 4*15 = 60 bytes on 64bit (but there is no alignment for each string). IMHO there is no need to take this into account because the calculation already reserves 1024 bytes (POSIX suggests 2048 bytes) for implementation details like this.

jelmd pushed a commit to jelmd/ksh that referenced this issue Mar 13, 2021
command -x utility ... can be used as a built-in alternative for
xargs. In contrast to xargs implementations it tries to max out the
getconf ARG_MAX buffer to reduce the number of utility executions and
thus might be faster.

For more information see ksh-community#17

Note that ksh93/ksh@acf84e9
tries to fix this problem as well, but is based on wrong assumptions
and thus calculates wrong buffer sizes, wastes to much space and does
e.g. not work reliable for Solaris.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant