Skip to content

Conversation

ecnelises
Copy link

Filling the whole command into 'sh -c' may hit length limit of single argument. For non-console subprocesses, use pipe to invoke sh instead.

Fixes #1261

Filling the whole command into 'sh -c' may hit length limit of single
argument. For non-console subprocesses, use pipe to invoke sh instead.
Fatal("posix_spawn: %s", strerror(err));

if (!use_console_) {
ssize_t written = write(input_pipe[1], command.c_str(), command.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that work for large commands?

Most systems use a default pipe buffer size of 64 kiB, some even smaller (see https://github.com/afborchert/pipebuf) so this write() call will block infinitely if command.size() is larger than that (and the bug referenced by this PR talks about command sizes of 128 kiB).

Linux has fcntl(F_SETPIPE_SZ) to change that the pipe buffer size, but I am not aware of similar features on other systems. Even the Linux pipe manpage tsates that applications should not rely on a specific capacity.

It might be more portable and simple to write long commands to a file that is passed as the first argument to the shell instead. And that would also work for console processes too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friendly ping?

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

Successfully merging this pull request may close these issues.

Long build line can hit MAX_ARG_STRLEN on Linux
2 participants