Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Conversation

siteshwar
Copy link
Contributor

There was a regression introduced after the last stable release which
causes mishandling of redirections in subshells. For e.g.

foo=$(print /bin/echo bar)
print foo=$foo

prints bar on stdout and the variable foo is empty.

Handling of redirections in $() style of command substitution was
changed after the last stable release. sh_subshell() function replaces
sfstdout with a newly created temporary stream with this line :

sp->saveout = sfswap(sfstdout, NULL);

The newly created stream has it's fd value set to -1. If `` style of
command subtitution happens inside $(), it tries to use this stream with
invalid fd and fails to close it. So redirections for stdout do not
work.

We should check if the stream that we are closing actually corresponds
to the file descriptor that we want to close. If not, directly invoke
close() on the fd.

Resolves: #478

@krader1961
Copy link
Contributor

LGTM

There was a regression introduced after the last stable release which
causes mishandling of redirections in subshells. For e.g.

foo=$(print `/bin/echo bar`)
print foo=$foo

prints `bar` on stdout and the variable foo is empty.

Handling of redirections in $() style of command substitution was
changed after the last stable release. sh_subshell() function replaces
sfstdout with a newly created temporary stream with this line :

sp->saveout = sfswap(sfstdout, NULL);

The newly created stream has it's fd value set to -1. If `` style of
command subtitution happens inside $(), it tries to use this stream with
invalid fd and fails to close it. So redirections for stdout do not
work.

We should check if the stream that we are closing actually corresponds
to the file descriptor that we want to close. If not, directly invoke
close() on the fd.

Resolves: #478
sfio provides an api to get file descritptor of a stream. Use it instead
of directly accessing private member of Sfio_t struct.

Related: #478
@siteshwar
Copy link
Contributor Author

I have made one minor change in the pull request to use sffileno() instead of directly accessing _file member of Sfio_t struct. There may be test case failures on Travis, but they are caused by recent changes in framework for testing (#481).

Merging.

@siteshwar siteshwar merged commit 4bbeec5 into att:master Apr 19, 2018
@siteshwar siteshwar deleted the gh478 branch April 19, 2018 11:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backticks nested in $( ) result in misdirected output
2 participants